aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-11 22:01:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-11 22:07:21 -0700
commit5b2a79848ced20db80f3f4ce46b3ef7f4a051d53 (patch)
treedfdd8caf259e2d03ba89d4c0211d9cafb45c6064 /src/Compilation.zig
parent8932c2d7456fc86b9e92c7976cedcce798caef1a (diff)
downloadzig-5b2a79848ced20db80f3f4ce46b3ef7f4a051d53.tar.gz
zig-5b2a79848ced20db80f3f4ce46b3ef7f4a051d53.zip
stage2: cleanups regarding red zone CLI flags
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang. * build.zig: remove the double negative and make it an optional bool. This follows precedent from other flags, allowing the compiler CLI to be the decider of what is default instead of duplicating the default value into the build system code. * Compilation: make it an optional `want_red_zone` instead of a `no_red_zone` bool. The default is decided by a call to `target_util.hasRedZone`. * When creating a Clang command line, put -mred-zone on the command line if we are forcing it to be enabled. * Update update_clang_options.zig with respect to the recent {s}/{} format changes. * `zig cc` integration with red zone preference.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 1588544010..0efad3362d 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -392,7 +392,7 @@ pub const InitOptions = struct {
want_pie: ?bool = null,
want_sanitize_c: ?bool = null,
want_stack_check: ?bool = null,
- no_red_zone: bool = false,
+ want_red_zone: ?bool = null,
want_valgrind: ?bool = null,
want_tsan: ?bool = null,
want_compiler_rt: ?bool = null,
@@ -744,6 +744,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
} else null;
const strip = options.strip or !target_util.hasDebugInfo(options.target);
+ const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
// 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,
@@ -774,7 +775,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
cache.hash.add(pie);
cache.hash.add(tsan);
cache.hash.add(stack_check);
- cache.hash.add(options.no_red_zone);
+ cache.hash.add(red_zone);
cache.hash.add(link_mode);
cache.hash.add(options.function_sections);
cache.hash.add(strip);
@@ -984,7 +985,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.valgrind = valgrind,
.tsan = tsan,
.stack_check = stack_check,
- .no_red_zone = options.no_red_zone,
+ .red_zone = red_zone,
.single_threaded = single_threaded,
.verbose_link = options.verbose_link,
.machine_code_model = options.machine_code_model,
@@ -2258,11 +2259,13 @@ pub fn addCCArgs(
} else if (!comp.sanitize_c and comp.bin_file.options.tsan) {
try argv.append("-fsanitize=thread");
}
-
- if (comp.bin_file.options.no_red_zone) {
+
+ if (comp.bin_file.options.red_zone) {
+ try argv.append("-mred-zone");
+ } else if (target_util.hasRedZone(target)) {
try argv.append("-mno-red-zone");
}
-
+
switch (comp.bin_file.options.optimize_mode) {
.Debug => {
// windows c runtime requires -D_DEBUG if using debug libraries
@@ -2967,7 +2970,7 @@ fn buildOutputFromZig(
.function_sections = true,
.want_sanitize_c = false,
.want_stack_check = false,
- .no_red_zone = comp.bin_file.options.no_red_zone,
+ .want_red_zone = comp.bin_file.options.red_zone,
.want_valgrind = false,
.want_tsan = false,
.want_pic = comp.bin_file.options.pic,
@@ -3206,7 +3209,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
.tsan_enabled = comp.bin_file.options.tsan,
.function_sections = comp.bin_file.options.function_sections,
.enable_stack_probing = comp.bin_file.options.stack_check,
- .no_red_zone = comp.bin_file.options.no_red_zone,
+ .red_zone = comp.bin_file.options.red_zone,
.enable_time_report = comp.time_report,
.enable_stack_report = comp.stack_report,
.test_is_evented = comp.test_evented_io,
@@ -3351,7 +3354,7 @@ pub fn build_crt_file(
.optimize_mode = comp.compilerRtOptMode(),
.want_sanitize_c = false,
.want_stack_check = false,
- .no_red_zone = comp.bin_file.options.no_red_zone,
+ .want_red_zone = comp.bin_file.options.red_zone,
.want_valgrind = false,
.want_tsan = false,
.want_pic = comp.bin_file.options.pic,