commit 72f0ae7ec46c24d59aef2fae793275bede59ac8c (tree)
parent 95eb37a198271373b9c4918ce885bb959418e67e
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Sun, 31 May 2026 08:21:59 +0100
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.)
Diffstat:
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig
@@ -441,7 +441,7 @@ pub fn resolve(options: Options) ResolveError!Config {
break :b false;
}
- if (!target_util.hasNewLinkerSupport(target.ofmt, backend)) {
+ if (!target_util.hasNewLinker(target.ofmt)) {
if (options.use_new_linker == true) return error.NewLinkerIncompatibleObjectFormat;
break :b false;
}
diff --git a/src/main.zig b/src/main.zig
@@ -4137,8 +4137,8 @@ fn createModule(
error.LldUnavailable => fatal("zig was compiled without LLD libraries", .{}),
error.ClangUnavailable => fatal("zig was compiled without Clang libraries", .{}),
error.DllExportFnsRequiresWindows => fatal("only Windows OS targets support DLLs", .{}),
- error.NewLinkerIncompatibleObjectFormat => fatal("using the new linker to link {s} files is unsupported", .{@tagName(target.ofmt)}),
error.NewLinkerIncompatibleWithLld => fatal("using the new linker is incompatible with using lld", .{}),
+ error.NewLinkerIncompatibleObjectFormat => fatal("no new linker available for '{t}' files", .{target.ofmt}),
};
}
diff --git a/src/target.zig b/src/target.zig
@@ -275,12 +275,10 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
};
}
-pub fn hasNewLinkerSupport(ofmt: std.Target.ObjectFormat, backend: std.lang.CompilerBackend) bool {
+/// Returns `true` if `ofmt` has two linker implementations, so `-fnew-linker` is meaningful.
+pub fn hasNewLinker(ofmt: std.Target.ObjectFormat) bool {
return switch (ofmt) {
- .elf, .coff => switch (backend) {
- .stage2_x86_64 => true,
- else => false,
- },
+ .elf => true,
else => false,
};
}