diff options
| -rw-r--r-- | lib/std/Build/Step/Compile.zig | 15 | ||||
| -rw-r--r-- | lib/std/zig.zig | 2 | ||||
| -rw-r--r-- | src/Compilation.zig | 1 | ||||
| -rw-r--r-- | src/Compilation/Config.zig | 8 | ||||
| -rw-r--r-- | src/codegen/llvm.zig | 2 | ||||
| -rw-r--r-- | test/standalone/c_compiler/build.zig | 6 | ||||
| -rw-r--r-- | test/tests.zig | 2 |
7 files changed, 24 insertions, 12 deletions
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index cbcb71304f..2515893384 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 2300155474..da329d4885 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 9c1117966d..b177a447c1 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 bc648ae4ad..b71590f191 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 c1ee88a6cb..6ad4ccc242 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 af9d8b492a..4dd3eb7e84 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 43a631512d..ef2cb6127f 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; |
