authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2020-12-20 21:41:00+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-11 22:07:14-07:00
log8932c2d7456fc86b9e92c7976cedcce798caef1a
treef1a592127ee02e182eead556b6946b13a7d55edb
parent56c03881ebd8617e6506bfad01bf9cfdd4d3df7e

Added support for no red zone


13 files changed, 37 insertions(+), 1 deletions(-)

lib/std/build.zig+4
...@@ -1262,6 +1262,7 @@ pub const LibExeObjStep = struct {...@@ -1262,6 +1262,7 @@ pub const LibExeObjStep = struct {
1262 disable_stack_probing: bool,1262 disable_stack_probing: bool,
1263 disable_sanitize_c: bool,1263 disable_sanitize_c: bool,
1264 sanitize_thread: bool,1264 sanitize_thread: bool,
1265 no_red_zone: bool = false,
1265 rdynamic: bool,1266 rdynamic: bool,
1266 c_std: Builder.CStd,1267 c_std: Builder.CStd,
1267 override_lib_dir: ?[]const u8,1268 override_lib_dir: ?[]const u8,
...@@ -2260,6 +2261,9 @@ pub const LibExeObjStep = struct {...@@ -2260,6 +2261,9 @@ pub const LibExeObjStep = struct {
2260 if (self.disable_stack_probing) {2261 if (self.disable_stack_probing) {
2261 try zig_args.append("-fno-stack-check");2262 try zig_args.append("-fno-stack-check");
2262 }2263 }
2264 if (self.no_red_zone) {
2265 try zig_args.append("-fno-red-zone");
2266 }
2263 if (self.disable_sanitize_c) {2267 if (self.disable_sanitize_c) {
2264 try zig_args.append("-fno-sanitize-c");2268 try zig_args.append("-fno-sanitize-c");
2265 }2269 }
src/Compilation.zig+11-1
...@@ -392,6 +392,7 @@ pub const InitOptions = struct {...@@ -392,6 +392,7 @@ pub const InitOptions = struct {
392 want_pie: ?bool = null,392 want_pie: ?bool = null,
393 want_sanitize_c: ?bool = null,393 want_sanitize_c: ?bool = null,
394 want_stack_check: ?bool = null,394 want_stack_check: ?bool = null,
395 no_red_zone: bool = false,
395 want_valgrind: ?bool = null,396 want_valgrind: ?bool = null,
396 want_tsan: ?bool = null,397 want_tsan: ?bool = null,
397 want_compiler_rt: ?bool = null,398 want_compiler_rt: ?bool = null,
...@@ -773,6 +774,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -773,6 +774,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
773 cache.hash.add(pie);774 cache.hash.add(pie);
774 cache.hash.add(tsan);775 cache.hash.add(tsan);
775 cache.hash.add(stack_check);776 cache.hash.add(stack_check);
777 cache.hash.add(options.no_red_zone);
776 cache.hash.add(link_mode);778 cache.hash.add(link_mode);
777 cache.hash.add(options.function_sections);779 cache.hash.add(options.function_sections);
778 cache.hash.add(strip);780 cache.hash.add(strip);
...@@ -982,6 +984,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -982,6 +984,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
982 .valgrind = valgrind,984 .valgrind = valgrind,
983 .tsan = tsan,985 .tsan = tsan,
984 .stack_check = stack_check,986 .stack_check = stack_check,
987 .no_red_zone = options.no_red_zone,
985 .single_threaded = single_threaded,988 .single_threaded = single_threaded,
986 .verbose_link = options.verbose_link,989 .verbose_link = options.verbose_link,
987 .machine_code_model = options.machine_code_model,990 .machine_code_model = options.machine_code_model,
...@@ -2255,7 +2258,11 @@ pub fn addCCArgs(...@@ -2255,7 +2258,11 @@ pub fn addCCArgs(
2255 } else if (!comp.sanitize_c and comp.bin_file.options.tsan) {2258 } else if (!comp.sanitize_c and comp.bin_file.options.tsan) {
2256 try argv.append("-fsanitize=thread");2259 try argv.append("-fsanitize=thread");
2257 }2260 }
22582261
2262 if (comp.bin_file.options.no_red_zone) {
2263 try argv.append("-mno-red-zone");
2264 }
2265
2259 switch (comp.bin_file.options.optimize_mode) {2266 switch (comp.bin_file.options.optimize_mode) {
2260 .Debug => {2267 .Debug => {
2261 // windows c runtime requires -D_DEBUG if using debug libraries2268 // windows c runtime requires -D_DEBUG if using debug libraries
...@@ -2960,6 +2967,7 @@ fn buildOutputFromZig(...@@ -2960,6 +2967,7 @@ fn buildOutputFromZig(
2960 .function_sections = true,2967 .function_sections = true,
2961 .want_sanitize_c = false,2968 .want_sanitize_c = false,
2962 .want_stack_check = false,2969 .want_stack_check = false,
2970 .no_red_zone = comp.bin_file.options.no_red_zone,
2963 .want_valgrind = false,2971 .want_valgrind = false,
2964 .want_tsan = false,2972 .want_tsan = false,
2965 .want_pic = comp.bin_file.options.pic,2973 .want_pic = comp.bin_file.options.pic,
...@@ -3198,6 +3206,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3198,6 +3206,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3198 .tsan_enabled = comp.bin_file.options.tsan,3206 .tsan_enabled = comp.bin_file.options.tsan,
3199 .function_sections = comp.bin_file.options.function_sections,3207 .function_sections = comp.bin_file.options.function_sections,
3200 .enable_stack_probing = comp.bin_file.options.stack_check,3208 .enable_stack_probing = comp.bin_file.options.stack_check,
3209 .no_red_zone = comp.bin_file.options.no_red_zone,
3201 .enable_time_report = comp.time_report,3210 .enable_time_report = comp.time_report,
3202 .enable_stack_report = comp.stack_report,3211 .enable_stack_report = comp.stack_report,
3203 .test_is_evented = comp.test_evented_io,3212 .test_is_evented = comp.test_evented_io,
...@@ -3342,6 +3351,7 @@ pub fn build_crt_file(...@@ -3342,6 +3351,7 @@ pub fn build_crt_file(
3342 .optimize_mode = comp.compilerRtOptMode(),3351 .optimize_mode = comp.compilerRtOptMode(),
3343 .want_sanitize_c = false,3352 .want_sanitize_c = false,
3344 .want_stack_check = false,3353 .want_stack_check = false,
3354 .no_red_zone = comp.bin_file.options.no_red_zone,
3345 .want_valgrind = false,3355 .want_valgrind = false,
3346 .want_tsan = false,3356 .want_tsan = false,
3347 .want_pic = comp.bin_file.options.pic,3357 .want_pic = comp.bin_file.options.pic,
src/glibc.zig+1
...@@ -934,6 +934,7 @@ fn buildSharedLib(...@@ -934,6 +934,7 @@ fn buildSharedLib(
934 .optimize_mode = comp.compilerRtOptMode(),934 .optimize_mode = comp.compilerRtOptMode(),
935 .want_sanitize_c = false,935 .want_sanitize_c = false,
936 .want_stack_check = false,936 .want_stack_check = false,
937 .no_red_zone = comp.bin_file.options.no_red_zone,
937 .want_valgrind = false,938 .want_valgrind = false,
938 .want_tsan = false,939 .want_tsan = false,
939 .emit_h = null,940 .emit_h = null,
src/libcxx.zig+2
...@@ -167,6 +167,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -167,6 +167,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
167 .link_mode = link_mode,167 .link_mode = link_mode,
168 .want_sanitize_c = false,168 .want_sanitize_c = false,
169 .want_stack_check = false,169 .want_stack_check = false,
170 .no_red_zone = comp.bin_file.options.no_red_zone,
170 .want_valgrind = false,171 .want_valgrind = false,
171 .want_tsan = comp.bin_file.options.tsan,172 .want_tsan = comp.bin_file.options.tsan,
172 .want_pic = comp.bin_file.options.pic,173 .want_pic = comp.bin_file.options.pic,
...@@ -284,6 +285,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -284,6 +285,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
284 .link_mode = link_mode,285 .link_mode = link_mode,
285 .want_sanitize_c = false,286 .want_sanitize_c = false,
286 .want_stack_check = false,287 .want_stack_check = false,
288 .no_red_zone = comp.bin_file.options.no_red_zone,
287 .want_valgrind = false,289 .want_valgrind = false,
288 .want_tsan = comp.bin_file.options.tsan,290 .want_tsan = comp.bin_file.options.tsan,
289 .want_pic = comp.bin_file.options.pic,291 .want_pic = comp.bin_file.options.pic,
src/libunwind.zig+1
...@@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {...@@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
108 .link_mode = link_mode,108 .link_mode = link_mode,
109 .want_sanitize_c = false,109 .want_sanitize_c = false,
110 .want_stack_check = false,110 .want_stack_check = false,
111 .no_red_zone = comp.bin_file.options.no_red_zone,
111 .want_valgrind = false,112 .want_valgrind = false,
112 .want_tsan = false,113 .want_tsan = false,
113 .want_pic = comp.bin_file.options.pic,114 .want_pic = comp.bin_file.options.pic,
src/link.zig+1
...@@ -77,6 +77,7 @@ pub const Options = struct {...@@ -77,6 +77,7 @@ pub const Options = struct {
77 valgrind: bool,77 valgrind: bool,
78 tsan: bool,78 tsan: bool,
79 stack_check: bool,79 stack_check: bool,
80 no_red_zone: bool,
80 single_threaded: bool,81 single_threaded: bool,
81 verbose_link: bool,82 verbose_link: bool,
82 dll_export_fns: bool,83 dll_export_fns: bool,
src/main.zig+8
...@@ -282,6 +282,8 @@ const usage_build_generic =...@@ -282,6 +282,8 @@ const usage_build_generic =
282 \\ -fno-PIE Force-disable Position Independent Executable282 \\ -fno-PIE Force-disable Position Independent Executable
283 \\ -fstack-check Enable stack probing in unsafe builds283 \\ -fstack-check Enable stack probing in unsafe builds
284 \\ -fno-stack-check Disable stack probing in safe builds284 \\ -fno-stack-check Disable stack probing in safe builds
285 \\ -fred-zone Enable the "red-zone"
286 \\ -fno-red-zone Disable the "red-zone"
285 \\ -fsanitize-c Enable C undefined behavior detection in unsafe builds287 \\ -fsanitize-c Enable C undefined behavior detection in unsafe builds
286 \\ -fno-sanitize-c Disable C undefined behavior detection in safe builds288 \\ -fno-sanitize-c Disable C undefined behavior detection in safe builds
287 \\ -fvalgrind Include valgrind client requests in release builds289 \\ -fvalgrind Include valgrind client requests in release builds
...@@ -505,6 +507,7 @@ fn buildOutputType(...@@ -505,6 +507,7 @@ fn buildOutputType(
505 var want_pie: ?bool = null;507 var want_pie: ?bool = null;
506 var want_sanitize_c: ?bool = null;508 var want_sanitize_c: ?bool = null;
507 var want_stack_check: ?bool = null;509 var want_stack_check: ?bool = null;
510 var no_red_zone: bool = false;
508 var want_valgrind: ?bool = null;511 var want_valgrind: ?bool = null;
509 var want_tsan: ?bool = null;512 var want_tsan: ?bool = null;
510 var want_compiler_rt: ?bool = null;513 var want_compiler_rt: ?bool = null;
...@@ -843,6 +846,10 @@ fn buildOutputType(...@@ -843,6 +846,10 @@ fn buildOutputType(
843 want_stack_check = true;846 want_stack_check = true;
844 } else if (mem.eql(u8, arg, "-fno-stack-check")) {847 } else if (mem.eql(u8, arg, "-fno-stack-check")) {
845 want_stack_check = false;848 want_stack_check = false;
849 } else if (mem.eql(u8, arg, "-fred-zone")) {
850 no_red_zone = false;
851 } else if (mem.eql(u8, arg, "-fno-red-zone")) {
852 no_red_zone = true;
846 } else if (mem.eql(u8, arg, "-fsanitize-c")) {853 } else if (mem.eql(u8, arg, "-fsanitize-c")) {
847 want_sanitize_c = true;854 want_sanitize_c = true;
848 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {855 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {
...@@ -1760,6 +1767,7 @@ fn buildOutputType(...@@ -1760,6 +1767,7 @@ fn buildOutputType(
1760 .want_pie = want_pie,1767 .want_pie = want_pie,
1761 .want_sanitize_c = want_sanitize_c,1768 .want_sanitize_c = want_sanitize_c,
1762 .want_stack_check = want_stack_check,1769 .want_stack_check = want_stack_check,
1770 .no_red_zone = no_red_zone,
1763 .want_valgrind = want_valgrind,1771 .want_valgrind = want_valgrind,
1764 .want_tsan = want_tsan,1772 .want_tsan = want_tsan,
1765 .want_compiler_rt = want_compiler_rt,1773 .want_compiler_rt = want_compiler_rt,
src/musl.zig+1
...@@ -206,6 +206,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -206,6 +206,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
206 .optimize_mode = comp.compilerRtOptMode(),206 .optimize_mode = comp.compilerRtOptMode(),
207 .want_sanitize_c = false,207 .want_sanitize_c = false,
208 .want_stack_check = false,208 .want_stack_check = false,
209 .no_red_zone = comp.bin_file.options.no_red_zone,
209 .want_valgrind = false,210 .want_valgrind = false,
210 .want_tsan = false,211 .want_tsan = false,
211 .emit_h = null,212 .emit_h = null,
src/stage1.zig+1
...@@ -119,6 +119,7 @@ pub const Module = extern struct {...@@ -119,6 +119,7 @@ pub const Module = extern struct {
119 tsan_enabled: bool,119 tsan_enabled: bool,
120 function_sections: bool,120 function_sections: bool,
121 enable_stack_probing: bool,121 enable_stack_probing: bool,
122 no_red_zone: bool,
122 enable_time_report: bool,123 enable_time_report: bool,
123 enable_stack_report: bool,124 enable_stack_report: bool,
124 test_is_evented: bool,125 test_is_evented: bool,
src/stage1/all_types.hpp+1
...@@ -2195,6 +2195,7 @@ struct CodeGen {...@@ -2195,6 +2195,7 @@ struct CodeGen {
2195 bool link_mode_dynamic;2195 bool link_mode_dynamic;
2196 bool dll_export_fns;2196 bool dll_export_fns;
2197 bool have_stack_probing;2197 bool have_stack_probing;
2198 bool no_red_zone;
2198 bool function_sections;2199 bool function_sections;
2199 bool test_is_evented;2200 bool test_is_evented;
2200 bool valgrind_enabled;2201 bool valgrind_enabled;
src/stage1/codegen.cpp+4
...@@ -513,6 +513,10 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {...@@ -513,6 +513,10 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
513 } else {513 } else {
514 maybe_import_dll(g, llvm_fn, linkage);514 maybe_import_dll(g, llvm_fn, linkage);
515 }515 }
516
517 if (g->no_red_zone) {
518 addLLVMFnAttr(llvm_fn, "noredzone");
519 }
516520
517 if (fn->alignstack_value != 0) {521 if (fn->alignstack_value != 0) {
518 addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value);522 addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value);
src/stage1/stage1.cpp+1
...@@ -91,6 +91,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {...@@ -91,6 +91,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {
91 g->have_pic = stage1->pic;91 g->have_pic = stage1->pic;
92 g->have_pie = stage1->pie;92 g->have_pie = stage1->pie;
93 g->have_stack_probing = stage1->enable_stack_probing;93 g->have_stack_probing = stage1->enable_stack_probing;
94 g->no_red_zone = stage1->no_red_zone;
94 g->is_single_threaded = stage1->is_single_threaded;95 g->is_single_threaded = stage1->is_single_threaded;
95 g->valgrind_enabled = stage1->valgrind_enabled;96 g->valgrind_enabled = stage1->valgrind_enabled;
96 g->tsan_enabled = stage1->tsan_enabled;97 g->tsan_enabled = stage1->tsan_enabled;
src/stage1/stage1.h+1
...@@ -188,6 +188,7 @@ struct ZigStage1 {...@@ -188,6 +188,7 @@ struct ZigStage1 {
188 bool tsan_enabled;188 bool tsan_enabled;
189 bool function_sections;189 bool function_sections;
190 bool enable_stack_probing;190 bool enable_stack_probing;
191 bool no_red_zone;
191 bool enable_time_report;192 bool enable_time_report;
192 bool enable_stack_report;193 bool enable_stack_report;
193 bool test_is_evented;194 bool test_is_evented;