authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-06-21 14:52:18+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-21 20:31:19+02:00
log9aa93a045ebbf7d5c6349eb41e99ca516ab9ba65
treec95ca70d3ce8427b9b40a739e2447a5c55c17a5a
parentb9153f3f1d5f29a3a90779c2a5026fb52c719ac0

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.

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

src/link/Lld.zig+8-6
......@@ -304,14 +304,16 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
304304 // insight as to what's going on here you can read that function body which is more
305305 // well-commented.
306306
307 const link_inputs = comp.link_inputs;
308
309307 var object_files: std.ArrayList([*:0]const u8) = .empty;
310308
311 try object_files.ensureUnusedCapacity(arena, link_inputs.len);
312 for (link_inputs) |input| {
313 object_files.appendAssumeCapacity(try input.path().?.toStringZ(arena));
314 }
309 try object_files.ensureUnusedCapacity(arena, comp.link_inputs.len);
310 for (comp.link_inputs) |input| switch (input) {
311 .res, .dso, .dso_exact => {}, // shared libraries should not be included in static archives
312 .object, .archive => {
313 const path = try input.path().?.toStringZ(arena);
314 object_files.appendAssumeCapacity(path);
315 },
316 };
315317
316318 try object_files.ensureUnusedCapacity(arena, comp.c_objects.items.len +
317319 comp.win32_resources.items.len + 2);