Skip to content

Commit 8d5d44f

Browse files
committed
Compilation: strip debug info from ReleaseSmall by default
1 parent f374ea2 commit 8d5d44f

File tree

10 files changed

+29
-15
lines changed

10 files changed

+29
-15
lines changed

build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,15 @@ pub fn build(b: *Builder) !void {
309309
.Debug => {},
310310
.ReleaseFast => {
311311
zig1_obj.addArg("-OReleaseFast");
312-
zig1_obj.addArg("--strip");
312+
zig1_obj.addArg("-fstrip");
313313
},
314314
.ReleaseSafe => {
315315
zig1_obj.addArg("-OReleaseSafe");
316-
zig1_obj.addArg("--strip");
316+
zig1_obj.addArg("-fstrip");
317317
},
318318
.ReleaseSmall => {
319319
zig1_obj.addArg("-OReleaseSmall");
320-
zig1_obj.addArg("--strip");
320+
zig1_obj.addArg("-fstrip");
321321
},
322322
}
323323
if (single_threaded orelse false) {

lib/std/build.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ pub const LibExeObjStep = struct {
14681468
kind: Kind,
14691469
major_only_filename: ?[]const u8,
14701470
name_only_filename: ?[]const u8,
1471-
strip: bool,
1471+
strip: ?bool,
14721472
// keep in sync with src/link.zig:CompressDebugSections
14731473
compress_debug_sections: enum { none, zlib } = .none,
14741474
lib_paths: ArrayList([]const u8),
@@ -1738,7 +1738,7 @@ pub const LibExeObjStep = struct {
17381738

17391739
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
17401740
self.* = LibExeObjStep{
1741-
.strip = false,
1741+
.strip = null,
17421742
.builder = builder,
17431743
.verbose_link = false,
17441744
.verbose_cc = false,
@@ -1953,7 +1953,7 @@ pub const LibExeObjStep = struct {
19531953

19541954
pub fn producesPdbFile(self: *LibExeObjStep) bool {
19551955
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;
19571957
return self.isDynamicLibrary() or self.kind == .exe or self.kind == .test_exe;
19581958
}
19591959

@@ -2690,8 +2690,12 @@ pub const LibExeObjStep = struct {
26902690

26912691
if (self.emit_h) try zig_args.append("-femit-h");
26922692

2693-
if (self.strip) {
2694-
try zig_args.append("--strip");
2693+
if (self.strip) |strip| {
2694+
if (strip) {
2695+
try zig_args.append("-fstrip");
2696+
} else {
2697+
try zig_args.append("-fno-strip");
2698+
}
26952699
}
26962700

26972701
switch (self.compress_debug_sections) {

src/Compilation.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ pub const InitOptions = struct {
916916
use_clang: ?bool = null,
917917
use_stage1: ?bool = null,
918918
single_threaded: ?bool = null,
919+
strip: ?bool = null,
919920
rdynamic: bool = false,
920-
strip: bool = false,
921921
function_sections: bool = false,
922922
no_builtin: bool = false,
923923
is_native_os: bool,
@@ -1422,7 +1422,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
14221422
break :blk buf.items[0 .. buf.items.len - 1 :0].ptr;
14231423
} 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);
14261426
const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
14271427
const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
14281428
const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {

src/main.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ const usage_build_generic =
404404
\\ -fno-builtin Disable implicit builtin knowledge of functions
405405
\\ -ffunction-sections Places each function in a separate section
406406
\\ -fno-function-sections All functions go into same section
407-
\\ --strip Omit debug symbols
407+
\\ -fstrip Omit debug symbols
408+
\\ -fno-strip Keep debug symbols
408409
\\ -ofmt=[mode] Override target object format
409410
\\ elf Executable and Linking Format
410411
\\ c C source code
@@ -630,7 +631,7 @@ fn buildOutputType(
630631
var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };
631632
var have_version = false;
632633
var compatibility_version: ?std.builtin.Version = null;
633-
var strip = false;
634+
var strip: ?bool = null;
634635
var function_sections = false;
635636
var no_builtin = false;
636637
var watch = false;
@@ -1296,8 +1297,10 @@ fn buildOutputType(
12961297
} else if (mem.eql(u8, arg, "--show-builtin")) {
12971298
show_builtin = true;
12981299
emit_bin = .no;
1299-
} else if (mem.eql(u8, arg, "--strip")) {
1300+
} else if (mem.eql(u8, arg, "-fstrip")) {
13001301
strip = true;
1302+
} else if (mem.eql(u8, arg, "-fno-strip")) {
1303+
strip = false;
13011304
} else if (mem.eql(u8, arg, "-fsingle-threaded")) {
13021305
single_threaded = true;
13031306
} else if (mem.eql(u8, arg, "-fno-single-threaded")) {
@@ -1432,7 +1435,6 @@ fn buildOutputType(
14321435
.cc, .cpp => {
14331436
emit_h = .no;
14341437
soname = .no;
1435-
strip = false;
14361438
ensure_libc_on_non_freestanding = true;
14371439
ensure_libcpp_on_non_freestanding = arg_mode == .cpp;
14381440
want_native_include_dirs = true;
@@ -2186,6 +2188,9 @@ fn buildOutputType(
21862188
},
21872189
}
21882190

2191+
if (arg_mode == .build and optimize_mode == .ReleaseSmall and strip == null)
2192+
strip = true;
2193+
21892194
if (arg_mode == .translate_c and c_source_files.items.len != 1) {
21902195
fatal("translate-c expects exactly 1 source file (found {d})", .{c_source_files.items.len});
21912196
}

test/cli.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
133133
"--cache-dir", dir_path,
134134
"--name", "example",
135135
"-fno-emit-bin", "-fno-emit-h",
136-
"--strip", "-OReleaseFast",
136+
"-fstrip", "-OReleaseFast",
137137
example_zig_path,
138138
});
139139

test/link/wasm/archive/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn build(b: *Builder) void {
1515
lib.use_llvm = false;
1616
lib.use_stage1 = false;
1717
lib.use_lld = false;
18+
lib.strip = false;
1819

1920
const check = lib.checkObject(.wasm);
2021
check.checkStart("Section import");

test/link/wasm/bss/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
1313
lib.use_llvm = false;
1414
lib.use_stage1 = false;
1515
lib.use_lld = false;
16+
lib.strip = false;
1617
// to make sure the bss segment is emitted, we must import memory
1718
lib.import_memory = true;
1819
lib.install();

test/link/wasm/segments/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
1313
lib.use_llvm = false;
1414
lib.use_stage1 = false;
1515
lib.use_lld = false;
16+
lib.strip = false;
1617
lib.install();
1718

1819
const check_lib = lib.checkObject(.wasm);

test/link/wasm/stack_pointer/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
1313
lib.use_llvm = false;
1414
lib.use_stage1 = false;
1515
lib.use_lld = false;
16+
lib.strip = false;
1617
lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size
1718
lib.install();
1819

test/link/wasm/type/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn build(b: *Builder) void {
1313
lib.use_llvm = false;
1414
lib.use_stage1 = false;
1515
lib.use_lld = false;
16+
lib.strip = false;
1617
lib.install();
1718

1819
const check_lib = lib.checkObject(.wasm);

0 commit comments

Comments
 (0)