diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index cbcb71304f919ad7929a7556734b8efbe3f10c99..25158933849ebdeceaab940bc32404b9415fc1e9 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -167,6 +167,9 @@ discard_local_symbols: bool = false, /// Position Independent Executable pie: ?bool = null, +/// Link Time Optimization mode +lto: ?std.zig.LtoMode = null, + dll_export_fns: ?bool = null, subsystem: ?std.Target.SubSystem = null, @@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void), /// Overrides the default stack size stack_size: ?u64 = null, +/// Deprecated; prefer using `lto`. want_lto: ?bool = null, + use_llvm: ?bool, use_lld: ?bool, @@ -1711,7 +1716,15 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { } try addFlag(&zig_args, "PIE", compile.pie); - try addFlag(&zig_args, "lto", compile.want_lto); + + if (compile.lto) |lto| { + try zig_args.append(switch (lto) { + .full => "-flto=full", + .thin => "-flto=thin", + .none => "-fno-lto", + }); + } else try addFlag(&zig_args, "lto", compile.want_lto); + try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); if (compile.subsystem) |subsystem| { diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 23001554744df403883aba81d69b04954b5c40ee..da329d488592083ef2dd51754788d33773710ce9 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -313,6 +313,8 @@ pub const BuildId = union(enum) { } }; +pub const LtoMode = enum { none, full, thin }; + /// Renders a `std.Target.Cpu` value into a textual representation that can be parsed /// via the `-mcpu` flag passed to the Zig compiler. /// Appends the result to `buffer`. diff --git a/src/Compilation.zig b/src/Compilation.zig index 9c1117966d863da97fecd772d83c30c7edd94948..b177a447c136ba40a790054e37fafccfb8fc8b0e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1074,7 +1074,6 @@ pub const CreateOptions = struct { /// executable this field is ignored. want_compiler_rt: ?bool = null, want_ubsan_rt: ?bool = null, - want_lto: ?bool = null, function_sections: bool = false, data_sections: bool = false, time_report: bool = false, diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index bc648ae4ad26f88b94a45f58c11ab5d25798aa9c..b71590f191f3d53f7f9046c85797c90b853bdc7c 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -48,7 +48,7 @@ use_lib_llvm: bool, /// and updates the final binary. use_lld: bool, c_frontend: CFrontend, -lto: LtoMode, +lto: std.zig.LtoMode, /// WASI-only. Type of WASI execution model ("command" or "reactor"). /// Always set to `command` for non-WASI targets. wasi_exec_model: std.builtin.WasiExecModel, @@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool, pub const CFrontend = enum { clang, aro }; -pub const LtoMode = enum { none, full, thin }; - pub const DebugFormat = union(enum) { strip, dwarf: std.dwarf.Format, @@ -105,7 +103,7 @@ pub const Options = struct { use_lib_llvm: ?bool = null, use_lld: ?bool = null, use_clang: ?bool = null, - lto: ?LtoMode = null, + lto: ?std.zig.LtoMode = null, /// WASI-only. Type of WASI execution model ("command" or "reactor"). wasi_exec_model: ?std.builtin.WasiExecModel = null, import_memory: ?bool = null, @@ -288,7 +286,7 @@ pub fn resolve(options: Options) ResolveError!Config { break :b .clang; }; - const lto: LtoMode = b: { + const lto: std.zig.LtoMode = b: { if (!use_lld) { // zig ld LTO support is tracked by // https://github.com/ziglang/zig/issues/8680 diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index c1ee88a6cbf0b46d59698706e969ba520be479c1..6ad4ccc242e5685706ffb183c9afda527f13414b 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -771,7 +771,7 @@ pub const Object = struct { time_report: bool, sanitize_thread: bool, fuzz: bool, - lto: Compilation.Config.LtoMode, + lto: std.zig.LtoMode, }; pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void { diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index af9d8b492a3b081e9444524b2ff44a40ab402ab1..4dd3eb7e845a8483ab56b048b2f26fe36f51aa12 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -43,12 +43,12 @@ fn add( switch (target.result.os.tag) { .windows => { // https://github.com/ziglang/zig/issues/8531 - exe_cpp.want_lto = false; + exe_cpp.lto = .none; }, .macos => { // https://github.com/ziglang/zig/issues/8680 - exe_cpp.want_lto = false; - exe_c.want_lto = false; + exe_cpp.lto = .none; + exe_c.lto = .none; }, else => {}, } diff --git a/test/tests.zig b/test/tests.zig index 43a631512d1025072a026e404e22feddb8649322..ef2cb6127f9ca3375eadb9422bd01596491fe7d5 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1681,7 +1681,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { // This test is intentionally trying to check if the external ABI is // done properly. LTO would be a hindrance to this. - test_step.want_lto = false; + test_step.lto = .none; const run = b.addRunArtifact(test_step); run.skip_foreign_checks = true;