authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-19 11:04:01+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-20 14:29:58+01:00
logea475556756d5afbaf88d472e9b223ab2a1ca1f4
treeb2e2e95dc329ee3107acf0f9727f2b9a18a001a5
parent4c9235d969ed052b6325805669ecd63ebeb6d062
signature Commit is signed but in an unrecognized format.

Elf2: don't emulate a ZCU input object when building a static library

In this case, there is a *literal* ZCU input object in the static library itself. This was causing a safety check to occasionally trip in safe compiler builds. First noticed when debugging an unrelated issue: see https://codeberg.org/ziglang/zig/issues/37327#issuecomment-25643513. Resolves: https://codeberg.org/ziglang/zig/issues/37327

1 files changed, 21 insertions(+), 18 deletions(-)

src/link/Elf2.zig+21-18
......@@ -8421,24 +8421,27 @@ fn prelinkInner(elf: *Elf) Error!void {
84218421 if (comp.zcu) |_| self_hosted_codegen: {
84228422 if (comp.config.use_llvm) break :self_hosted_codegen;
84238423
8424 // We're using self-hosted codegen---add an input representing the Zig "object".
8425 try elf.inputs.ensureUnusedCapacity(gpa, 1);
8426 const zcu_name = try std.fmt.allocPrint(gpa, "{s}_zcu", .{comp.root_name});
8427 defer gpa.free(zcu_name);
8428 const zcu_file_symbol = try elf.addLocalSymbol(.{
8429 .node = .none,
8430 .name = zcu_name,
8431 .value = 0,
8432 .size = 0,
8433 .type = .FILE,
8434 .shndx = .ABS,
8435 });
8436 elf.inputs.addOneAssumeCapacity().* = .{
8437 .path = elf.base.emit,
8438 .member = null,
8439 .extra = .{ .file_symbol = zcu_file_symbol },
8440 };
8441 elf.input_pending_index += 1;
8424 if (elf.archive == null) {
8425 // Self-hosted codegen is logically emitting a relocatable which is then immediately
8426 // being linked into the output file, so add that fictional Zig object file input.
8427 try elf.inputs.ensureUnusedCapacity(gpa, 1);
8428 const zcu_name = try std.fmt.allocPrint(gpa, "{s}_zcu", .{comp.root_name});
8429 defer gpa.free(zcu_name);
8430 const zcu_file_symbol = try elf.addLocalSymbol(.{
8431 .node = .none,
8432 .name = zcu_name,
8433 .value = 0,
8434 .size = 0,
8435 .type = .FILE,
8436 .shndx = .ABS,
8437 });
8438 elf.inputs.addOneAssumeCapacity().* = .{
8439 .path = elf.base.emit,
8440 .member = null,
8441 .extra = .{ .file_symbol = zcu_file_symbol },
8442 };
8443 elf.input_pending_index += 1;
8444 }
84428445
84438446 switch (elf.shndx.debug_addr) {
84448447 .UNDEF => {},