authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-26 10:37:15+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-09-22 12:31:23+01:00
log82d389279cad3773d456860a5eedca494d301f9b
treebc755a4fa575be4f400d1784a7053957a121ddc8
parent9101d0395e28053a8cbceac40821afd15db127d3
signature Commit is signed but in an unrecognized format.

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.

2 files changed, 19 insertions(+), 0 deletions(-)

src/Compilation/Config.zig+8
...@@ -413,6 +413,12 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -413,6 +413,12 @@ pub fn resolve(options: Options) ResolveError!Config {
413 // assume no LLD.413 // assume no LLD.
414 if (options.use_new_linker == true) break :b false;414 if (options.use_new_linker == true) break :b false;
415415
416 if (options.use_new_linker == null and
417 target_util.preferNewLinkerOverLld(target))
418 {
419 break :b false;
420 }
421
416 // If we have no zig code to compile, no need for the self-hosted linker.422 // If we have no zig code to compile, no need for the self-hosted linker.
417 if (!options.have_zcu) break :b true;423 if (!options.have_zcu) break :b true;
418424
...@@ -448,6 +454,8 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -448,6 +454,8 @@ pub fn resolve(options: Options) ResolveError!Config {
448454
449 if (options.use_new_linker) |x| break :b x;455 if (options.use_new_linker) |x| break :b x;
450456
457 if (target_util.preferNewLinkerOverLld(target)) break :b true;
458
451 break :b options.incremental;459 break :b options.incremental;
452 };460 };
453461
src/target.zig+11
...@@ -285,6 +285,17 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {...@@ -285,6 +285,17 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
285 };285 };
286}286}
287287
288pub fn preferNewLinkerOverLld(target: *const std.Target) bool {
289 return switch (target.ofmt) {
290 .elf => switch (target.cpu.arch) {
291 // Elf2 is more complete than LLD on these targets.
292 .sparc64 => true,
293 else => false,
294 },
295 else => false,
296 };
297}
298
288/// Returns `true` if `ofmt` has two linker implementations, so `-fnew-linker` is meaningful.299/// Returns `true` if `ofmt` has two linker implementations, so `-fnew-linker` is meaningful.
289pub fn hasNewLinker(ofmt: std.Target.ObjectFormat) bool {300pub fn hasNewLinker(ofmt: std.Target.ObjectFormat) bool {
290 return switch (ofmt) {301 return switch (ofmt) {