From 72f0ae7ec46c24d59aef2fae793275bede59ac8c Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sun, 31 May 2026 08:21:59 +0100 Subject: [PATCH] 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.) --- src/Compilation/Config.zig | 2 +- src/main.zig | 2 +- src/target.zig | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 62dfca1e4ba78962110220f42002d6effdb5af6a..ea9929bbcd70986deacc74d28f94660b060dd217 100644 --- 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 index 1e674077e461dc63c5be1c6a25dc0d0ca1056f12..7dc632c7b184298e3d4b7f5242cd69281ef5c334 100644 --- 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 index 56c429a13496f37f2f66c16a97d1c497992476f3..997dbb89453bf30bcbc5cb172000684c27d75ba6 100644 --- 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, }; } -- 2.54.0