authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2022-10-05 14:33:11+03:30
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-11 17:51:25+02:00
logd086b371f0e21e5029e1b0d05838b87502eb63e6
tree01fc7376ec6e1dc9179b8f40536ee855ce8017c7
parent42a3b60c331cf01d1ab80eb79e959bc86397f75b

Compilation: strip debug info from ReleaseSmall by default


10 files changed, 29 insertions(+), 15 deletions(-)

build.zig+3-3
...@@ -309,15 +309,15 @@ pub fn build(b: *Builder) !void {...@@ -309,15 +309,15 @@ pub fn build(b: *Builder) !void {
309 .Debug => {},309 .Debug => {},
310 .ReleaseFast => {310 .ReleaseFast => {
311 zig1_obj.addArg("-OReleaseFast");311 zig1_obj.addArg("-OReleaseFast");
312 zig1_obj.addArg("--strip");312 zig1_obj.addArg("-fstrip");
313 },313 },
314 .ReleaseSafe => {314 .ReleaseSafe => {
315 zig1_obj.addArg("-OReleaseSafe");315 zig1_obj.addArg("-OReleaseSafe");
316 zig1_obj.addArg("--strip");316 zig1_obj.addArg("-fstrip");
317 },317 },
318 .ReleaseSmall => {318 .ReleaseSmall => {
319 zig1_obj.addArg("-OReleaseSmall");319 zig1_obj.addArg("-OReleaseSmall");
320 zig1_obj.addArg("--strip");320 zig1_obj.addArg("-fstrip");
321 },321 },
322 }322 }
323 if (single_threaded orelse false) {323 if (single_threaded orelse false) {
lib/std/build.zig+9-5
...@@ -1468,7 +1468,7 @@ pub const LibExeObjStep = struct {...@@ -1468,7 +1468,7 @@ pub const LibExeObjStep = struct {
1468 kind: Kind,1468 kind: Kind,
1469 major_only_filename: ?[]const u8,1469 major_only_filename: ?[]const u8,
1470 name_only_filename: ?[]const u8,1470 name_only_filename: ?[]const u8,
1471 strip: bool,1471 strip: ?bool,
1472 // keep in sync with src/link.zig:CompressDebugSections1472 // keep in sync with src/link.zig:CompressDebugSections
1473 compress_debug_sections: enum { none, zlib } = .none,1473 compress_debug_sections: enum { none, zlib } = .none,
1474 lib_paths: ArrayList([]const u8),1474 lib_paths: ArrayList([]const u8),
...@@ -1738,7 +1738,7 @@ pub const LibExeObjStep = struct {...@@ -1738,7 +1738,7 @@ pub const LibExeObjStep = struct {
17381738
1739 const self = builder.allocator.create(LibExeObjStep) catch unreachable;1739 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
1740 self.* = LibExeObjStep{1740 self.* = LibExeObjStep{
1741 .strip = false,1741 .strip = null,
1742 .builder = builder,1742 .builder = builder,
1743 .verbose_link = false,1743 .verbose_link = false,
1744 .verbose_cc = false,1744 .verbose_cc = false,
...@@ -1953,7 +1953,7 @@ pub const LibExeObjStep = struct {...@@ -1953,7 +1953,7 @@ pub const LibExeObjStep = struct {
19531953
1954 pub fn producesPdbFile(self: *LibExeObjStep) bool {1954 pub fn producesPdbFile(self: *LibExeObjStep) bool {
1955 if (!self.target.isWindows() and !self.target.isUefi()) return false;1955 if (!self.target.isWindows() and !self.target.isUefi()) return false;
1956 if (self.strip) return false;1956 if (self.strip != null and self.strip.?) return false;
1957 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .test_exe;1957 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .test_exe;
1958 }1958 }
19591959
...@@ -2690,8 +2690,12 @@ pub const LibExeObjStep = struct {...@@ -2690,8 +2690,12 @@ pub const LibExeObjStep = struct {
26902690
2691 if (self.emit_h) try zig_args.append("-femit-h");2691 if (self.emit_h) try zig_args.append("-femit-h");
26922692
2693 if (self.strip) {2693 if (self.strip) |strip| {
2694 try zig_args.append("--strip");2694 if (strip) {
2695 try zig_args.append("-fstrip");
2696 } else {
2697 try zig_args.append("-fno-strip");
2698 }
2695 }2699 }
26962700
2697 switch (self.compress_debug_sections) {2701 switch (self.compress_debug_sections) {
src/Compilation.zig+2-2
...@@ -916,8 +916,8 @@ pub const InitOptions = struct {...@@ -916,8 +916,8 @@ pub const InitOptions = struct {
916 use_clang: ?bool = null,916 use_clang: ?bool = null,
917 use_stage1: ?bool = null,917 use_stage1: ?bool = null,
918 single_threaded: ?bool = null,918 single_threaded: ?bool = null,
919 strip: ?bool = null,
919 rdynamic: bool = false,920 rdynamic: bool = false,
920 strip: bool = false,
921 function_sections: bool = false,921 function_sections: bool = false,
922 no_builtin: bool = false,922 no_builtin: bool = false,
923 is_native_os: bool,923 is_native_os: bool,
...@@ -1422,7 +1422,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1422,7 +1422,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1422 break :blk buf.items[0 .. buf.items.len - 1 :0].ptr;1422 break :blk buf.items[0 .. buf.items.len - 1 :0].ptr;
1423 } else null;1423 } else null;
14241424
1425 const strip = options.strip or !target_util.hasDebugInfo(options.target);1425 const strip = options.strip orelse !target_util.hasDebugInfo(options.target);
1426 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);1426 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
1427 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);1427 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
1428 const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {1428 const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {
src/main.zig+9-4
...@@ -404,7 +404,8 @@ const usage_build_generic =...@@ -404,7 +404,8 @@ const usage_build_generic =
404 \\ -fno-builtin Disable implicit builtin knowledge of functions404 \\ -fno-builtin Disable implicit builtin knowledge of functions
405 \\ -ffunction-sections Places each function in a separate section405 \\ -ffunction-sections Places each function in a separate section
406 \\ -fno-function-sections All functions go into same section406 \\ -fno-function-sections All functions go into same section
407 \\ --strip Omit debug symbols407 \\ -fstrip Omit debug symbols
408 \\ -fno-strip Keep debug symbols
408 \\ -ofmt=[mode] Override target object format409 \\ -ofmt=[mode] Override target object format
409 \\ elf Executable and Linking Format410 \\ elf Executable and Linking Format
410 \\ c C source code411 \\ c C source code
...@@ -630,7 +631,7 @@ fn buildOutputType(...@@ -630,7 +631,7 @@ fn buildOutputType(
630 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };631 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };
631 var have_version = false;632 var have_version = false;
632 var compatibility_version: ?std.builtin.Version = null;633 var compatibility_version: ?std.builtin.Version = null;
633 var strip = false;634 var strip: ?bool = null;
634 var function_sections = false;635 var function_sections = false;
635 var no_builtin = false;636 var no_builtin = false;
636 var watch = false;637 var watch = false;
...@@ -1296,8 +1297,10 @@ fn buildOutputType(...@@ -1296,8 +1297,10 @@ fn buildOutputType(
1296 } else if (mem.eql(u8, arg, "--show-builtin")) {1297 } else if (mem.eql(u8, arg, "--show-builtin")) {
1297 show_builtin = true;1298 show_builtin = true;
1298 emit_bin = .no;1299 emit_bin = .no;
1299 } else if (mem.eql(u8, arg, "--strip")) {1300 } else if (mem.eql(u8, arg, "-fstrip")) {
1300 strip = true;1301 strip = true;
1302 } else if (mem.eql(u8, arg, "-fno-strip")) {
1303 strip = false;
1301 } else if (mem.eql(u8, arg, "-fsingle-threaded")) {1304 } else if (mem.eql(u8, arg, "-fsingle-threaded")) {
1302 single_threaded = true;1305 single_threaded = true;
1303 } else if (mem.eql(u8, arg, "-fno-single-threaded")) {1306 } else if (mem.eql(u8, arg, "-fno-single-threaded")) {
...@@ -1432,7 +1435,6 @@ fn buildOutputType(...@@ -1432,7 +1435,6 @@ fn buildOutputType(
1432 .cc, .cpp => {1435 .cc, .cpp => {
1433 emit_h = .no;1436 emit_h = .no;
1434 soname = .no;1437 soname = .no;
1435 strip = false;
1436 ensure_libc_on_non_freestanding = true;1438 ensure_libc_on_non_freestanding = true;
1437 ensure_libcpp_on_non_freestanding = arg_mode == .cpp;1439 ensure_libcpp_on_non_freestanding = arg_mode == .cpp;
1438 want_native_include_dirs = true;1440 want_native_include_dirs = true;
...@@ -2186,6 +2188,9 @@ fn buildOutputType(...@@ -2186,6 +2188,9 @@ fn buildOutputType(
2186 },2188 },
2187 }2189 }
21882190
2191 if (arg_mode == .build and optimize_mode == .ReleaseSmall and strip == null)
2192 strip = true;
2193
2189 if (arg_mode == .translate_c and c_source_files.items.len != 1) {2194 if (arg_mode == .translate_c and c_source_files.items.len != 1) {
2190 fatal("translate-c expects exactly 1 source file (found {d})", .{c_source_files.items.len});2195 fatal("translate-c expects exactly 1 source file (found {d})", .{c_source_files.items.len});
2191 }2196 }
test/cli.zig+1-1
...@@ -133,7 +133,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {...@@ -133,7 +133,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
133 "--cache-dir", dir_path,133 "--cache-dir", dir_path,
134 "--name", "example",134 "--name", "example",
135 "-fno-emit-bin", "-fno-emit-h",135 "-fno-emit-bin", "-fno-emit-h",
136 "--strip", "-OReleaseFast",136 "-fstrip", "-OReleaseFast",
137 example_zig_path,137 example_zig_path,
138 });138 });
139139
test/link/wasm/archive/build.zig+1
...@@ -15,6 +15,7 @@ pub fn build(b: *Builder) void {...@@ -15,6 +15,7 @@ pub fn build(b: *Builder) void {
15 lib.use_llvm = false;15 lib.use_llvm = false;
16 lib.use_stage1 = false;16 lib.use_stage1 = false;
17 lib.use_lld = false;17 lib.use_lld = false;
18 lib.strip = false;
1819
19 const check = lib.checkObject(.wasm);20 const check = lib.checkObject(.wasm);
20 check.checkStart("Section import");21 check.checkStart("Section import");
test/link/wasm/bss/build.zig+1
...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
13 lib.use_llvm = false;13 lib.use_llvm = false;
14 lib.use_stage1 = false;14 lib.use_stage1 = false;
15 lib.use_lld = false;15 lib.use_lld = false;
16 lib.strip = false;
16 // to make sure the bss segment is emitted, we must import memory17 // to make sure the bss segment is emitted, we must import memory
17 lib.import_memory = true;18 lib.import_memory = true;
18 lib.install();19 lib.install();
test/link/wasm/segments/build.zig+1
...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
13 lib.use_llvm = false;13 lib.use_llvm = false;
14 lib.use_stage1 = false;14 lib.use_stage1 = false;
15 lib.use_lld = false;15 lib.use_lld = false;
16 lib.strip = false;
16 lib.install();17 lib.install();
1718
18 const check_lib = lib.checkObject(.wasm);19 const check_lib = lib.checkObject(.wasm);
test/link/wasm/stack_pointer/build.zig+1
...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
13 lib.use_llvm = false;13 lib.use_llvm = false;
14 lib.use_stage1 = false;14 lib.use_stage1 = false;
15 lib.use_lld = false;15 lib.use_lld = false;
16 lib.strip = false;
16 lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size17 lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size
17 lib.install();18 lib.install();
1819
test/link/wasm/type/build.zig+1
...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {...@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
13 lib.use_llvm = false;13 lib.use_llvm = false;
14 lib.use_stage1 = false;14 lib.use_stage1 = false;
15 lib.use_lld = false;15 lib.use_lld = false;
16 lib.strip = false;
16 lib.install();17 lib.install();
1718
18 const check_lib = lib.checkObject(.wasm);19 const check_lib = lib.checkObject(.wasm);