diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-01-11 22:07:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-01-11 22:07:47 -0700 |
| commit | 0edde40c25c033aec67f235365593ee26ff52740 (patch) | |
| tree | dfdd8caf259e2d03ba89d4c0211d9cafb45c6064 /src | |
| parent | 56c03881ebd8617e6506bfad01bf9cfdd4d3df7e (diff) | |
| parent | 5b2a79848ced20db80f3f4ce46b3ef7f4a051d53 (diff) | |
| download | zig-0edde40c25c033aec67f235365593ee26ff52740.tar.gz zig-0edde40c25c033aec67f235365593ee26ff52740.zip | |
Merge 'Add support for no red zone'
Merges #7511
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 13 | ||||
| -rw-r--r-- | src/clang_options_data.zig | 18 | ||||
| -rw-r--r-- | src/glibc.zig | 1 | ||||
| -rw-r--r-- | src/libcxx.zig | 2 | ||||
| -rw-r--r-- | src/libunwind.zig | 1 | ||||
| -rw-r--r-- | src/link.zig | 1 | ||||
| -rw-r--r-- | src/main.zig | 12 | ||||
| -rw-r--r-- | src/musl.zig | 1 | ||||
| -rw-r--r-- | src/stage1.zig | 1 | ||||
| -rw-r--r-- | src/stage1/all_types.hpp | 1 | ||||
| -rw-r--r-- | src/stage1/codegen.cpp | 4 | ||||
| -rw-r--r-- | src/stage1/stage1.cpp | 1 | ||||
| -rw-r--r-- | src/stage1/stage1.h | 1 | ||||
| -rw-r--r-- | src/target.zig | 18 |
14 files changed, 73 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index b017dde8c8..0efad3362d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -392,6 +392,7 @@ pub const InitOptions = struct { want_pie: ?bool = null, want_sanitize_c: ?bool = null, want_stack_check: ?bool = null, + want_red_zone: ?bool = null, want_valgrind: ?bool = null, want_tsan: ?bool = null, want_compiler_rt: ?bool = null, @@ -743,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, @@ -773,6 +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(red_zone); cache.hash.add(link_mode); cache.hash.add(options.function_sections); cache.hash.add(strip); @@ -982,6 +985,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .valgrind = valgrind, .tsan = tsan, .stack_check = stack_check, + .red_zone = red_zone, .single_threaded = single_threaded, .verbose_link = options.verbose_link, .machine_code_model = options.machine_code_model, @@ -2256,6 +2260,12 @@ pub fn addCCArgs( try argv.append("-fsanitize=thread"); } + 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 @@ -2960,6 +2970,7 @@ fn buildOutputFromZig( .function_sections = true, .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = false, .want_pic = comp.bin_file.options.pic, @@ -3198,6 +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, + .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, @@ -3342,6 +3354,7 @@ pub fn build_crt_file( .optimize_mode = comp.compilerRtOptMode(), .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = false, .want_pic = comp.bin_file.options.pic, diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig index 52dc8c0280..c901c6045f 100644 --- a/src/clang_options_data.zig +++ b/src/clang_options_data.zig @@ -3803,7 +3803,14 @@ flagpd1("mno-qpx"), flagpd1("mno-rdpid"), flagpd1("mno-rdrnd"), flagpd1("mno-rdseed"), -flagpd1("mno-red-zone"), +.{ + .name = "mno-red-zone", + .syntax = .flag, + .zig_equivalent = .no_red_zone, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("mno-reference-types"), flagpd1("mno-relax"), flagpd1("mno-relax-all"), @@ -3901,7 +3908,14 @@ flagpd1("mrdseed"), flagpd1("mreassociate"), flagpd1("mrecip"), flagpd1("mrecord-mcount"), -flagpd1("mred-zone"), +.{ + .name = "mred-zone", + .syntax = .flag, + .zig_equivalent = .red_zone, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("mreference-types"), sepd1("mregparm"), flagpd1("mrelax"), diff --git a/src/glibc.zig b/src/glibc.zig index e7b7b1b1cf..b154bd530d 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -934,6 +934,7 @@ fn buildSharedLib( .optimize_mode = comp.compilerRtOptMode(), .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = false, .emit_h = null, diff --git a/src/libcxx.zig b/src/libcxx.zig index e79a0106e9..11989998e9 100644 --- a/src/libcxx.zig +++ b/src/libcxx.zig @@ -167,6 +167,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { .link_mode = link_mode, .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = comp.bin_file.options.tsan, .want_pic = comp.bin_file.options.pic, @@ -284,6 +285,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { .link_mode = link_mode, .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = comp.bin_file.options.tsan, .want_pic = comp.bin_file.options.pic, diff --git a/src/libunwind.zig b/src/libunwind.zig index 7710b1aa77..c2d0475d6f 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { .link_mode = link_mode, .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = false, .want_pic = comp.bin_file.options.pic, diff --git a/src/link.zig b/src/link.zig index ffb69adee9..6914131bea 100644 --- a/src/link.zig +++ b/src/link.zig @@ -77,6 +77,7 @@ pub const Options = struct { valgrind: bool, tsan: bool, stack_check: bool, + red_zone: bool, single_threaded: bool, verbose_link: bool, dll_export_fns: bool, diff --git a/src/main.zig b/src/main.zig index b50f89e5c2..867aa348b1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -267,6 +267,8 @@ const usage_build_generic = \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses \\ small|kernel| \\ medium|large] + \\ -mred-zone Force-enable the "red-zone" + \\ -mno-red-zone Force-disable the "red-zone" \\ --name [name] Override root name (not a file path) \\ -O [mode] Choose what to optimize for \\ Debug (default) Optimizations off, safety on @@ -505,6 +507,7 @@ fn buildOutputType( var want_pie: ?bool = null; var want_sanitize_c: ?bool = null; var want_stack_check: ?bool = null; + var want_red_zone: ?bool = null; var want_valgrind: ?bool = null; var want_tsan: ?bool = null; var want_compiler_rt: ?bool = null; @@ -843,6 +846,10 @@ fn buildOutputType( want_stack_check = true; } else if (mem.eql(u8, arg, "-fno-stack-check")) { want_stack_check = false; + } else if (mem.eql(u8, arg, "-mred-zone")) { + want_red_zone = true; + } else if (mem.eql(u8, arg, "-mno-red-zone")) { + want_red_zone = false; } else if (mem.eql(u8, arg, "-fsanitize-c")) { want_sanitize_c = true; } else if (mem.eql(u8, arg, "-fno-sanitize-c")) { @@ -1068,6 +1075,8 @@ fn buildOutputType( .no_pic => want_pic = false, .pie => want_pie = true, .no_pie => want_pie = false, + .red_zone => want_red_zone = true, + .no_red_zone => want_red_zone = false, .nostdlib => ensure_libc_on_non_freestanding = false, .nostdlib_cpp => ensure_libcpp_on_non_freestanding = false, .shared => { @@ -1760,6 +1769,7 @@ fn buildOutputType( .want_pie = want_pie, .want_sanitize_c = want_sanitize_c, .want_stack_check = want_stack_check, + .want_red_zone = want_red_zone, .want_valgrind = want_valgrind, .want_tsan = want_tsan, .want_compiler_rt = want_compiler_rt, @@ -2969,6 +2979,8 @@ pub const ClangArgIterator = struct { framework_dir, framework, nostdlibinc, + red_zone, + no_red_zone, }; const Args = struct { diff --git a/src/musl.zig b/src/musl.zig index a865e78623..0cb6983e28 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -206,6 +206,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { .optimize_mode = comp.compilerRtOptMode(), .want_sanitize_c = false, .want_stack_check = false, + .want_red_zone = comp.bin_file.options.red_zone, .want_valgrind = false, .want_tsan = false, .emit_h = null, diff --git a/src/stage1.zig b/src/stage1.zig index cf3a252ce8..44fd8e109e 100644 --- a/src/stage1.zig +++ b/src/stage1.zig @@ -119,6 +119,7 @@ pub const Module = extern struct { tsan_enabled: bool, function_sections: bool, enable_stack_probing: bool, + red_zone: bool, enable_time_report: bool, enable_stack_report: bool, test_is_evented: bool, diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 24b54ad794..c235bb362d 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -2195,6 +2195,7 @@ struct CodeGen { bool link_mode_dynamic; bool dll_export_fns; bool have_stack_probing; + bool red_zone; bool function_sections; bool test_is_evented; bool valgrind_enabled; diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 386bc43086..10943483f4 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -514,6 +514,10 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { maybe_import_dll(g, llvm_fn, linkage); } + if (!g->red_zone) { + addLLVMFnAttr(llvm_fn, "noredzone"); + } + if (fn->alignstack_value != 0) { addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value); } diff --git a/src/stage1/stage1.cpp b/src/stage1/stage1.cpp index 1195a83931..d680121577 100644 --- a/src/stage1/stage1.cpp +++ b/src/stage1/stage1.cpp @@ -91,6 +91,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) { g->have_pic = stage1->pic; g->have_pie = stage1->pie; g->have_stack_probing = stage1->enable_stack_probing; + g->red_zone = stage1->red_zone; g->is_single_threaded = stage1->is_single_threaded; g->valgrind_enabled = stage1->valgrind_enabled; g->tsan_enabled = stage1->tsan_enabled; diff --git a/src/stage1/stage1.h b/src/stage1/stage1.h index dbf6491699..6db3621cf5 100644 --- a/src/stage1/stage1.h +++ b/src/stage1/stage1.h @@ -188,6 +188,7 @@ struct ZigStage1 { bool tsan_enabled; bool function_sections; bool enable_stack_probing; + bool red_zone; bool enable_time_report; bool enable_stack_report; bool test_is_evented; diff --git a/src/target.zig b/src/target.zig index daac577c7b..c3df682ce0 100644 --- a/src/target.zig +++ b/src/target.zig @@ -349,3 +349,21 @@ pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode { return .ReleaseFast; } } + +pub fn hasRedZone(target: std.Target) bool { + return switch (target.cpu.arch) { + .x86_64, + .i386, + .wasm32, + .wasm64, + .powerpc, + .powerpc64, + .powerpc64le, + .aarch64, + .aarch64_be, + .aarch64_32, + => true, + + else => false, + }; +} |
