From 9aa93a045ebbf7d5c6349eb41e99ca516ab9ba65 Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sun, 21 Jun 2026 14:52:18 +0100 Subject: [PATCH] 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. --- src/link/Lld.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/link/Lld.zig b/src/link/Lld.zig index d84e3c1fe2a68042dd90ead613f9e9f17c80e740..c4c4e0fb3d721cc134473db4b348ee65a048d08e 100644 --- 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); -- 2.54.0