aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Bouchoux <xavierb@gmail.com>2024-10-26 10:37:39 +0200
committerAlex Rønne Petersen <alex@alexrp.com>2024-10-26 19:46:40 +0200
commit6a364b4a5e71b971b753d2b62c7708ae1e76d707 (patch)
tree3e5292fc32849a00f9b90c002e01d2a1f6492193 /src
parentb1361f237aa6b2584e6dbc43c8ae8dc74394eb64 (diff)
downloadzig-6a364b4a5e71b971b753d2b62c7708ae1e76d707.tar.gz
zig-6a364b4a5e71b971b753d2b62c7708ae1e76d707.zip
link/Elf.zig: ensure capacity before appending linker args.
fixes e567abb339e1edaf5a3c86fe632522a3b8005275 "rework linker inputs" closes https://github.com/ziglang/zig/issues/21801
Diffstat (limited to 'src')
-rw-r--r--src/link/Elf.zig3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index d02d98800d..8a5e8f9282 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -1962,7 +1962,8 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
if (is_exe_or_dyn_lib) {
// Worst-case, we need an --as-needed argument for every lib, as well
// as one before and one after.
- try argv.append("--as-needed");
+ try argv.ensureUnusedCapacity(2 * self.base.comp.link_inputs.len + 2);
+ argv.appendAssumeCapacity("--as-needed");
var as_needed = true;
for (self.base.comp.link_inputs) |link_input| switch (link_input) {