authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-02 08:15:19+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-03 09:44:58+02:00
log56b0c7bd2f5936c17571e878f835cf0d542ca1fd
tree0c4fac1623366d112d47a07d28a0f02fca9c718d
parent8060fad4250d0157ac412f95c76511770e1eb097
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.zig.system: Force disable the small_data feature for hexagon.

This works around the fact that LLVM and LLD both have broken support for the small data area, yet the feature is on by default for all Hexagon CPUs. I want to eventually replace this hack with a flag in update_cpu_features.zig for marking features that should always be off by default and not be accessible to users. That way, the compiler will have full control over them.

1 files changed, 10 insertions(+), 0 deletions(-)

lib/std/zig/system.zig+10
...@@ -385,6 +385,16 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {...@@ -385,6 +385,16 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
385 query.cpu_features_sub,385 query.cpu_features_sub,
386 );386 );
387387
388 if (cpu_arch == .hexagon) {
389 // Both LLVM and LLD have broken support for the small data area. Yet LLVM has the feature
390 // on by default for all Hexagon CPUs. Clang sort of solves this by defaulting the `-gpsize`
391 // command line parameter for the Hexagon backend to 0, so that no constants get placed in
392 // the SDA. (This of course breaks down if the user passes `-G <n>` to Clang...) We can't do
393 // the `-gpsize` hack because we can have multiple concurrent LLVM emit jobs, and command
394 // line options in LLVM are shared globally. So just force this feature off. Lovely stuff.
395 result.cpu.features.removeFeature(@intFromEnum(Target.hexagon.Feature.small_data));
396 }
397
388 // https://github.com/llvm/llvm-project/issues/105978398 // https://github.com/llvm/llvm-project/issues/105978
389 if (result.cpu.arch.isArmOrThumb() and result.floatAbi() == .soft) {399 if (result.cpu.arch.isArmOrThumb() and result.floatAbi() == .soft) {
390 result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));400 result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));