authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-09-30 19:49:13+01:00
committergravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-16 21:55:51+01:00
logb15d6b2a34294bd48bc090f858c1b9527763163a
tree722c000612f2f4581820c9c437f40dfd5f015fe2
parentfdd11f6cee7ef14253cef53729e09d9415b4be7e

Add build.zig and command line flags


14 files changed, 68 insertions(+), 2 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
...@@ -680,6 +680,7 @@ pub const InitOptions = struct {...@@ -680,6 +680,7 @@ pub const InitOptions = struct {
680 want_sanitize_c: ?bool = null,680 want_sanitize_c: ?bool = null,
681 want_stack_check: ?bool = null,681 want_stack_check: ?bool = null,
682 want_red_zone: ?bool = null,682 want_red_zone: ?bool = null,
683 omit_frame_pointer: ?bool = null,
683 want_valgrind: ?bool = null,684 want_valgrind: ?bool = null,
684 want_tsan: ?bool = null,685 want_tsan: ?bool = null,
685 want_compiler_rt: ?bool = null,686 want_compiler_rt: ?bool = null,
...@@ -1113,6 +1114,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1113,6 +1114,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
11131114
1114 const strip = options.strip or !target_util.hasDebugInfo(options.target);1115 const strip = options.strip or !target_util.hasDebugInfo(options.target);
1115 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);1116 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
1117 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
11161118
1117 // We put everything into the cache hash that *cannot be modified during an incremental update*.1119 // We put everything into the cache hash that *cannot be modified during an incremental update*.
1118 // For example, one cannot change the target between updates, but one can change source files,1120 // For example, one cannot change the target between updates, but one can change source files,
...@@ -1146,6 +1148,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1146,6 +1148,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1146 cache.hash.add(tsan);1148 cache.hash.add(tsan);
1147 cache.hash.add(stack_check);1149 cache.hash.add(stack_check);
1148 cache.hash.add(red_zone);1150 cache.hash.add(red_zone);
1151 cache.hash.add(omit_frame_pointer);
1149 cache.hash.add(link_mode);1152 cache.hash.add(link_mode);
1150 cache.hash.add(options.function_sections);1153 cache.hash.add(options.function_sections);
1151 cache.hash.add(strip);1154 cache.hash.add(strip);
...@@ -1416,6 +1419,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1416,6 +1419,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1416 .tsan = tsan,1419 .tsan = tsan,
1417 .stack_check = stack_check,1420 .stack_check = stack_check,
1418 .red_zone = red_zone,1421 .red_zone = red_zone,
1422 .omit_frame_pointer = omit_frame_pointer,
1419 .single_threaded = single_threaded,1423 .single_threaded = single_threaded,
1420 .verbose_link = options.verbose_link,1424 .verbose_link = options.verbose_link,
1421 .machine_code_model = options.machine_code_model,1425 .machine_code_model = options.machine_code_model,
...@@ -3189,6 +3193,12 @@ pub fn addCCArgs(...@@ -3189,6 +3193,12 @@ pub fn addCCArgs(
3189 try argv.append("-mno-red-zone");3193 try argv.append("-mno-red-zone");
3190 }3194 }
31913195
3196 if (comp.bin_file.options.omit_frame_pointer) {
3197 try argv.append("-fomit-frame-pointer");
3198 } else {
3199 try argv.append("-fno-omit-frame-pointer");
3200 }
3201
3192 switch (comp.bin_file.options.optimize_mode) {3202 switch (comp.bin_file.options.optimize_mode) {
3193 .Debug => {3203 .Debug => {
3194 // windows c runtime requires -D_DEBUG if using debug libraries3204 // windows c runtime requires -D_DEBUG if using debug libraries
...@@ -4019,6 +4029,7 @@ fn buildOutputFromZig(...@@ -4019,6 +4029,7 @@ fn buildOutputFromZig(
4019 .want_sanitize_c = false,4029 .want_sanitize_c = false,
4020 .want_stack_check = false,4030 .want_stack_check = false,
4021 .want_red_zone = comp.bin_file.options.red_zone,4031 .want_red_zone = comp.bin_file.options.red_zone,
4032 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4022 .want_valgrind = false,4033 .want_valgrind = false,
4023 .want_tsan = false,4034 .want_tsan = false,
4024 .want_pic = comp.bin_file.options.pic,4035 .want_pic = comp.bin_file.options.pic,
...@@ -4302,6 +4313,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -4302,6 +4313,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
4302 .include_compiler_rt = include_compiler_rt,4313 .include_compiler_rt = include_compiler_rt,
4303 .enable_stack_probing = comp.bin_file.options.stack_check,4314 .enable_stack_probing = comp.bin_file.options.stack_check,
4304 .red_zone = comp.bin_file.options.red_zone,4315 .red_zone = comp.bin_file.options.red_zone,
4316 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4305 .enable_time_report = comp.time_report,4317 .enable_time_report = comp.time_report,
4306 .enable_stack_report = comp.stack_report,4318 .enable_stack_report = comp.stack_report,
4307 .test_is_evented = comp.test_evented_io,4319 .test_is_evented = comp.test_evented_io,
...@@ -4451,6 +4463,7 @@ pub fn build_crt_file(...@@ -4451,6 +4463,7 @@ pub fn build_crt_file(
4451 .want_sanitize_c = false,4463 .want_sanitize_c = false,
4452 .want_stack_check = false,4464 .want_stack_check = false,
4453 .want_red_zone = comp.bin_file.options.red_zone,4465 .want_red_zone = comp.bin_file.options.red_zone,
4466 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
4454 .want_valgrind = false,4467 .want_valgrind = false,
4455 .want_tsan = false,4468 .want_tsan = false,
4456 .want_pic = comp.bin_file.options.pic,4469 .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/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
...@@ -330,6 +330,8 @@ const usage_build_generic =...@@ -330,6 +330,8 @@ const usage_build_generic =
330 \\ medium|large]330 \\ medium|large]
331 \\ -mred-zone Force-enable the "red-zone"331 \\ -mred-zone Force-enable the "red-zone"
332 \\ -mno-red-zone Force-disable the "red-zone"332 \\ -mno-red-zone Force-disable the "red-zone"
333 \\ -fomit-frame-pointer Omit the stack frame pointer
334 \\ -fno-omit-frame-pointer Store the stack frame pointer
333 \\ -mexec-model=[value] Execution model (WASI only)335 \\ -mexec-model=[value] Execution model (WASI only)
334 \\ --name [name] Override root name (not a file path)336 \\ --name [name] Override root name (not a file path)
335 \\ -O [mode] Choose what to optimize for337 \\ -O [mode] Choose what to optimize for
...@@ -587,6 +589,7 @@ fn buildOutputType(...@@ -587,6 +589,7 @@ fn buildOutputType(
587 var want_sanitize_c: ?bool = null;589 var want_sanitize_c: ?bool = null;
588 var want_stack_check: ?bool = null;590 var want_stack_check: ?bool = null;
589 var want_red_zone: ?bool = null;591 var want_red_zone: ?bool = null;
592 var omit_frame_pointer: ?bool = null;
590 var want_valgrind: ?bool = null;593 var want_valgrind: ?bool = null;
591 var want_tsan: ?bool = null;594 var want_tsan: ?bool = null;
592 var want_compiler_rt: ?bool = null;595 var want_compiler_rt: ?bool = null;
...@@ -975,6 +978,10 @@ fn buildOutputType(...@@ -975,6 +978,10 @@ fn buildOutputType(
975 want_red_zone = true;978 want_red_zone = true;
976 } else if (mem.eql(u8, arg, "-mno-red-zone")) {979 } else if (mem.eql(u8, arg, "-mno-red-zone")) {
977 want_red_zone = false;980 want_red_zone = false;
981 } else if (mem.eql(u8, arg, "-fomit-frame-pointer")) {
982 omit_frame_pointer = true;
983 } else if (mem.eql(u8, arg, "-fno-omit-frame-pointer")) {
984 omit_frame_pointer = false;
978 } else if (mem.eql(u8, arg, "-fsanitize-c")) {985 } else if (mem.eql(u8, arg, "-fsanitize-c")) {
979 want_sanitize_c = true;986 want_sanitize_c = true;
980 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {987 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {
...@@ -1216,6 +1223,8 @@ fn buildOutputType(...@@ -1216,6 +1223,8 @@ fn buildOutputType(
1216 .no_lto => want_lto = false,1223 .no_lto => want_lto = false,
1217 .red_zone => want_red_zone = true,1224 .red_zone => want_red_zone = true,
1218 .no_red_zone => want_red_zone = false,1225 .no_red_zone => want_red_zone = false,
1226 .omit_frame_pointer => omit_frame_pointer = true,
1227 .no_omit_frame_pointer => omit_frame_pointer = false,
1219 .unwind_tables => want_unwind_tables = true,1228 .unwind_tables => want_unwind_tables = true,
1220 .no_unwind_tables => want_unwind_tables = false,1229 .no_unwind_tables => want_unwind_tables = false,
1221 .nostdlib => ensure_libc_on_non_freestanding = false,1230 .nostdlib => ensure_libc_on_non_freestanding = false,
...@@ -2081,6 +2090,7 @@ fn buildOutputType(...@@ -2081,6 +2090,7 @@ fn buildOutputType(
2081 .want_sanitize_c = want_sanitize_c,2090 .want_sanitize_c = want_sanitize_c,
2082 .want_stack_check = want_stack_check,2091 .want_stack_check = want_stack_check,
2083 .want_red_zone = want_red_zone,2092 .want_red_zone = want_red_zone,
2093 .omit_frame_pointer = omit_frame_pointer,
2084 .want_valgrind = want_valgrind,2094 .want_valgrind = want_valgrind,
2085 .want_tsan = want_tsan,2095 .want_tsan = want_tsan,
2086 .want_compiler_rt = want_compiler_rt,2096 .want_compiler_rt = want_compiler_rt,
...@@ -3706,6 +3716,8 @@ pub const ClangArgIterator = struct {...@@ -3706,6 +3716,8 @@ pub const ClangArgIterator = struct {
3706 nostdlibinc,3716 nostdlibinc,
3707 red_zone,3717 red_zone,
3708 no_red_zone,3718 no_red_zone,
3719 omit_frame_pointer,
3720 no_omit_frame_pointer,
3709 strip,3721 strip,
3710 exec_model,3722 exec_model,
3711 emit_llvm,3723 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/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",