diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f5ce8529ef6..11fa6581327b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -942,7 +942,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) else() - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip) + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip=all) endif() if(ZIG_STATIC AND NOT MSVC) diff --git a/build.zig b/build.zig index b82279403ae5..b0cd780a1366 100644 --- a/build.zig +++ b/build.zig @@ -174,14 +174,14 @@ pub fn build(b: *std.Build) !void { const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false; const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c); const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false; - const strip = b.option(bool, "strip", "Omit debug information"); + const strip = b.option(std.builtin.Strip, "strip", "Omit debug information"); const valgrind = b.option(bool, "valgrind", "Enable valgrind integration"); const pie = b.option(bool, "pie", "Produce a Position Independent Executable"); const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct; const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false; const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { - if (strip == true) break :blk @as(u32, 0); + if (strip == .all) break :blk @as(u32, 0); if (optimize != .Debug) break :blk 0; break :blk 4; }; @@ -661,7 +661,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { const AddCompilerStepOptions = struct { optimize: std.builtin.OptimizeMode, target: std.Build.ResolvedTarget, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, valgrind: ?bool = null, sanitize_thread: ?bool = null, single_threaded: ?bool = null, diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh index 69eed679e3c6..d7532eecf0f9 100644 --- a/ci/aarch64-linux-release.sh +++ b/ci/aarch64-linux-release.sh @@ -68,7 +68,7 @@ stage3-release/bin/zig build \ -Denable-llvm \ -Dno-lib \ -Doptimize=ReleaseFast \ - -Dstrip \ + -Dstrip=all \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ -Dversion-string="$(stage3-release/bin/zig version)" diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh index dac793075a6b..72f5949f675c 100755 --- a/ci/aarch64-macos-release.sh +++ b/ci/aarch64-macos-release.sh @@ -62,7 +62,7 @@ stage3-release/bin/zig build \ -Denable-llvm \ -Dno-lib \ -Doptimize=ReleaseFast \ - -Dstrip \ + -Dstrip=all \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ -Dversion-string="$(stage3-release/bin/zig version)" diff --git a/ci/aarch64-windows.ps1 b/ci/aarch64-windows.ps1 index 44140506a743..46f07c088b50 100644 --- a/ci/aarch64-windows.ps1 +++ b/ci/aarch64-windows.ps1 @@ -76,7 +76,7 @@ Write-Output "Build and compare stage4..." -Denable-llvm ` -Dno-lib ` -Doptimize=ReleaseFast ` - -Dstrip ` + -Dstrip=all ` -Dtarget="$TARGET" ` -Duse-zig-libcxx ` -Dversion-string="$(stage3-release\bin\zig version)" diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index d6c0cc5701b3..202d57c6375f 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -76,7 +76,7 @@ stage3-release/bin/zig build \ -Denable-llvm \ -Dno-lib \ -Doptimize=ReleaseFast \ - -Dstrip \ + -Dstrip=all \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ -Dversion-string="$(stage3-release/bin/zig version)" diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh index 30b37819155e..b1027b5fd8fd 100755 --- a/ci/x86_64-macos-release.sh +++ b/ci/x86_64-macos-release.sh @@ -64,7 +64,7 @@ stage3/bin/zig build \ -Denable-llvm \ -Dno-lib \ -Doptimize=ReleaseFast \ - -Dstrip \ + -Dstrip=all \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ -Dversion-string="$(stage3/bin/zig version)" diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 index 965fc4b578f5..30a68ef35293 100644 --- a/ci/x86_64-windows-release.ps1 +++ b/ci/x86_64-windows-release.ps1 @@ -76,7 +76,7 @@ Write-Output "Build and compare stage4..." -Denable-llvm ` -Dno-lib ` -Doptimize=ReleaseFast ` - -Dstrip ` + -Dstrip=all ` -Dtarget="$TARGET" ` -Duse-zig-libcxx ` -Dversion-string="$(stage3-release\bin\zig version)" diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 4afdcd2bff8c..2bfecf59c97d 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -744,7 +744,10 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { .link_libc = options.link_libc, .single_threaded = options.single_threaded, .pic = options.pic, - .strip = options.strip, + .strip = if (options.strip) |should_strip| switch (should_strip) { + false => .none, + true => .all, + } else null, .unwind_tables = options.unwind_tables, .omit_frame_pointer = options.omit_frame_pointer, .sanitize_thread = options.sanitize_thread, @@ -813,7 +816,10 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { .link_libc = options.link_libc, .single_threaded = options.single_threaded, .pic = options.pic, - .strip = options.strip, + .strip = if (options.strip) |should_strip| switch (should_strip) { + false => .none, + true => .all, + } else null, .unwind_tables = options.unwind_tables, .omit_frame_pointer = options.omit_frame_pointer, .sanitize_thread = options.sanitize_thread, @@ -887,7 +893,10 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile .link_libc = options.link_libc, .single_threaded = options.single_threaded, .pic = options.pic, - .strip = options.strip, + .strip = if (options.strip) |should_strip| switch (should_strip) { + false => .none, + true => .all, + } else null, .unwind_tables = options.unwind_tables, .omit_frame_pointer = options.omit_frame_pointer, .sanitize_thread = options.sanitize_thread, @@ -958,7 +967,10 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile .link_libc = options.link_libc, .single_threaded = options.single_threaded, .pic = options.pic, - .strip = options.strip, + .strip = if (options.strip) |should_strip| switch (should_strip) { + false => .none, + true => .all, + } else null, .unwind_tables = options.unwind_tables, .omit_frame_pointer = options.omit_frame_pointer, .sanitize_thread = options.sanitize_thread, @@ -1074,7 +1086,10 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { .link_libcpp = options.link_libcpp, .single_threaded = options.single_threaded, .pic = options.pic, - .strip = options.strip, + .strip = if (options.strip) |should_strip| switch (should_strip) { + false => .none, + true => .all, + } else null, .unwind_tables = options.unwind_tables, .omit_frame_pointer = options.omit_frame_pointer, .sanitize_thread = options.sanitize_thread, diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index f29994673158..472555ee1d1f 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -17,7 +17,7 @@ rpaths: std.ArrayListUnmanaged(RPath), frameworks: std.StringArrayHashMapUnmanaged(LinkFrameworkOptions), link_objects: std.ArrayListUnmanaged(LinkObject), -strip: ?bool, +strip: ?std.builtin.Strip, unwind_tables: ?std.builtin.UnwindTables, single_threaded: ?bool, stack_protector: ?bool, @@ -246,7 +246,7 @@ pub const CreateOptions = struct { /// `null` neither requires nor prevents libc++ from being linked. link_libcpp: ?bool = null, single_threaded: ?bool = null, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, unwind_tables: ?std.builtin.UnwindTables = null, dwarf_format: ?std.dwarf.Format = null, code_model: std.builtin.CodeModel = .default, @@ -544,7 +544,6 @@ pub fn appendZigProcessFlags( ) !void { const b = m.owner; - try addFlag(zig_args, m.strip, "-fstrip", "-fno-strip"); try addFlag(zig_args, m.single_threaded, "-fsingle-threaded", "-fno-single-threaded"); try addFlag(zig_args, m.stack_check, "-fstack-check", "-fno-stack-check"); try addFlag(zig_args, m.stack_protector, "-fstack-protector", "-fno-stack-protector"); @@ -557,6 +556,14 @@ pub fn appendZigProcessFlags( try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC"); try addFlag(zig_args, m.red_zone, "-mred-zone", "-mno-red-zone"); + if (m.strip) |strip| { + try zig_args.append(switch (strip) { + .none => "-fstrip=none", + .debug_info => "-fstrip=debug_info", + .all => "-fstrip=all", + }); + } + if (m.dwarf_format) |dwarf_format| { try zig_args.append(switch (dwarf_format) { .@"32" => "-gdwarf32", diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 25061917facc..220020e95c00 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -661,7 +661,7 @@ pub fn producesPdbFile(compile: *Compile) bool { else => return false, } if (target.ofmt == .c) return false; - if (compile.root_module.strip == true or + if (compile.root_module.strip != .none or (compile.root_module.strip == null and compile.root_module.optimize == .ReleaseSmall)) { return false; diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index f1e262012e54..0274511a89f2 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -160,6 +160,16 @@ pub const OptimizeMode = enum { /// Deprecated; use OptimizeMode. pub const Mode = OptimizeMode; +/// This data structure is used by the Zig language code generation and +/// therefore must be kept in sync with the compiler implementation. +pub const Strip = enum { + none, + /// Strip debug_info while retaining symbol table. + debug_info, + /// Strip debug_info and symbol table. + all, +}; + /// The calling convention of a function defines how arguments and return values are passed, as well /// as any other requirements which callers and callees must respect, such as register preservation /// and stack alignment. diff --git a/src/Builtin.zig b/src/Builtin.zig index ac23cafb3c44..f0999913fdd1 100644 --- a/src/Builtin.zig +++ b/src/Builtin.zig @@ -14,7 +14,7 @@ sanitize_thread: bool, fuzz: bool, pic: bool, pie: bool, -strip: bool, +strip: std.builtin.Strip, code_model: std.builtin.CodeModel, omit_frame_pointer: bool, wasi_exec_model: std.builtin.WasiExecModel, @@ -228,7 +228,8 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void { \\pub const fuzz = {}; \\pub const position_independent_code = {}; \\pub const position_independent_executable = {}; - \\pub const strip_debug_info = {}; + \\pub const strip_debug_info: bool = strip == .all; + \\pub const strip: std.builtin.Strip = .{p_}; \\pub const code_model: std.builtin.CodeModel = .{p_}; \\pub const omit_frame_pointer = {}; \\ @@ -243,7 +244,7 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void { opts.fuzz, opts.pic, opts.pie, - opts.strip, + std.zig.fmtId(@tagName(opts.strip)), std.zig.fmtId(@tagName(opts.code_model)), opts.omit_frame_pointer, }); diff --git a/src/Compilation.zig b/src/Compilation.zig index 14c216854e88..d3db59113889 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6820,6 +6820,6 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { /// This decides whether to strip debug info for all zig-provided libraries, including /// compiler-rt, libcxx, libc, libunwind, etc. -pub fn compilerRtStrip(comp: Compilation) bool { +pub fn compilerRtStrip(comp: Compilation) std.builtin.Strip { return comp.root_mod.strip; } diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index ee175cce1161..da76de9d0382 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -57,7 +57,7 @@ shared_memory: bool, is_test: bool, debug_format: DebugFormat, root_optimize_mode: std.builtin.OptimizeMode, -root_strip: bool, +root_strip: std.builtin.Strip, root_error_tracing: bool, dll_export_fns: bool, rdynamic: bool, @@ -80,7 +80,7 @@ pub const Options = struct { have_zcu: bool, emit_bin: bool, root_optimize_mode: ?std.builtin.OptimizeMode = null, - root_strip: ?bool = null, + root_strip: ?std.builtin.Strip = null, root_error_tracing: ?bool = null, link_mode: ?std.builtin.LinkMode = null, ensure_libc_on_non_freestanding: bool = false, @@ -409,15 +409,15 @@ pub fn resolve(options: Options) ResolveError!Config { break :b false; }; - const root_strip = b: { + const root_strip: std.builtin.Strip = b: { if (options.root_strip) |x| break :b x; - if (root_optimize_mode == .ReleaseSmall) break :b true; - if (!target_util.hasDebugInfo(target)) break :b true; - break :b false; + if (root_optimize_mode == .ReleaseSmall) break :b .all; + if (!target_util.hasDebugInfo(target)) break :b .debug_info; + break :b .none; }; const debug_format: DebugFormat = b: { - if (root_strip and !options.any_non_stripped) break :b .strip; + if (root_strip != .none and !options.any_non_stripped) break :b .strip; if (options.debug_format) |x| break :b x; break :b switch (target.ofmt) { .elf, .goff, .macho, .wasm, .xcoff => .{ .dwarf = .@"32" }, @@ -435,7 +435,7 @@ pub fn resolve(options: Options) ResolveError!Config { const root_error_tracing = b: { if (options.root_error_tracing) |x| break :b x; - if (root_strip) break :b false; + if (root_strip == .all) break :b false; if (!backend_supports_error_tracing) break :b false; break :b switch (root_optimize_mode) { .Debug => true, diff --git a/src/Package/Module.zig b/src/Package/Module.zig index 0dec7bde76e5..43494173a73f 100644 --- a/src/Package/Module.zig +++ b/src/Package/Module.zig @@ -19,7 +19,7 @@ single_threaded: bool, error_tracing: bool, valgrind: bool, pic: bool, -strip: bool, +strip: std.builtin.Strip, omit_frame_pointer: bool, stack_check: bool, stack_protector: u32, @@ -83,7 +83,7 @@ pub const CreateOptions = struct { error_tracing: ?bool = null, valgrind: ?bool = null, pic: ?bool = null, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, omit_frame_pointer: ?bool = null, stack_check: ?bool = null, /// null means default. @@ -121,7 +121,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { const optimize_mode = options.inherited.optimize_mode orelse if (options.parent) |p| p.optimize_mode else options.global.root_optimize_mode; - const strip = b: { + const strip: std.builtin.Strip = b: { if (options.inherited.strip) |x| break :b x; if (options.parent) |p| break :b p.strip; break :b options.global.root_strip; @@ -135,7 +135,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { } if (options.inherited.valgrind) |x| break :b x; if (options.parent) |p| break :b p.valgrind; - if (strip) break :b false; + if (strip == .all) break :b false; break :b optimize_mode == .Debug; }; diff --git a/src/Sema.zig b/src/Sema.zig index ad144bf0133a..884d29a27a7e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2979,7 +2979,7 @@ fn zirStructDecl( try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -3236,7 +3236,7 @@ fn zirEnumDecl( codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -3358,7 +3358,7 @@ fn zirUnionDecl( try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -3444,7 +3444,7 @@ fn zirOpaqueDecl( codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -6727,7 +6727,7 @@ fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) Com } fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { - if (block.isComptime() or block.ownerModule().strip) return; + if (block.isComptime() or block.ownerModule().strip != .none) return; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; @@ -6753,7 +6753,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi } fn zirDbgEmptyStmt(_: *Sema, block: *Block, _: Zir.Inst.Index) CompileError!void { - if (block.isComptime() or block.ownerModule().strip) return; + if (block.isComptime() or block.ownerModule().strip != .none) return; _ = try block.addNoOp(.dbg_empty_stmt); } @@ -6776,7 +6776,7 @@ fn addDbgVar( air_tag: Air.Inst.Tag, name: []const u8, ) CompileError!void { - if (block.isComptime() or block.ownerModule().strip) return; + if (block.isComptime() or block.ownerModule().strip != .none) return; const pt = sema.pt; const zcu = pt.zcu; @@ -8135,7 +8135,7 @@ fn analyzeCall( sema.inst_map.putAssumeCapacityNoClobber(fn_zir_info.param_body[arg_idx], arg); } - const need_debug_scope = !block.isComptime() and !block.is_typeof and !block.ownerModule().strip; + const need_debug_scope = !block.isComptime() and !block.is_typeof and block.ownerModule().strip == .none; const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); try sema.air_instructions.append(gpa, .{ .tag = if (need_debug_scope) .dbg_inline_block else .block, @@ -20785,7 +20785,7 @@ fn structInitAnon( try zcu.comp.queueJob(.{ .resolve_type_fully = wip.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; try zcu.comp.queueJob(.{ .codegen_type = wip.index }); } break :ty wip.finish(ip, new_namespace_index); @@ -22102,7 +22102,7 @@ fn reifyEnum( codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -22356,7 +22356,7 @@ fn reifyUnion( try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -22709,7 +22709,7 @@ fn reifyStruct( try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (block.ownerModule().strip) break :codegen_type; + if (block.ownerModule().strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 32372bf597d5..28050ff7659d 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -1243,7 +1243,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr if (!try nav_ty.hasRuntimeBitsSema(pt)) { if (zcu.comp.config.use_llvm) break :queue_codegen; - if (file.mod.strip) break :queue_codegen; + if (file.mod.strip != .none) break :queue_codegen; } // This job depends on any resolve_type_fully jobs queued up before it. @@ -1797,7 +1797,7 @@ fn createFileRootStruct( try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); codegen_type: { if (zcu.comp.config.use_llvm) break :codegen_type; - if (file.mod.strip) break :codegen_type; + if (file.mod.strip != .none) break :codegen_type; // This job depends on any resolve_type_fully jobs queued up before it. try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index }); } @@ -2683,7 +2683,7 @@ fn analyzeFnBodyInner(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaE .tag = .arg, .data = .{ .arg = .{ .ty = Air.internedToRef(param_ty), - .name = if (inner_block.ownerModule().strip) + .name = if (inner_block.ownerModule().strip != .none) .none else try sema.appendAirString(sema.code.nullTerminatedString(param_name)), diff --git a/src/codegen/c.zig b/src/codegen/c.zig index b9731716f799..e8fda0a27620 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2661,7 +2661,7 @@ pub fn genTypeDecl( _ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{}); try writer.writeByte(';'); const file_scope = ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip); - if (!zcu.fileByIndex(file_scope).mod.strip) try writer.print(" /* {} */", .{ + if (zcu.fileByIndex(file_scope).mod.strip != .none) try writer.print(" /* {} */", .{ ty.containerTypeName(ip).fmt(ip), }); try writer.writeByte('\n'); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 97ed00c98d84..4af41c9372ff 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1477,7 +1477,7 @@ pub const Object = struct { var deinit_wip = true; var wip = try Builder.WipFunction.init(&o.builder, .{ .function = function_index, - .strip = owner_mod.strip, + .strip = owner_mod.strip != .none, }); defer if (deinit_wip) wip.deinit(); wip.cursor = .{ .block = try wip.block(0, "Entry") }; @@ -4802,7 +4802,7 @@ pub const NavGen = struct { const line_number = zcu.navSrcLine(nav_index) + 1; - if (!mod.strip) { + if (mod.strip == .none) { const debug_file = try o.getDebugFile(file_scope); const debug_global_var = try o.builder.debugGlobalVar( diff --git a/src/link/Elf.zig b/src/link/Elf.zig index edd45f65ee8b..52e11ff62963 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1102,8 +1102,10 @@ fn dumpArgvInit(self: *Elf, arena: Allocator) !void { try argv.append(gpa, "-pie"); } - if (comp.config.debug_format == .strip) { - try argv.append(gpa, "-s"); + switch (comp.config.root_strip) { + .none => {}, + .debug_info => try argv.append(gpa, "-S"), + .all => try argv.append(gpa, "-s"), } if (comp.config.link_libc) { @@ -1803,8 +1805,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s try argv.append("--export-dynamic"); } - if (comp.config.debug_format == .strip) { - try argv.append("-s"); + switch (comp.config.root_strip) { + .none => {}, + .debug_info => try argv.append("-S"), + .all => try argv.append("-s"), } if (self.z_nodelete) { diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 643c9ea95204..7101a4d3a5b5 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -4011,8 +4011,10 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: try argv.append("--no-gc-sections"); } - if (comp.config.debug_format == .strip) { - try argv.append("-s"); + switch (comp.config.root_strip) { + .none => {}, + .debug_info => try argv.append("-S"), + .all => try argv.append("-s"), } if (wasm.initial_memory) |initial_memory| { diff --git a/src/link/Wasm/Flush.zig b/src/link/Wasm/Flush.zig index f862bcf42725..b871fc167b2e 100644 --- a/src/link/Wasm/Flush.zig +++ b/src/link/Wasm/Flush.zig @@ -1011,7 +1011,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { try emitNameSection(wasm, f.data_segment_groups.items, binary_bytes); } - if (comp.config.debug_format != .strip) { + if (comp.config.root_strip != .all) { // The build id must be computed on the main sections only, // so we have to do it now, before the debug sections. switch (wasm.base.build_id) { diff --git a/src/main.zig b/src/main.zig index daf6010dcc51..ff77ee8cd810 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1548,9 +1548,20 @@ fn buildOutputType( show_builtin = true; emit_bin = .no; } else if (mem.eql(u8, arg, "-fstrip")) { - mod_opts.strip = true; + mod_opts.strip = .all; + } else if (mem.startsWith(u8, arg, "-fstrip=")) { + const fstrip_arg = arg["-fstrip=".len..]; + if (mem.eql(u8, fstrip_arg, "none")) { + mod_opts.strip = .none; + } else if (mem.eql(u8, fstrip_arg, "debug_info")) { + mod_opts.strip = .debug_info; + } else if (mem.eql(u8, fstrip_arg, "all")) { + mod_opts.strip = .all; + } else { + fatal("unknown value '{s}' passed to strip", .{arg[1..]}); + } } else if (mem.eql(u8, arg, "-fno-strip")) { - mod_opts.strip = false; + mod_opts.strip = .none; } else if (mem.eql(u8, arg, "-gdwarf32")) { create_module.opts.debug_format = .{ .dwarf = .@"32" }; } else if (mem.eql(u8, arg, "-gdwarf64")) { @@ -2177,24 +2188,24 @@ fn buildOutputType( } }, .debug => { - mod_opts.strip = false; + mod_opts.strip = .none; if (mem.eql(u8, it.only_arg, "g")) { - // We handled with strip = false above. + // We handled with strip = .none above. } else if (mem.eql(u8, it.only_arg, "g1") or mem.eql(u8, it.only_arg, "gline-tables-only")) { - // We handled with strip = false above. but we also want reduced debug info. + // We handled with strip = .none above. but we also want reduced debug info. try cc_argv.append(arena, "-gline-tables-only"); } else { try cc_argv.appendSlice(arena, it.other_args); } }, .gdwarf32 => { - mod_opts.strip = false; + mod_opts.strip = .none; create_module.opts.debug_format = .{ .dwarf = .@"32" }; }, .gdwarf64 => { - mod_opts.strip = false; + mod_opts.strip = .none; create_module.opts.debug_format = .{ .dwarf = .@"64" }; }, .sanitize => { @@ -2253,7 +2264,7 @@ fn buildOutputType( .framework_dir => try create_module.framework_dirs.append(arena, it.only_arg), .framework => try create_module.frameworks.put(arena, it.only_arg, .{}), .nostdlibinc => create_module.want_native_include_dirs = false, - .strip => mod_opts.strip = true, + .strip => mod_opts.strip = .all, .exec_model => { create_module.opts.wasi_exec_model = parseWasiExecModel(it.only_arg); }, @@ -2556,12 +2567,10 @@ fn buildOutputType( mem.eql(u8, arg, "--color-diagnostics=never")) { color = .off; - } else if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip-all") or - mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--strip-debug")) - { - // -s, --strip-all Strip all symbols - // -S, --strip-debug Strip debugging symbols - mod_opts.strip = true; + } else if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip-all")) { + mod_opts.strip = .all; + } else if (mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--strip-debug")) { + mod_opts.strip = .debug_info; } else if (mem.eql(u8, arg, "--start-group") or mem.eql(u8, arg, "--end-group")) { @@ -2871,7 +2880,7 @@ fn buildOutputType( .none => {}, .sync, .@"async" => create_module.opts.any_unwind_tables = true, }; - if (mod_opts.strip == false) + if (mod_opts.strip == .none or mod_opts.strip == .debug_info) create_module.opts.any_non_stripped = true; if (mod_opts.error_tracing == true) create_module.opts.any_error_tracing = true; @@ -5465,7 +5474,7 @@ fn jitCmd( .Debug else .ReleaseFast; - const strip = optimize_mode != .Debug; + const strip: std.builtin.Strip = if (optimize_mode != .Debug) .debug_info else .none; const override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); const override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); @@ -7574,7 +7583,7 @@ fn handleModArg( .none => {}, .sync, .@"async" => create_module.opts.any_unwind_tables = true, }; - if (mod_opts.strip == false) + if (mod_opts.strip == .none or mod_opts.strip == .debug_info) create_module.opts.any_non_stripped = true; if (mod_opts.error_tracing == true) create_module.opts.any_error_tracing = true; diff --git a/test/link/elf.zig b/test/link/elf.zig index a64da3ad2016..c4584a0cc304 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -1794,7 +1794,7 @@ fn testImportingDataDynamic(b: *Build, opts: Options) *Step { \\ printFoo(); \\} , - .strip = true, // TODO temp hack + .strip = .all, // TODO temp hack // temp hack for what? }); main.pie = true; main.linkLibrary(dso); @@ -1841,7 +1841,7 @@ fn testImportingDataStatic(b: *Build, opts: Options) *Step { \\ @import("std").debug.print("{d}\n", .{foo}); \\} , - .strip = true, // TODO temp hack + .strip = .all, // TODO temp hack // temp hack for what? }); main.linkLibrary(lib); main.linkLibC(); @@ -2244,7 +2244,7 @@ fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { }, .{ .name = "a", .c_source_bytes = "int foo;", - .strip = true, + .strip = .all, }); const exe = addExecutable(b, opts, .{ .name = "main" }); @@ -2989,7 +2989,7 @@ fn testStrip(b: *Build, opts: Options) *Step { { const exe = addExecutable(b, opts, .{ .name = "main1" }); exe.addObject(obj); - exe.root_module.strip = false; + exe.root_module.strip = .none; exe.linkLibC(); const check = exe.checkObject(); @@ -3002,7 +3002,7 @@ fn testStrip(b: *Build, opts: Options) *Step { { const exe = addExecutable(b, opts, .{ .name = "main2" }); exe.addObject(obj); - exe.root_module.strip = true; + exe.root_module.strip = .all; exe.linkLibC(); const check = exe.checkObject(); diff --git a/test/link/link.zig b/test/link/link.zig index 59198e6c8eb1..8b1a7bfa2358 100644 --- a/test/link/link.zig +++ b/test/link/link.zig @@ -9,7 +9,7 @@ pub const Options = struct { optimize: std.builtin.OptimizeMode = .Debug, use_llvm: bool = true, use_lld: bool = false, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, }; pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { @@ -18,7 +18,11 @@ pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; const use_lld = if (opts.use_lld) "lld" else "no-lld"; if (opts.strip) |strip| { - const s = if (strip) "strip" else "no-strip"; + const s = switch (strip) { + .all => "strip", + .debug_info => "strip-debug-info", + .none => "no-strip", + }; const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}-{s}-{s}", .{ prefix, target, optimize, use_llvm, use_lld, s, }) catch @panic("OOM"); @@ -43,7 +47,7 @@ const OverlayOptions = struct { objcpp_source_flags: []const []const u8 = &.{}, zig_source_bytes: ?[]const u8 = null, pic: ?bool = null, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, }; pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile { diff --git a/test/link/macho.zig b/test/link/macho.zig index 49925e1c1437..1f19e4229517 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -898,7 +898,7 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step { const obj = addObject(b, opts, .{ .name = "bobj", .zig_source_bytes = "export var bar: i32 = -42;", - .strip = true, // TODO for self-hosted, we don't really emit any valid DWARF yet since we only export a global + .strip = .all, // TODO for self-hosted, we don't really emit any valid DWARF yet since we only export a global }); const lib = addStaticLibrary(b, opts, .{ diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig index 4606f1d7cdb7..c37f3898aa42 100644 --- a/test/link/wasm/archive/build.zig +++ b/test/link/wasm/archive/build.zig @@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), - .strip = false, + .strip = .none, }), }); lib.entry = .disabled; diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig index 8989103fc3f8..e3dbb8765650 100644 --- a/test/link/wasm/producers/build.zig +++ b/test/link/wasm/producers/build.zig @@ -18,7 +18,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, - .strip = false, + .strip = .none, }), }); lib.entry = .disabled; diff --git a/test/link/wasm/shared-memory/build.zig b/test/link/wasm/shared-memory/build.zig index 02dc08a282c7..2077a7836363 100644 --- a/test/link/wasm/shared-memory/build.zig +++ b/test/link/wasm/shared-memory/build.zig @@ -20,7 +20,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt .os_tag = .freestanding, }), .optimize = optimize_mode, - .strip = false, + .strip = .none, .single_threaded = false, }), }); diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig index 793e3ae94f91..5aee8f330b10 100644 --- a/test/link/wasm/stack_pointer/build.zig +++ b/test/link/wasm/stack_pointer/build.zig @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, - .strip = false, + .strip = .none, }), }); lib.entry = .disabled; diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig index 063fd779b378..cd4dc39f1abd 100644 --- a/test/link/wasm/type/build.zig +++ b/test/link/wasm/type/build.zig @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, - .strip = false, + .strip = .none, }), }); exe.entry = .disabled; diff --git a/test/src/Debugger.zig b/test/src/Debugger.zig index f8948eb7b901..bbec914b518c 100644 --- a/test/src/Debugger.zig +++ b/test/src/Debugger.zig @@ -2457,7 +2457,7 @@ fn addTest( .link_libc = target.link_libc, .single_threaded = target.single_threaded, .pic = target.pic, - .strip = false, + .strip = .none, }); for (files[1..]) |file| { const path = files_wf.add(file.path, file.source); diff --git a/test/standalone/omit_cfi/build.zig b/test/standalone/omit_cfi/build.zig index 62f9fed471b2..5318ded71794 100644 --- a/test/standalone/omit_cfi/build.zig +++ b/test/standalone/omit_cfi/build.zig @@ -35,7 +35,7 @@ pub fn build(b: *std.Build) void { // We are mainly concerned with CFI directives in our non-libc startup code and syscall // code, so make it explicit that we don't want libc. .link_libc = false, - .strip = true, + .strip = .all, }), }); @@ -57,7 +57,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = .Debug, .link_libc = false, - .strip = true, + .strip = .all, .unwind_tables = .none, }), }); diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 4a1ef4b5b2e9..a1a3a47fd831 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -76,7 +76,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, .link_libc = true, - .strip = false, + .strip = .none, }), }); diff --git a/test/standalone/strip_empty_loop/build.zig b/test/standalone/strip_empty_loop/build.zig index 9f268d4cb864..96662d4fccdf 100644 --- a/test/standalone/strip_empty_loop/build.zig +++ b/test/standalone/strip_empty_loop/build.zig @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, - .strip = true, + .strip = .all, }), }); diff --git a/test/standalone/strip_struct_init/build.zig b/test/standalone/strip_struct_init/build.zig index 175724df6348..20e6e1844eb6 100644 --- a/test/standalone/strip_struct_init/build.zig +++ b/test/standalone/strip_struct_init/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("main.zig"), .target = b.graph.host, .optimize = optimize, - .strip = true, + .strip = .all, }), }); diff --git a/test/tests.zig b/test/tests.zig index 306b0d04f016..15bff86e62e6 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -27,7 +27,7 @@ const TestTarget = struct { use_llvm: ?bool = null, use_lld: ?bool = null, pic: ?bool = null, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, skip_modules: []const []const u8 = &.{}, // This is intended for targets that are known to be slow to compile. These are acceptable to @@ -121,7 +121,7 @@ const test_targets = blk: { }, .use_llvm = false, .use_lld = false, - .strip = true, + .strip = .all, }, // Doesn't support new liveness //.{ @@ -898,7 +898,7 @@ const CAbiTarget = struct { use_llvm: ?bool = null, use_lld: ?bool = null, pic: ?bool = null, - strip: ?bool = null, + strip: ?std.builtin.Strip = null, c_defines: []const []const u8 = &.{}, }; @@ -930,7 +930,7 @@ const c_abi_targets = [_]CAbiTarget{ }, .use_llvm = false, .use_lld = false, - .strip = true, + .strip = .all, .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, }, .{