From 5b2a79848ced20db80f3f4ce46b3ef7f4a051d53 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 11 Jan 2021 22:01:16 -0700 Subject: 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. --- src/Compilation.zig | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/Compilation.zig') 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, -- cgit v1.2.3