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 {
30623062// member indicates, for each member file.
30633063/// String that begins an archive file.
30643064pub const ARMAG = "!<arch>\n";
3065/// String that begins a thin archive file.
3066pub const ARMAG_THIN = "!<thin>\n";
30653067/// String in ar_fmag at the end of each header.
30663068pub const ARFMAG = "`\n";
30673069/// 32-bit symtab identifier
src/link.zig+4-1
......@@ -2226,7 +2226,10 @@ fn resolvePathInputLib(
22262226 const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|
22272227 fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });
22282228 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 {
22302233 // Appears to be an ELF or archive file.
22312234 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
22322235 }