From 82d389279cad3773d456860a5eedca494d301f9b Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Wed, 26 Aug 2026 10:37:15 +0100 Subject: [PATCH] compiler: default to Elf2 instead of LLD on sparc64 `Elf2` is now a more complete linker implementation than LLD when targeting sparc64 on ELF. For instance, LLD is essentially incapable of building code which links against glibc on `sparc64-linux`, while `Elf2` can handle that just fine. --- src/Compilation/Config.zig | 8 ++++++++ src/target.zig | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 85915ded1b97d4e324a1cebbdb1385758ebea6f0..3691b1eb423b72130b0fd8e962137a08a1da1d61 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -413,6 +413,12 @@ pub fn resolve(options: Options) ResolveError!Config { // assume no LLD. if (options.use_new_linker == true) break :b false; + if (options.use_new_linker == null and + target_util.preferNewLinkerOverLld(target)) + { + break :b false; + } + // If we have no zig code to compile, no need for the self-hosted linker. if (!options.have_zcu) break :b true; @@ -448,6 +454,8 @@ pub fn resolve(options: Options) ResolveError!Config { if (options.use_new_linker) |x| break :b x; + if (target_util.preferNewLinkerOverLld(target)) break :b true; + break :b options.incremental; }; diff --git a/src/target.zig b/src/target.zig index 01fe63f4ef1bc77aaa56c4246298deb17715d8a7..81d39c22fa4d81129016bd58b04c97a6e3e7a1b6 100644 --- a/src/target.zig +++ b/src/target.zig @@ -285,6 +285,17 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool { }; } +pub fn preferNewLinkerOverLld(target: *const std.Target) bool { + return switch (target.ofmt) { + .elf => switch (target.cpu.arch) { + // Elf2 is more complete than LLD on these targets. + .sparc64 => true, + else => false, + }, + else => false, + }; +} + /// Returns `true` if `ofmt` has two linker implementations, so `-fnew-linker` is meaningful. pub fn hasNewLinker(ofmt: std.Target.ObjectFormat) bool { return switch (ofmt) { -- 2.54.0