diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-11-24 18:35:37 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-11-24 18:46:32 -0700 |
| commit | 20cc7af8e6e47ba209ab0d462826f40516c86b9d (patch) | |
| tree | 865fcfffdc31cf0b7220d41198266f0627b2d118 /src/Compilation.zig | |
| parent | 27c5c7fb23fceb0a333444408a1dea4188a14c32 (diff) | |
| download | zig-20cc7af8e6e47ba209ab0d462826f40516c86b9d.tar.gz zig-20cc7af8e6e47ba209ab0d462826f40516c86b9d.zip | |
stage2: support LLD -O flags on ELF
In 7e23b3245a9bf6e002009e6c18c10a9995671afa I made -O flags to the
linker emit a warning that the argument does nothing. That was not
correct however; LLD does have some logic that does different things
depending on -O0, -O1, and -O2. It defaults to -O1, and it does less
optimizations with -O0 and more with -O2.
With this commit, e.g. `-Wl,-O1` is supported by the `zig cc` frontend,
and by default we pass `-O0` to LLD in debug mode, and `-O3` in release
modes.
I also fixed a bug in the LLD ELF linker line which was incorrectly
passing `-O` flags instead of `--lto-O` flags for LTO.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 2ff390f196..4196eb634d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -736,6 +736,7 @@ pub const InitOptions = struct { linker_tsaware: bool = false, linker_nxcompat: bool = false, linker_dynamicbase: bool = false, + linker_optimization: ?u8 = null, major_subsystem_version: ?u32 = null, minor_subsystem_version: ?u32 = null, clang_passthrough_mode: bool = false, @@ -1140,6 +1141,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { const strip = options.strip or !target_util.hasDebugInfo(options.target); const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target); const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug); + const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) { + .Debug => @as(u8, 0), + else => @as(u8, 3), + }; // We put everything into the cache hash that *cannot be modified during an incremental update*. // For example, one cannot change the target between updates, but one can change source files, @@ -1450,6 +1455,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .tsaware = options.linker_tsaware, .nxcompat = options.linker_nxcompat, .dynamicbase = options.linker_dynamicbase, + .linker_optimization = linker_optimization, .major_subsystem_version = options.major_subsystem_version, .minor_subsystem_version = options.minor_subsystem_version, .stack_size_override = options.stack_size_override, |
