authorgravatar for maci.stgn@gmail.comMarcel W. Wysocki <maci.stgn@gmail.com> 2026-02-16 00:45:28+08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-17 23:15:32+01:00
log0e3c6514a4d1f89498bf411b58131d129218807f
tree7663f47753744a6567e9d3ecd671950e5fff655a
parent0fd8dc8ea6872a545ba7f58e0f934cfa86adb2a4

link: recognize thin archives in ld script detection

Needed for linking the Linux kernel.

2 files changed, 6 insertions(+), 1 deletions(-)

lib/std/elf.zig+2
...@@ -3062,6 +3062,8 @@ fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 {...@@ -3062,6 +3062,8 @@ fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 {
3062// member indicates, for each member file.3062// member indicates, for each member file.
3063/// String that begins an archive file.3063/// String that begins an archive file.
3064pub const ARMAG = "!<arch>\n";3064pub const ARMAG = "!<arch>\n";
3065/// String that begins a thin archive file.
3066pub const ARMAG_THIN = "!<thin>\n";
3065/// String in ar_fmag at the end of each header.3067/// String in ar_fmag at the end of each header.
3066pub const ARFMAG = "`\n";3068pub const ARFMAG = "`\n";
3067/// 32-bit symtab identifier3069/// 32-bit symtab identifier
src/link.zig+4-1
...@@ -2226,7 +2226,10 @@ fn resolvePathInputLib(...@@ -2226,7 +2226,10 @@ fn resolvePathInputLib(
2226 const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|2226 const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|
2227 fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });2227 fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });
2228 const buf = ld_script_bytes.items[0..n];2228 const buf = ld_script_bytes.items[0..n];
2229 if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {2229 if (mem.startsWith(u8, buf, std.elf.MAGIC) or
2230 mem.startsWith(u8, buf, std.elf.ARMAG) or
2231 mem.startsWith(u8, buf, std.elf.ARMAG_THIN))
2232 {
2230 // Appears to be an ELF or archive file.2233 // Appears to be an ELF or archive file.
2231 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);2234 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
2232 }2235 }