From 366c76744429cb9c2fcd60abad191b7ef40ed5db Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 25 Jan 2022 11:52:13 -0700 Subject: [PATCH] link: Elf, Wasm: forward strip flag when linking with LLD --- src/link/Coff.zig | 1 + src/link/Elf.zig | 5 +++++ src/link/Wasm.zig | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 5d24e42fadd427dd2f2b5eff790b06cef368ab45..20a76f49a2ad9ab1a8ff5a8eebeab93368e7e01b 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -972,6 +972,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { man.hash.add(self.base.options.tsaware); man.hash.add(self.base.options.nxcompat); man.hash.add(self.base.options.dynamicbase); + // strip does not need to go into the linker hash because it is part of the hash namespace man.hash.addOptional(self.base.options.major_subsystem_version); man.hash.addOptional(self.base.options.minor_subsystem_version); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index d83b5fde7336210f65b2d6adf5989e04c9f8c8fc..a7ce8d0783cad7d9d129850b70a0825408e6b3f0 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1414,6 +1414,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { man.hash.add(self.base.options.z_noexecstack); man.hash.add(self.base.options.z_now); man.hash.add(self.base.options.z_relro); + // strip does not need to go into the linker hash because it is part of the hash namespace if (self.base.options.link_libc) { man.hash.add(self.base.options.libc_installation != null); if (self.base.options.libc_installation) |libc_installation| { @@ -1554,6 +1555,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { try argv.append("--export-dynamic"); } + if (self.base.options.strip) { + try argv.append("-s"); + } + if (self.base.options.z_nodelete) { try argv.append("-z"); try argv.append("nodelete"); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index f0b1f75239613e8bf763ce7f35dec1a957a8a8ff..9a9c6c464cb8aec47411ba73f584b4196498947d 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -1223,6 +1223,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { man.hash.addOptional(self.base.options.max_memory); man.hash.addOptional(self.base.options.global_base); man.hash.add(self.base.options.export_symbol_names.len); + // strip does not need to go into the linker hash because it is part of the hash namespace for (self.base.options.export_symbol_names) |symbol_name| { man.hash.addBytes(symbol_name); } @@ -1311,6 +1312,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { try argv.append("--export-table"); } + if (self.base.options.strip) { + try argv.append("-s"); + } + if (self.base.options.initial_memory) |initial_memory| { const arg = try std.fmt.allocPrint(arena, "--initial-memory={d}", .{initial_memory}); try argv.append(arg); -- 2.54.0