Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ci/aarch64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ci/aarch64-macos-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ci/aarch64-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-macos-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-windows-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
25 changes: 20 additions & 5 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions lib/std/Build/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/Builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};
\\
Expand All @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 8 additions & 8 deletions src/Compilation/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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" },
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Package/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};

Expand Down
Loading
Loading