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 {
15151515
15161516 red_zone: ?bool = null,
15171517
1518 omit_frame_pointer: ?bool = null,
1519
15181520 subsystem: ?std.Target.SubSystem = null,
15191521
15201522 /// Overrides the default stack size
......@@ -2406,6 +2408,13 @@ pub const LibExeObjStep = struct {
24062408 try zig_args.append("-mno-red-zone");
24072409 }
24082410 }
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 }
24092418 if (self.disable_sanitize_c) {
24102419 try zig_args.append("-fno-sanitize-c");
24112420 }
src/Compilation.zig+13
......@@ -680,6 +680,7 @@ pub const InitOptions = struct {
680680 want_sanitize_c: ?bool = null,
681681 want_stack_check: ?bool = null,
682682 want_red_zone: ?bool = null,
683 omit_frame_pointer: ?bool = null,
683684 want_valgrind: ?bool = null,
684685 want_tsan: ?bool = null,
685686 want_compiler_rt: ?bool = null,
......@@ -1113,6 +1114,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
11131114
11141115 const strip = options.strip or !target_util.hasDebugInfo(options.target);
11151116 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
11171119 // We put everything into the cache hash that *cannot be modified during an incremental update*.
11181120 // 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 {
11461148 cache.hash.add(tsan);
11471149 cache.hash.add(stack_check);
11481150 cache.hash.add(red_zone);
1151 cache.hash.add(omit_frame_pointer);
11491152 cache.hash.add(link_mode);
11501153 cache.hash.add(options.function_sections);
11511154 cache.hash.add(strip);
......@@ -1416,6 +1419,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14161419 .tsan = tsan,
14171420 .stack_check = stack_check,
14181421 .red_zone = red_zone,
1422 .omit_frame_pointer = omit_frame_pointer,
14191423 .single_threaded = single_threaded,
14201424 .verbose_link = options.verbose_link,
14211425 .machine_code_model = options.machine_code_model,
......@@ -3189,6 +3193,12 @@ pub fn addCCArgs(
31893193 try argv.append("-mno-red-zone");
31903194 }
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
31923202 switch (comp.bin_file.options.optimize_mode) {
31933203 .Debug => {
31943204 // windows c runtime requires -D_DEBUG if using debug libraries
......@@ -4019,6 +4029,7 @@ fn buildOutputFromZig(
40194029 .want_sanitize_c = false,
40204030 .want_stack_check = false,
40214031 .want_red_zone = comp.bin_file.options.red_zone,
4032 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
40224033 .want_valgrind = false,
40234034 .want_tsan = false,
40244035 .want_pic = comp.bin_file.options.pic,
......@@ -4302,6 +4313,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
43024313 .include_compiler_rt = include_compiler_rt,
43034314 .enable_stack_probing = comp.bin_file.options.stack_check,
43044315 .red_zone = comp.bin_file.options.red_zone,
4316 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
43054317 .enable_time_report = comp.time_report,
43064318 .enable_stack_report = comp.stack_report,
43074319 .test_is_evented = comp.test_evented_io,
......@@ -4451,6 +4463,7 @@ pub fn build_crt_file(
44514463 .want_sanitize_c = false,
44524464 .want_stack_check = false,
44534465 .want_red_zone = comp.bin_file.options.red_zone,
4466 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
44544467 .want_valgrind = false,
44554468 .want_tsan = false,
44564469 .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"),
30143014flagpd1("fno-objc-legacy-dispatch"),
30153015flagpd1("fno-objc-nonfragile-abi"),
30163016flagpd1("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},
30183025flagpd1("fno-openmp"),
30193026flagpd1("fno-openmp-cuda-force-full-runtime"),
30203027flagpd1("fno-openmp-cuda-mode"),
......@@ -3235,7 +3242,14 @@ flagpd1("fobjc-runtime-has-weak"),
32353242flagpd1("fobjc-sender-dependent-dispatch"),
32363243flagpd1("fobjc-subscripting-legacy-runtime"),
32373244flagpd1("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},
32393253flagpd1("fopenmp"),
32403254flagpd1("fopenmp-cuda-force-full-runtime"),
32413255flagpd1("fopenmp-cuda-mode"),
src/glibc.zig+1
......@@ -953,6 +953,7 @@ fn buildSharedLib(
953953 .want_sanitize_c = false,
954954 .want_stack_check = false,
955955 .want_red_zone = comp.bin_file.options.red_zone,
956 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
956957 .want_valgrind = false,
957958 .want_tsan = false,
958959 .emit_h = null,
src/libcxx.zig+2
......@@ -189,6 +189,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
189189 .want_sanitize_c = false,
190190 .want_stack_check = false,
191191 .want_red_zone = comp.bin_file.options.red_zone,
192 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
192193 .want_valgrind = false,
193194 .want_tsan = comp.bin_file.options.tsan,
194195 .want_pic = comp.bin_file.options.pic,
......@@ -321,6 +322,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
321322 .want_sanitize_c = false,
322323 .want_stack_check = false,
323324 .want_red_zone = comp.bin_file.options.red_zone,
325 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
324326 .want_valgrind = false,
325327 .want_tsan = comp.bin_file.options.tsan,
326328 .want_pic = comp.bin_file.options.pic,
src/libunwind.zig+1
......@@ -113,6 +113,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
113113 .want_sanitize_c = false,
114114 .want_stack_check = false,
115115 .want_red_zone = comp.bin_file.options.red_zone,
116 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
116117 .want_valgrind = false,
117118 .want_tsan = false,
118119 .want_pic = comp.bin_file.options.pic,
src/link.zig+1
......@@ -90,6 +90,7 @@ pub const Options = struct {
9090 tsan: bool,
9191 stack_check: bool,
9292 red_zone: bool,
93 omit_frame_pointer: bool,
9394 single_threaded: bool,
9495 verbose_link: bool,
9596 dll_export_fns: bool,
src/main.zig+12
......@@ -330,6 +330,8 @@ const usage_build_generic =
330330 \\ medium|large]
331331 \\ -mred-zone Force-enable the "red-zone"
332332 \\ -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
333335 \\ -mexec-model=[value] Execution model (WASI only)
334336 \\ --name [name] Override root name (not a file path)
335337 \\ -O [mode] Choose what to optimize for
......@@ -587,6 +589,7 @@ fn buildOutputType(
587589 var want_sanitize_c: ?bool = null;
588590 var want_stack_check: ?bool = null;
589591 var want_red_zone: ?bool = null;
592 var omit_frame_pointer: ?bool = null;
590593 var want_valgrind: ?bool = null;
591594 var want_tsan: ?bool = null;
592595 var want_compiler_rt: ?bool = null;
......@@ -975,6 +978,10 @@ fn buildOutputType(
975978 want_red_zone = true;
976979 } else if (mem.eql(u8, arg, "-mno-red-zone")) {
977980 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;
978985 } else if (mem.eql(u8, arg, "-fsanitize-c")) {
979986 want_sanitize_c = true;
980987 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {
......@@ -1216,6 +1223,8 @@ fn buildOutputType(
12161223 .no_lto => want_lto = false,
12171224 .red_zone => want_red_zone = true,
12181225 .no_red_zone => want_red_zone = false,
1226 .omit_frame_pointer => omit_frame_pointer = true,
1227 .no_omit_frame_pointer => omit_frame_pointer = false,
12191228 .unwind_tables => want_unwind_tables = true,
12201229 .no_unwind_tables => want_unwind_tables = false,
12211230 .nostdlib => ensure_libc_on_non_freestanding = false,
......@@ -2081,6 +2090,7 @@ fn buildOutputType(
20812090 .want_sanitize_c = want_sanitize_c,
20822091 .want_stack_check = want_stack_check,
20832092 .want_red_zone = want_red_zone,
2093 .omit_frame_pointer = omit_frame_pointer,
20842094 .want_valgrind = want_valgrind,
20852095 .want_tsan = want_tsan,
20862096 .want_compiler_rt = want_compiler_rt,
......@@ -3706,6 +3716,8 @@ pub const ClangArgIterator = struct {
37063716 nostdlibinc,
37073717 red_zone,
37083718 no_red_zone,
3719 omit_frame_pointer,
3720 no_omit_frame_pointer,
37093721 strip,
37103722 exec_model,
37113723 emit_llvm,
src/musl.zig+1
......@@ -207,6 +207,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
207207 .want_sanitize_c = false,
208208 .want_stack_check = false,
209209 .want_red_zone = comp.bin_file.options.red_zone,
210 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
210211 .want_valgrind = false,
211212 .want_tsan = false,
212213 .emit_h = null,
src/stage1.zig+1
......@@ -128,6 +128,7 @@ pub const Module = extern struct {
128128 include_compiler_rt: bool,
129129 enable_stack_probing: bool,
130130 red_zone: bool,
131 omit_frame_pointer: bool,
131132 enable_time_report: bool,
132133 enable_stack_report: bool,
133134 test_is_evented: bool,
src/stage1/all_types.hpp+1
......@@ -2175,6 +2175,7 @@ struct CodeGen {
21752175 bool dll_export_fns;
21762176 bool have_stack_probing;
21772177 bool red_zone;
2178 bool omit_frame_pointer;
21782179 bool function_sections;
21792180 bool include_compiler_rt;
21802181 bool test_is_evented;
src/stage1/stage1.cpp+1
......@@ -95,6 +95,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {
9595 g->unwind_tables = stage1->unwind_tables;
9696 g->have_stack_probing = stage1->enable_stack_probing;
9797 g->red_zone = stage1->red_zone;
98 g->omit_frame_pointer = stage1->omit_frame_pointer;
9899 g->is_single_threaded = stage1->is_single_threaded;
99100 g->valgrind_enabled = stage1->valgrind_enabled;
100101 g->tsan_enabled = stage1->tsan_enabled;
src/stage1/stage1.h+1
......@@ -199,6 +199,7 @@ struct ZigStage1 {
199199 bool include_compiler_rt;
200200 bool enable_stack_probing;
201201 bool red_zone;
202 bool omit_frame_pointer;
202203 bool enable_time_report;
203204 bool enable_stack_report;
204205 bool test_is_evented;
tools/update_clang_options.zig+8
......@@ -300,6 +300,14 @@ const known_options = [_]KnownOpt{
300300 .name = "mno-red-zone",
301301 .ident = "no_red_zone",
302302 },
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 },
303311 .{
304312 .name = "MD",
305313 .ident = "dep_file",