zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9aa93a045ebbf7d5c6349eb41e99ca516ab9ba65 (tree)
parent b9153f3f1d5f29a3a90779c2a5026fb52c719ac0
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Sun, 21 Jun 2026 14:52:18 +0100

Lld: don't include shared libraries in static archives

The only reason this wasn't causing more problems is because both LLD
and our old ELF linker both ignore bogus archive entries! `Elf2`, OTOH,
emits an error when it encounters such an entry, which is how this was
spotted.

Diffstat:
Msrc/link/Lld.zig | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/link/Lld.zig b/src/link/Lld.zig @@ -304,14 +304,16 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void { // insight as to what's going on here you can read that function body which is more // well-commented. - const link_inputs = comp.link_inputs; - var object_files: std.ArrayList([*:0]const u8) = .empty; - try object_files.ensureUnusedCapacity(arena, link_inputs.len); - for (link_inputs) |input| { - object_files.appendAssumeCapacity(try input.path().?.toStringZ(arena)); - } + try object_files.ensureUnusedCapacity(arena, comp.link_inputs.len); + for (comp.link_inputs) |input| switch (input) { + .res, .dso, .dso_exact => {}, // shared libraries should not be included in static archives + .object, .archive => { + const path = try input.path().?.toStringZ(arena); + object_files.appendAssumeCapacity(path); + }, + }; try object_files.ensureUnusedCapacity(arena, comp.c_objects.items.len + comp.win32_resources.items.len + 2);