authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2025-07-09 19:03:16+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-11 04:57:54+02:00
logf551c7c581c7bf1f3324c0611a73c22f2aae82b4
tree41e8a857c7fc2b78e3e77ca3711d30c2e38e2053
parent5360968e03525be4d312ca61a7ba2dcb7890ec42

link.Elf: check files in archives for ELF magic

Apparently raw LLVM IR Bitcode files ("Bitstreams") may appear in archives with LTO enabled. I observed this in the wild on Chimera Linux. I'm not yet sure if it's in scope for Zig to support these special archives, but we should at least give a correct error message.

1 files changed, 3 insertions(+), 0 deletions(-)

src/link/Elf/Object.zig+3
......@@ -106,6 +106,9 @@ pub fn parseCommon(
106106 const header_buffer = try Elf.preadAllAlloc(gpa, handle, offset, @sizeOf(elf.Elf64_Ehdr));
107107 defer gpa.free(header_buffer);
108108 self.header = @as(*align(1) const elf.Elf64_Ehdr, @ptrCast(header_buffer)).*;
109 if (!mem.eql(u8, self.header.?.e_ident[0..4], elf.MAGIC)) {
110 return diags.failParse(path, "not an ELF file", .{});
111 }
109112
110113 const em = target.toElfMachine();
111114 if (em != self.header.?.e_machine) {