authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-25 19:15:17-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-10-25 19:15:17-04:00
log30d01c8fea68baab396081da040f49defa494088
tree410ad5e004d75dfb7cf29c077ab163e8853f8748
parent97dc5f6eb531c91e8bd23a5589cae64e0a4561e8
parentb5be01a5972d2288658eecbf6a52c3ea8331c151
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9874 from leecannon/frame_pointer

Make omiting frame pointer independent of build mode

17 files changed, 102 insertions(+), 12 deletions(-)

lib/std/build.zig+9
...@@ -1515,6 +1515,8 @@ pub const LibExeObjStep = struct {...@@ -1515,6 +1515,8 @@ pub const LibExeObjStep = struct {
15151515
1516 red_zone: ?bool = null,1516 red_zone: ?bool = null,
15171517
1518 omit_frame_pointer: ?bool = null,
1519
1518 subsystem: ?std.Target.SubSystem = null,1520 subsystem: ?std.Target.SubSystem = null,
15191521
1520 /// Overrides the default stack size1522 /// Overrides the default stack size
...@@ -2406,6 +2408,13 @@ pub const LibExeObjStep = struct {...@@ -2406,6 +2408,13 @@ pub const LibExeObjStep = struct {
2406 try zig_args.append("-mno-red-zone");2408 try zig_args.append("-mno-red-zone");
2407 }2409 }
2408 }2410 }
2411 if (self.omit_frame_pointer) |omit_frame_pointer| {
2412 if (omit_frame_pointer) {
2413 try zig_args.append("-fomit-frame-pointer");
2414 } else {
2415 try zig_args.append("-fno-omit-frame-pointer");
2416 }
2417 }
2409 if (self.disable_sanitize_c) {2418 if (self.disable_sanitize_c) {
2410 try zig_args.append("-fno-sanitize-c");2419 try zig_args.append("-fno-sanitize-c");
2411 }2420 }
src/Compilation.zig+13
...@@ -688,6 +688,7 @@ pub const InitOptions = struct {...@@ -688,6 +688,7 @@ pub const InitOptions = struct {
688 want_sanitize_c: ?bool = null,688 want_sanitize_c: ?bool = null,
689 want_stack_check: ?bool = null,689 want_stack_check: ?bool = null,
690 want_red_zone: ?bool = null,690 want_red_zone: ?bool = null,
691 omit_frame_pointer: ?bool = null,
691 want_valgrind: ?bool = null,692 want_valgrind: ?bool = null,
692 want_tsan: ?bool = null,693 want_tsan: ?bool = null,
693 want_compiler_rt: ?bool = null,694 want_compiler_rt: ?bool = null,
...@@ -1123,6 +1124,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1123,6 +1124,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
11231124
1124 const strip = options.strip or !target_util.hasDebugInfo(options.target);1125 const strip = options.strip or !target_util.hasDebugInfo(options.target);
1125 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);1126 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
1127 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
11261128
1127 // We put everything into the cache hash that *cannot be modified during an incremental update*.1129 // We put everything into the cache hash that *cannot be modified during an incremental update*.
1128 // For example, one cannot change the target between updates, but one can change source files,1130 // For example, one cannot change the target between updates, but one can change source files,
...@@ -1156,6 +1158,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1156,6 +1158,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1156 cache.hash.add(tsan);1158 cache.hash.add(tsan);
1157 cache.hash.add(stack_check);1159 cache.hash.add(stack_check);
1158 cache.hash.add(red_zone);1160 cache.hash.add(red_zone);
1161 cache.hash.add(omit_frame_pointer);
1159 cache.hash.add(link_mode);1162 cache.hash.add(link_mode);
1160 cache.hash.add(options.function_sections);1163 cache.hash.add(options.function_sections);
1161 cache.hash.add(strip);1164 cache.hash.add(strip);
...@@ -1426,6 +1429,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1426,6 +1429,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1426 .tsan = tsan,1429 .tsan = tsan,
1427 .stack_check = stack_check,1430 .stack_check = stack_check,
1428 .red_zone = red_zone,1431 .red_zone = red_zone,
1432 .omit_frame_pointer = omit_frame_pointer,
1429 .single_threaded = single_threaded,1433 .single_threaded = single_threaded,
1430 .verbose_link = options.verbose_link,1434 .verbose_link = options.verbose_link,
1431 .machine_code_model = options.machine_code_model,1435 .machine_code_model = options.machine_code_model,
...@@ -3292,6 +3296,12 @@ pub fn addCCArgs(...@@ -3292,6 +3296,12 @@ pub fn addCCArgs(
3292 try argv.append("-mno-red-zone");3296 try argv.append("-mno-red-zone");
3293 }3297 }
32943298
3299 if (comp.bin_file.options.omit_frame_pointer) {
3300 try argv.append("-fomit-frame-pointer");
3301 } else {
3302 try argv.append("-fno-omit-frame-pointer");
3303 }
3304
3295 switch (comp.bin_file.options.optimize_mode) {3305 switch (comp.bin_file.options.optimize_mode) {
3296 .Debug => {3306 .Debug => {
3297 // windows c runtime requires -D_DEBUG if using debug libraries3307 // windows c runtime requires -D_DEBUG if using debug libraries
...@@ -4122,6 +4132,7 @@ fn buildOutputFromZig(...@@ -4122,6 +4132,7 @@ fn buildOutputFromZig(
4122 .want_sanitize_c = false,4132 .want_sanitize_c = false,
4123 .want_stack_check = false,4133 .want_stack_check = false,
4124 .want_red_zone = comp.bin_file.options.red_zone,4134 .want_red_zone = comp.bin_file.options.red_zone,
4135 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4125 .want_valgrind = false,4136 .want_valgrind = false,
4126 .want_tsan = false,4137 .want_tsan = false,
4127 .want_pic = comp.bin_file.options.pic,4138 .want_pic = comp.bin_file.options.pic,
...@@ -4405,6 +4416,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -4405,6 +4416,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
4405 .include_compiler_rt = include_compiler_rt,4416 .include_compiler_rt = include_compiler_rt,
4406 .enable_stack_probing = comp.bin_file.options.stack_check,4417 .enable_stack_probing = comp.bin_file.options.stack_check,
4407 .red_zone = comp.bin_file.options.red_zone,4418 .red_zone = comp.bin_file.options.red_zone,
4419 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4408 .enable_time_report = comp.time_report,4420 .enable_time_report = comp.time_report,
4409 .enable_stack_report = comp.stack_report,4421 .enable_stack_report = comp.stack_report,
4410 .test_is_evented = comp.test_evented_io,4422 .test_is_evented = comp.test_evented_io,
...@@ -4554,6 +4566,7 @@ pub fn build_crt_file(...@@ -4554,6 +4566,7 @@ pub fn build_crt_file(
4554 .want_sanitize_c = false,4566 .want_sanitize_c = false,
4555 .want_stack_check = false,4567 .want_stack_check = false,
4556 .want_red_zone = comp.bin_file.options.red_zone,4568 .want_red_zone = comp.bin_file.options.red_zone,
4569 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4557 .want_valgrind = false,4570 .want_valgrind = false,
4558 .want_tsan = false,4571 .want_tsan = false,
4559 .want_pic = comp.bin_file.options.pic,4572 .want_pic = comp.bin_file.options.pic,
src/clang_options_data.zig+16-2
...@@ -3014,7 +3014,14 @@ flagpd1("fno-objc-infer-related-result-type"),...@@ -3014,7 +3014,14 @@ flagpd1("fno-objc-infer-related-result-type"),
3014flagpd1("fno-objc-legacy-dispatch"),3014flagpd1("fno-objc-legacy-dispatch"),
3015flagpd1("fno-objc-nonfragile-abi"),3015flagpd1("fno-objc-nonfragile-abi"),
3016flagpd1("fno-objc-weak"),3016flagpd1("fno-objc-weak"),
3017flagpd1("fno-omit-frame-pointer"),3017.{
3018 .name = "fno-omit-frame-pointer",
3019 .syntax = .flag,
3020 .zig_equivalent = .no_omit_frame_pointer,
3021 .pd1 = true,
3022 .pd2 = false,
3023 .psl = false,
3024},
3018flagpd1("fno-openmp"),3025flagpd1("fno-openmp"),
3019flagpd1("fno-openmp-cuda-force-full-runtime"),3026flagpd1("fno-openmp-cuda-force-full-runtime"),
3020flagpd1("fno-openmp-cuda-mode"),3027flagpd1("fno-openmp-cuda-mode"),
...@@ -3235,7 +3242,14 @@ flagpd1("fobjc-runtime-has-weak"),...@@ -3235,7 +3242,14 @@ flagpd1("fobjc-runtime-has-weak"),
3235flagpd1("fobjc-sender-dependent-dispatch"),3242flagpd1("fobjc-sender-dependent-dispatch"),
3236flagpd1("fobjc-subscripting-legacy-runtime"),3243flagpd1("fobjc-subscripting-legacy-runtime"),
3237flagpd1("fobjc-weak"),3244flagpd1("fobjc-weak"),
3238flagpd1("fomit-frame-pointer"),3245.{
3246 .name = "fomit-frame-pointer",
3247 .syntax = .flag,
3248 .zig_equivalent = .omit_frame_pointer,
3249 .pd1 = true,
3250 .pd2 = false,
3251 .psl = false,
3252},
3239flagpd1("fopenmp"),3253flagpd1("fopenmp"),
3240flagpd1("fopenmp-cuda-force-full-runtime"),3254flagpd1("fopenmp-cuda-force-full-runtime"),
3241flagpd1("fopenmp-cuda-mode"),3255flagpd1("fopenmp-cuda-mode"),
src/codegen/llvm.zig+25
...@@ -668,6 +668,11 @@ pub const DeclGen = struct {...@@ -668,6 +668,11 @@ pub const DeclGen = struct {
668 if (!dg.module.comp.bin_file.options.red_zone) {668 if (!dg.module.comp.bin_file.options.red_zone) {
669 dg.addFnAttr(llvm_fn, "noredzone");669 dg.addFnAttr(llvm_fn, "noredzone");
670 }670 }
671 if (dg.module.comp.bin_file.options.omit_frame_pointer) {
672 dg.addFnAttrString(llvm_fn, "frame-pointer", "none");
673 } else {
674 dg.addFnAttrString(llvm_fn, "frame-pointer", "all");
675 }
671 dg.addFnAttr(llvm_fn, "nounwind");676 dg.addFnAttr(llvm_fn, "nounwind");
672 if (dg.module.comp.unwind_tables) {677 if (dg.module.comp.unwind_tables) {
673 dg.addFnAttr(llvm_fn, "uwtable");678 dg.addFnAttr(llvm_fn, "uwtable");
...@@ -1541,10 +1546,30 @@ pub const DeclGen = struct {...@@ -1541,10 +1546,30 @@ pub const DeclGen = struct {
1541 val.addAttributeAtIndex(index, llvm_attr);1546 val.addAttributeAtIndex(index, llvm_attr);
1542 }1547 }
15431548
1549 fn addAttrString(
1550 dg: *DeclGen,
1551 val: *const llvm.Value,
1552 index: llvm.AttributeIndex,
1553 name: []const u8,
1554 value: []const u8,
1555 ) void {
1556 const llvm_attr = dg.context.createStringAttribute(
1557 name.ptr,
1558 @intCast(c_uint, name.len),
1559 value.ptr,
1560 @intCast(c_uint, value.len),
1561 );
1562 val.addAttributeAtIndex(index, llvm_attr);
1563 }
1564
1544 fn addFnAttr(dg: DeclGen, val: *const llvm.Value, name: []const u8) void {1565 fn addFnAttr(dg: DeclGen, val: *const llvm.Value, name: []const u8) void {
1545 dg.addAttr(val, std.math.maxInt(llvm.AttributeIndex), name);1566 dg.addAttr(val, std.math.maxInt(llvm.AttributeIndex), name);
1546 }1567 }
15471568
1569 fn addFnAttrString(dg: *DeclGen, val: *const llvm.Value, name: []const u8, value: []const u8) void {
1570 dg.addAttrString(val, std.math.maxInt(llvm.AttributeIndex), name, value);
1571 }
1572
1548 fn removeFnAttr(fn_val: *const llvm.Value, name: []const u8) void {1573 fn removeFnAttr(fn_val: *const llvm.Value, name: []const u8) void {
1549 removeAttr(fn_val, std.math.maxInt(llvm.AttributeIndex), name);1574 removeAttr(fn_val, std.math.maxInt(llvm.AttributeIndex), name);
1550 }1575 }
src/codegen/llvm/bindings.zig+3
...@@ -28,6 +28,9 @@ pub const Context = opaque {...@@ -28,6 +28,9 @@ pub const Context = opaque {
28 pub const createEnumAttribute = LLVMCreateEnumAttribute;28 pub const createEnumAttribute = LLVMCreateEnumAttribute;
29 extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute;29 extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute;
3030
31 pub const createStringAttribute = LLVMCreateStringAttribute;
32 extern fn LLVMCreateStringAttribute(*const Context, Key: [*]const u8, Key_Len: c_uint, Value: [*]const u8, Value_Len: c_uint) *const Attribute;
33
31 pub const intType = LLVMIntTypeInContext;34 pub const intType = LLVMIntTypeInContext;
32 extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;35 extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;
3336
src/glibc.zig+1
...@@ -953,6 +953,7 @@ fn buildSharedLib(...@@ -953,6 +953,7 @@ fn buildSharedLib(
953 .want_sanitize_c = false,953 .want_sanitize_c = false,
954 .want_stack_check = false,954 .want_stack_check = false,
955 .want_red_zone = comp.bin_file.options.red_zone,955 .want_red_zone = comp.bin_file.options.red_zone,
956 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
956 .want_valgrind = false,957 .want_valgrind = false,
957 .want_tsan = false,958 .want_tsan = false,
958 .emit_h = null,959 .emit_h = null,
src/libcxx.zig+2
...@@ -189,6 +189,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -189,6 +189,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
189 .want_sanitize_c = false,189 .want_sanitize_c = false,
190 .want_stack_check = false,190 .want_stack_check = false,
191 .want_red_zone = comp.bin_file.options.red_zone,191 .want_red_zone = comp.bin_file.options.red_zone,
192 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
192 .want_valgrind = false,193 .want_valgrind = false,
193 .want_tsan = comp.bin_file.options.tsan,194 .want_tsan = comp.bin_file.options.tsan,
194 .want_pic = comp.bin_file.options.pic,195 .want_pic = comp.bin_file.options.pic,
...@@ -321,6 +322,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -321,6 +322,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
321 .want_sanitize_c = false,322 .want_sanitize_c = false,
322 .want_stack_check = false,323 .want_stack_check = false,
323 .want_red_zone = comp.bin_file.options.red_zone,324 .want_red_zone = comp.bin_file.options.red_zone,
325 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
324 .want_valgrind = false,326 .want_valgrind = false,
325 .want_tsan = comp.bin_file.options.tsan,327 .want_tsan = comp.bin_file.options.tsan,
326 .want_pic = comp.bin_file.options.pic,328 .want_pic = comp.bin_file.options.pic,
src/libunwind.zig+1
...@@ -113,6 +113,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {...@@ -113,6 +113,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
113 .want_sanitize_c = false,113 .want_sanitize_c = false,
114 .want_stack_check = false,114 .want_stack_check = false,
115 .want_red_zone = comp.bin_file.options.red_zone,115 .want_red_zone = comp.bin_file.options.red_zone,
116 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
116 .want_valgrind = false,117 .want_valgrind = false,
117 .want_tsan = false,118 .want_tsan = false,
118 .want_pic = comp.bin_file.options.pic,119 .want_pic = comp.bin_file.options.pic,
src/link.zig+1
...@@ -90,6 +90,7 @@ pub const Options = struct {...@@ -90,6 +90,7 @@ pub const Options = struct {
90 tsan: bool,90 tsan: bool,
91 stack_check: bool,91 stack_check: bool,
92 red_zone: bool,92 red_zone: bool,
93 omit_frame_pointer: bool,
93 single_threaded: bool,94 single_threaded: bool,
94 verbose_link: bool,95 verbose_link: bool,
95 dll_export_fns: bool,96 dll_export_fns: bool,
src/main.zig+12
...@@ -323,6 +323,8 @@ const usage_build_generic =...@@ -323,6 +323,8 @@ const usage_build_generic =
323 \\ medium|large]323 \\ medium|large]
324 \\ -mred-zone Force-enable the "red-zone"324 \\ -mred-zone Force-enable the "red-zone"
325 \\ -mno-red-zone Force-disable the "red-zone"325 \\ -mno-red-zone Force-disable the "red-zone"
326 \\ -fomit-frame-pointer Omit the stack frame pointer
327 \\ -fno-omit-frame-pointer Store the stack frame pointer
326 \\ -mexec-model=[value] Execution model (WASI only)328 \\ -mexec-model=[value] Execution model (WASI only)
327 \\ --name [name] Override root name (not a file path)329 \\ --name [name] Override root name (not a file path)
328 \\ -O [mode] Choose what to optimize for330 \\ -O [mode] Choose what to optimize for
...@@ -581,6 +583,7 @@ fn buildOutputType(...@@ -581,6 +583,7 @@ fn buildOutputType(
581 var want_sanitize_c: ?bool = null;583 var want_sanitize_c: ?bool = null;
582 var want_stack_check: ?bool = null;584 var want_stack_check: ?bool = null;
583 var want_red_zone: ?bool = null;585 var want_red_zone: ?bool = null;
586 var omit_frame_pointer: ?bool = null;
584 var want_valgrind: ?bool = null;587 var want_valgrind: ?bool = null;
585 var want_tsan: ?bool = null;588 var want_tsan: ?bool = null;
586 var want_compiler_rt: ?bool = null;589 var want_compiler_rt: ?bool = null;
...@@ -976,6 +979,10 @@ fn buildOutputType(...@@ -976,6 +979,10 @@ fn buildOutputType(
976 want_red_zone = true;979 want_red_zone = true;
977 } else if (mem.eql(u8, arg, "-mno-red-zone")) {980 } else if (mem.eql(u8, arg, "-mno-red-zone")) {
978 want_red_zone = false;981 want_red_zone = false;
982 } else if (mem.eql(u8, arg, "-fomit-frame-pointer")) {
983 omit_frame_pointer = true;
984 } else if (mem.eql(u8, arg, "-fno-omit-frame-pointer")) {
985 omit_frame_pointer = false;
979 } else if (mem.eql(u8, arg, "-fsanitize-c")) {986 } else if (mem.eql(u8, arg, "-fsanitize-c")) {
980 want_sanitize_c = true;987 want_sanitize_c = true;
981 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {988 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {
...@@ -1217,6 +1224,8 @@ fn buildOutputType(...@@ -1217,6 +1224,8 @@ fn buildOutputType(
1217 .no_lto => want_lto = false,1224 .no_lto => want_lto = false,
1218 .red_zone => want_red_zone = true,1225 .red_zone => want_red_zone = true,
1219 .no_red_zone => want_red_zone = false,1226 .no_red_zone => want_red_zone = false,
1227 .omit_frame_pointer => omit_frame_pointer = true,
1228 .no_omit_frame_pointer => omit_frame_pointer = false,
1220 .unwind_tables => want_unwind_tables = true,1229 .unwind_tables => want_unwind_tables = true,
1221 .no_unwind_tables => want_unwind_tables = false,1230 .no_unwind_tables => want_unwind_tables = false,
1222 .nostdlib => ensure_libc_on_non_freestanding = false,1231 .nostdlib => ensure_libc_on_non_freestanding = false,
...@@ -2082,6 +2091,7 @@ fn buildOutputType(...@@ -2082,6 +2091,7 @@ fn buildOutputType(
2082 .want_sanitize_c = want_sanitize_c,2091 .want_sanitize_c = want_sanitize_c,
2083 .want_stack_check = want_stack_check,2092 .want_stack_check = want_stack_check,
2084 .want_red_zone = want_red_zone,2093 .want_red_zone = want_red_zone,
2094 .omit_frame_pointer = omit_frame_pointer,
2085 .want_valgrind = want_valgrind,2095 .want_valgrind = want_valgrind,
2086 .want_tsan = want_tsan,2096 .want_tsan = want_tsan,
2087 .want_compiler_rt = want_compiler_rt,2097 .want_compiler_rt = want_compiler_rt,
...@@ -3708,6 +3718,8 @@ pub const ClangArgIterator = struct {...@@ -3708,6 +3718,8 @@ pub const ClangArgIterator = struct {
3708 nostdlibinc,3718 nostdlibinc,
3709 red_zone,3719 red_zone,
3710 no_red_zone,3720 no_red_zone,
3721 omit_frame_pointer,
3722 no_omit_frame_pointer,
3711 strip,3723 strip,
3712 exec_model,3724 exec_model,
3713 emit_llvm,3725 emit_llvm,
src/musl.zig+1
...@@ -207,6 +207,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -207,6 +207,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
207 .want_sanitize_c = false,207 .want_sanitize_c = false,
208 .want_stack_check = false,208 .want_stack_check = false,
209 .want_red_zone = comp.bin_file.options.red_zone,209 .want_red_zone = comp.bin_file.options.red_zone,
210 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
210 .want_valgrind = false,211 .want_valgrind = false,
211 .want_tsan = false,212 .want_tsan = false,
212 .emit_h = null,213 .emit_h = null,
src/stage1.zig+1
...@@ -128,6 +128,7 @@ pub const Module = extern struct {...@@ -128,6 +128,7 @@ pub const Module = extern struct {
128 include_compiler_rt: bool,128 include_compiler_rt: bool,
129 enable_stack_probing: bool,129 enable_stack_probing: bool,
130 red_zone: bool,130 red_zone: bool,
131 omit_frame_pointer: bool,
131 enable_time_report: bool,132 enable_time_report: bool,
132 enable_stack_report: bool,133 enable_stack_report: bool,
133 test_is_evented: bool,134 test_is_evented: bool,
src/stage1/all_types.hpp+1
...@@ -2175,6 +2175,7 @@ struct CodeGen {...@@ -2175,6 +2175,7 @@ struct CodeGen {
2175 bool dll_export_fns;2175 bool dll_export_fns;
2176 bool have_stack_probing;2176 bool have_stack_probing;
2177 bool red_zone;2177 bool red_zone;
2178 bool omit_frame_pointer;
2178 bool function_sections;2179 bool function_sections;
2179 bool include_compiler_rt;2180 bool include_compiler_rt;
2180 bool test_is_evented;2181 bool test_is_evented;
src/stage1/codegen.cpp+6-10
...@@ -363,10 +363,6 @@ static bool cc_want_sret_attr(CallingConvention cc) {...@@ -363,10 +363,6 @@ static bool cc_want_sret_attr(CallingConvention cc) {
363 zig_unreachable();363 zig_unreachable();
364}364}
365365
366static bool codegen_have_frame_pointer(CodeGen *g) {
367 return g->build_mode == BuildModeDebug;
368}
369
370static void add_common_fn_attributes(CodeGen *g, LLVMValueRef llvm_fn) {366static void add_common_fn_attributes(CodeGen *g, LLVMValueRef llvm_fn) {
371 if (!g->red_zone) {367 if (!g->red_zone) {
372 addLLVMFnAttr(llvm_fn, "noredzone");368 addLLVMFnAttr(llvm_fn, "noredzone");
...@@ -603,7 +599,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {...@@ -603,7 +599,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
603 addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value);599 addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value);
604 }600 }
605601
606 if (codegen_have_frame_pointer(g) && cc != CallingConventionInline) {602 if (!g->omit_frame_pointer && cc != CallingConventionInline) {
607 ZigLLVMAddFunctionAttr(llvm_fn, "frame-pointer", "all");603 ZigLLVMAddFunctionAttr(llvm_fn, "frame-pointer", "all");
608 }604 }
609 if (fn->section_name) {605 if (fn->section_name) {
...@@ -1223,7 +1219,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1223,7 +1219,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
1223 // Error return trace memory is in the stack, which is impossible to be at address 01219 // Error return trace memory is in the stack, which is impossible to be at address 0
1224 // on any architecture.1220 // on any architecture.
1225 addLLVMArgAttr(fn_val, (unsigned)0, "nonnull");1221 addLLVMArgAttr(fn_val, (unsigned)0, "nonnull");
1226 if (codegen_have_frame_pointer(g)) {1222 if (!g->omit_frame_pointer) {
1227 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");1223 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");
1228 }1224 }
12291225
...@@ -1299,7 +1295,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {...@@ -1299,7 +1295,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {
1299 LLVMSetLinkage(fn_val, LLVMInternalLinkage);1295 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1300 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));1296 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1301 add_common_fn_attributes(g, fn_val);1297 add_common_fn_attributes(g, fn_val);
1302 if (codegen_have_frame_pointer(g)) {1298 if (!g->omit_frame_pointer) {
1303 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");1299 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");
1304 }1300 }
13051301
...@@ -1381,7 +1377,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1381,7 +1377,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1381 LLVMSetLinkage(fn_val, LLVMInternalLinkage);1377 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1382 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));1378 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1383 add_common_fn_attributes(g, fn_val);1379 add_common_fn_attributes(g, fn_val);
1384 if (codegen_have_frame_pointer(g)) {1380 if (!g->omit_frame_pointer) {
1385 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");1381 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");
1386 }1382 }
1387 // Not setting alignment here. See the comment above about1383 // Not setting alignment here. See the comment above about
...@@ -2389,7 +2385,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {...@@ -2389,7 +2385,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
23892385
2390 addLLVMArgAttr(fn_val, (unsigned)1, "noalias");2386 addLLVMArgAttr(fn_val, (unsigned)1, "noalias");
2391 addLLVMArgAttr(fn_val, (unsigned)1, "readonly");2387 addLLVMArgAttr(fn_val, (unsigned)1, "readonly");
2392 if (codegen_have_frame_pointer(g)) {2388 if (!g->omit_frame_pointer) {
2393 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");2389 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");
2394 }2390 }
23952391
...@@ -5418,7 +5414,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -5418,7 +5414,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
5418 LLVMSetLinkage(fn_val, LLVMInternalLinkage);5414 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
5419 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));5415 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
5420 add_common_fn_attributes(g, fn_val);5416 add_common_fn_attributes(g, fn_val);
5421 if (codegen_have_frame_pointer(g)) {5417 if (!g->omit_frame_pointer) {
5422 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");5418 ZigLLVMAddFunctionAttr(fn_val, "frame-pointer", "all");
5423 }5419 }
54245420
src/stage1/stage1.cpp+1
...@@ -95,6 +95,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {...@@ -95,6 +95,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {
95 g->unwind_tables = stage1->unwind_tables;95 g->unwind_tables = stage1->unwind_tables;
96 g->have_stack_probing = stage1->enable_stack_probing;96 g->have_stack_probing = stage1->enable_stack_probing;
97 g->red_zone = stage1->red_zone;97 g->red_zone = stage1->red_zone;
98 g->omit_frame_pointer = stage1->omit_frame_pointer;
98 g->is_single_threaded = stage1->is_single_threaded;99 g->is_single_threaded = stage1->is_single_threaded;
99 g->valgrind_enabled = stage1->valgrind_enabled;100 g->valgrind_enabled = stage1->valgrind_enabled;
100 g->tsan_enabled = stage1->tsan_enabled;101 g->tsan_enabled = stage1->tsan_enabled;
src/stage1/stage1.h+1
...@@ -199,6 +199,7 @@ struct ZigStage1 {...@@ -199,6 +199,7 @@ struct ZigStage1 {
199 bool include_compiler_rt;199 bool include_compiler_rt;
200 bool enable_stack_probing;200 bool enable_stack_probing;
201 bool red_zone;201 bool red_zone;
202 bool omit_frame_pointer;
202 bool enable_time_report;203 bool enable_time_report;
203 bool enable_stack_report;204 bool enable_stack_report;
204 bool test_is_evented;205 bool test_is_evented;
tools/update_clang_options.zig+8
...@@ -300,6 +300,14 @@ const known_options = [_]KnownOpt{...@@ -300,6 +300,14 @@ const known_options = [_]KnownOpt{
300 .name = "mno-red-zone",300 .name = "mno-red-zone",
301 .ident = "no_red_zone",301 .ident = "no_red_zone",
302 },302 },
303 .{
304 .name = "fomit-frame-pointer",
305 .ident = "omit_frame_pointer",
306 },
307 .{
308 .name = "fno-omit-frame-pointer",
309 .ident = "no_omit_frame_pointer",
310 },
303 .{311 .{
304 .name = "MD",312 .name = "MD",
305 .ident = "dep_file",313 .ident = "dep_file",