Commit e37c55bae0

Andrew Kelley <andrew@ziglang.org>
2022-01-25 19:52:13
link: Elf, Wasm: forward strip flag when linking with LLD
1 parent 93545fe
Changed files (3)
src/link/Coff.zig
@@ -949,6 +949,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);
 
src/link/Elf.zig
@@ -1337,6 +1337,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| {
@@ -1477,6 +1478,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");
src/link/Wasm.zig
@@ -1028,6 +1028,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);
         }
@@ -1107,6 +1108,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
             try argv.append("--import-memory");
         }
 
+        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);