From 56b0c7bd2f5936c17571e878f835cf0d542ca1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 2 Oct 2024 08:15:19 +0200 Subject: [PATCH] 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. --- lib/std/zig/system.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 046bd3854e..9fcaaf0cb1 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -385,6 +385,16 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { query.cpu_features_sub, ); + if (cpu_arch == .hexagon) { + // Both LLVM and LLD have broken support for the small data area. Yet LLVM has the feature + // on by default for all Hexagon CPUs. Clang sort of solves this by defaulting the `-gpsize` + // command line parameter for the Hexagon backend to 0, so that no constants get placed in + // the SDA. (This of course breaks down if the user passes `-G ` to Clang...) We can't do + // the `-gpsize` hack because we can have multiple concurrent LLVM emit jobs, and command + // line options in LLVM are shared globally. So just force this feature off. Lovely stuff. + result.cpu.features.removeFeature(@intFromEnum(Target.hexagon.Feature.small_data)); + } + // https://github.com/llvm/llvm-project/issues/105978 if (result.cpu.arch.isArmOrThumb() and result.floatAbi() == .soft) { result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));