authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-31 08:21:59+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-06-04 07:27:24+01:00
log72f0ae7ec46c24d59aef2fae793275bede59ac8c
tree8aed846acdef74f722ef7b0c62bfee1efaae881f
parent95eb37a198271373b9c4918ce885bb959418e67e
signaturelock-open Commit is signed but in an unrecognized format.

Compilation.Config: improve error reporting for '-fnew-linker'

...and allow using `Elf2` with backends other than self-hosted x86_64. The new ELF linker is currently opt-in, so there's no harm in allowing backends which are not yet "officially" supported. (And also I'm going to make the LLVM backend work with `Elf2` in the next commit because that seems pretty trivial.)

3 files changed, 5 insertions(+), 7 deletions(-)

src/Compilation/Config.zig+1-1
......@@ -441,7 +441,7 @@ pub fn resolve(options: Options) ResolveError!Config {
441441 break :b false;
442442 }
443443
444 if (!target_util.hasNewLinkerSupport(target.ofmt, backend)) {
444 if (!target_util.hasNewLinker(target.ofmt)) {
445445 if (options.use_new_linker == true) return error.NewLinkerIncompatibleObjectFormat;
446446 break :b false;
447447 }
src/main.zig+1-1
......@@ -4137,8 +4137,8 @@ fn createModule(
41374137 error.LldUnavailable => fatal("zig was compiled without LLD libraries", .{}),
41384138 error.ClangUnavailable => fatal("zig was compiled without Clang libraries", .{}),
41394139 error.DllExportFnsRequiresWindows => fatal("only Windows OS targets support DLLs", .{}),
4140 error.NewLinkerIncompatibleObjectFormat => fatal("using the new linker to link {s} files is unsupported", .{@tagName(target.ofmt)}),
41414140 error.NewLinkerIncompatibleWithLld => fatal("using the new linker is incompatible with using lld", .{}),
4141 error.NewLinkerIncompatibleObjectFormat => fatal("no new linker available for '{t}' files", .{target.ofmt}),
41424142 };
41434143 }
41444144
src/target.zig+3-5
......@@ -275,12 +275,10 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
275275 };
276276}
277277
278pub fn hasNewLinkerSupport(ofmt: std.Target.ObjectFormat, backend: std.lang.CompilerBackend) bool {
278/// Returns `true` if `ofmt` has two linker implementations, so `-fnew-linker` is meaningful.
279pub fn hasNewLinker(ofmt: std.Target.ObjectFormat) bool {
279280 return switch (ofmt) {
280 .elf, .coff => switch (backend) {
281 .stage2_x86_64 => true,
282 else => false,
283 },
281 .elf => true,
284282 else => false,
285283 };
286284}