| author | |
| committer | |
| log | 2b65dc10328cc437b21114e3c87fac2ef6ef9adc |
| tree | e40cec4e13ea3f1605b47ff84e8bc956162dde6c |
| parent | 4b0ddb817bb5d4effd8cd2dd0844ac278e35e1d5 |
| signature |
7 files changed, 159 insertions(+), 24 deletions(-)
src-self-hosted/clang_options.zig+5-5| ... | ... | @@ -46,23 +46,23 @@ pub const CliArg = struct { |
| 46 | 46 | multi_arg: u8, |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | pub fn matchEql(self: CliArg, arg: []const u8) bool { | |
| 49 | pub fn matchEql(self: CliArg, arg: []const u8) u2 { | |
| 50 | 50 | if (self.pd1 and arg.len >= self.name.len + 1 and |
| 51 | 51 | mem.startsWith(u8, arg, "-") and mem.eql(u8, arg[1..], self.name)) |
| 52 | 52 | { |
| 53 | return true; | |
| 53 | return 1; | |
| 54 | 54 | } |
| 55 | 55 | if (self.pd2 and arg.len >= self.name.len + 2 and |
| 56 | 56 | mem.startsWith(u8, arg, "--") and mem.eql(u8, arg[2..], self.name)) |
| 57 | 57 | { |
| 58 | return true; | |
| 58 | return 2; | |
| 59 | 59 | } |
| 60 | 60 | if (self.psl and arg.len >= self.name.len + 1 and |
| 61 | 61 | mem.startsWith(u8, arg, "/") and mem.eql(u8, arg[1..], self.name)) |
| 62 | 62 | { |
| 63 | return true; | |
| 63 | return 1; | |
| 64 | 64 | } |
| 65 | return false; | |
| 65 | return 0; | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | pub fn matchStartsWith(self: CliArg, arg: []const u8) usize { |
src-self-hosted/clang_options_data.zig+41-13| ... | ... | @@ -35,7 +35,14 @@ flagpd1("MV"), |
| 35 | 35 | flagpd1("Mach"), |
| 36 | 36 | flagpd1("O0"), |
| 37 | 37 | flagpd1("O4"), |
| 38 | flagpd1("O"), | |
| 38 | .{ | |
| 39 | .name = "O", | |
| 40 | .syntax = .flag, | |
| 41 | .zig_equivalent = .optimize, | |
| 42 | .pd1 = true, | |
| 43 | .pd2 = false, | |
| 44 | .psl = false, | |
| 45 | }, | |
| 39 | 46 | flagpd1("ObjC"), |
| 40 | 47 | flagpd1("ObjC++"), |
| 41 | 48 | flagpd1("P"), |
| ... | ... | @@ -1485,7 +1492,7 @@ flagpd1("###"), |
| 1485 | 1492 | .{ |
| 1486 | 1493 | .name = "debug", |
| 1487 | 1494 | .syntax = .flag, |
| 1488 | .zig_equivalent = .other, | |
| 1495 | .zig_equivalent = .debug, | |
| 1489 | 1496 | .pd1 = false, |
| 1490 | 1497 | .pd2 = true, |
| 1491 | 1498 | .psl = false, |
| ... | ... | @@ -1701,7 +1708,7 @@ flagpd1("###"), |
| 1701 | 1708 | .{ |
| 1702 | 1709 | .name = "optimize", |
| 1703 | 1710 | .syntax = .flag, |
| 1704 | .zig_equivalent = .other, | |
| 1711 | .zig_equivalent = .optimize, | |
| 1705 | 1712 | .pd1 = false, |
| 1706 | 1713 | .pd2 = true, |
| 1707 | 1714 | .psl = false, |
| ... | ... | @@ -2034,7 +2041,7 @@ flagpd1("fno-semantic-interposition"), |
| 2034 | 2041 | .{ |
| 2035 | 2042 | .name = "O1", |
| 2036 | 2043 | .syntax = .flag, |
| 2037 | .zig_equivalent = .other, | |
| 2044 | .zig_equivalent = .optimize, | |
| 2038 | 2045 | .pd1 = true, |
| 2039 | 2046 | .pd2 = false, |
| 2040 | 2047 | .psl = true, |
| ... | ... | @@ -2042,7 +2049,7 @@ flagpd1("fno-semantic-interposition"), |
| 2042 | 2049 | .{ |
| 2043 | 2050 | .name = "O2", |
| 2044 | 2051 | .syntax = .flag, |
| 2045 | .zig_equivalent = .other, | |
| 2052 | .zig_equivalent = .optimize, | |
| 2046 | 2053 | .pd1 = true, |
| 2047 | 2054 | .pd2 = false, |
| 2048 | 2055 | .psl = true, |
| ... | ... | @@ -2083,7 +2090,7 @@ flagpd1("fno-ident"), |
| 2083 | 2090 | .{ |
| 2084 | 2091 | .name = "Og", |
| 2085 | 2092 | .syntax = .flag, |
| 2086 | .zig_equivalent = .other, | |
| 2093 | .zig_equivalent = .optimize, | |
| 2087 | 2094 | .pd1 = true, |
| 2088 | 2095 | .pd2 = false, |
| 2089 | 2096 | .psl = true, |
| ... | ... | @@ -3088,7 +3095,14 @@ flagpd1("g0"), |
| 3088 | 3095 | flagpd1("g1"), |
| 3089 | 3096 | flagpd1("g2"), |
| 3090 | 3097 | flagpd1("g3"), |
| 3091 | flagpd1("g"), | |
| 3098 | .{ | |
| 3099 | .name = "g", | |
| 3100 | .syntax = .flag, | |
| 3101 | .zig_equivalent = .debug, | |
| 3102 | .pd1 = true, | |
| 3103 | .pd2 = false, | |
| 3104 | .psl = false, | |
| 3105 | }, | |
| 3092 | 3106 | sepd1("gcc-toolchain"), |
| 3093 | 3107 | flagpd1("gcodeview"), |
| 3094 | 3108 | flagpd1("gcodeview-ghash"), |
| ... | ... | @@ -4954,7 +4968,7 @@ joinpd1("flto-jobs="), |
| 4954 | 4968 | .{ |
| 4955 | 4969 | .name = "fsanitize=", |
| 4956 | 4970 | .syntax = .comma_joined, |
| 4957 | .zig_equivalent = .other, | |
| 4971 | .zig_equivalent = .sanitize, | |
| 4958 | 4972 | .pd1 = true, |
| 4959 | 4973 | .pd2 = false, |
| 4960 | 4974 | .psl = false, |
| ... | ... | @@ -4997,7 +5011,7 @@ joinpd1("segs_read_"), |
| 4997 | 5011 | .{ |
| 4998 | 5012 | .name = "optimize=", |
| 4999 | 5013 | .syntax = .joined, |
| 5000 | .zig_equivalent = .other, | |
| 5014 | .zig_equivalent = .optimize, | |
| 5001 | 5015 | .pd1 = false, |
| 5002 | 5016 | .pd2 = true, |
| 5003 | 5017 | .psl = false, |
| ... | ... | @@ -5187,7 +5201,7 @@ joinpd1("Rpass="), |
| 5187 | 5201 | .{ |
| 5188 | 5202 | .name = "debug=", |
| 5189 | 5203 | .syntax = .joined, |
| 5190 | .zig_equivalent = .other, | |
| 5204 | .zig_equivalent = .debug, | |
| 5191 | 5205 | .pd1 = false, |
| 5192 | 5206 | .pd2 = true, |
| 5193 | 5207 | .psl = false, |
| ... | ... | @@ -5231,7 +5245,14 @@ joinpd1("mtune="), |
| 5231 | 5245 | .psl = false, |
| 5232 | 5246 | }, |
| 5233 | 5247 | joinpd1("weak-l"), |
| 5234 | joinpd1("Ofast"), | |
| 5248 | .{ | |
| 5249 | .name = "Ofast", | |
| 5250 | .syntax = .joined, | |
| 5251 | .zig_equivalent = .optimize, | |
| 5252 | .pd1 = true, | |
| 5253 | .pd2 = false, | |
| 5254 | .psl = false, | |
| 5255 | }, | |
| 5235 | 5256 | jspd1("Tdata"), |
| 5236 | 5257 | jspd1("Ttext"), |
| 5237 | 5258 | .{ |
| ... | ... | @@ -5584,7 +5605,14 @@ jspd1("G"), |
| 5584 | 5605 | jspd1("I"), |
| 5585 | 5606 | jspd1("J"), |
| 5586 | 5607 | jspd1("L"), |
| 5587 | joinpd1("O"), | |
| 5608 | .{ | |
| 5609 | .name = "O", | |
| 5610 | .syntax = .joined, | |
| 5611 | .zig_equivalent = .optimize, | |
| 5612 | .pd1 = true, | |
| 5613 | .pd2 = false, | |
| 5614 | .psl = false, | |
| 5615 | }, | |
| 5588 | 5616 | joinpd1("R"), |
| 5589 | 5617 | jspd1("T"), |
| 5590 | 5618 | jspd1("U"), |
| ... | ... | @@ -5619,7 +5647,7 @@ joinpd1("Z"), |
| 5619 | 5647 | .{ |
| 5620 | 5648 | .name = "O", |
| 5621 | 5649 | .syntax = .joined, |
| 5622 | .zig_equivalent = .other, | |
| 5650 | .zig_equivalent = .optimize, | |
| 5623 | 5651 | .pd1 = true, |
| 5624 | 5652 | .pd2 = false, |
| 5625 | 5653 | .psl = true, |
src-self-hosted/stage2.zig+12-6| ... | ... | @@ -1248,6 +1248,9 @@ pub const ClangArgIterator = extern struct { |
| 1248 | 1248 | rdynamic, |
| 1249 | 1249 | wl, |
| 1250 | 1250 | preprocess, |
| 1251 | optimize, | |
| 1252 | debug, | |
| 1253 | sanitize, | |
| 1251 | 1254 | }; |
| 1252 | 1255 | |
| 1253 | 1256 | fn init(argv: []const [*:0]const u8) ClangArgIterator { |
| ... | ... | @@ -1284,11 +1287,14 @@ pub const ClangArgIterator = extern struct { |
| 1284 | 1287 | } |
| 1285 | 1288 | |
| 1286 | 1289 | find_clang_arg: for (clang_args) |clang_arg| switch (clang_arg.syntax) { |
| 1287 | .flag => if (clang_arg.matchEql(arg)) { | |
| 1288 | self.zig_equivalent = clang_arg.zig_equivalent; | |
| 1289 | self.only_arg = arg.ptr; | |
| 1290 | .flag => { | |
| 1291 | const prefix_len = clang_arg.matchEql(arg); | |
| 1292 | if (prefix_len > 0) { | |
| 1293 | self.zig_equivalent = clang_arg.zig_equivalent; | |
| 1294 | self.only_arg = arg.ptr + prefix_len; | |
| 1290 | 1295 | |
| 1291 | break :find_clang_arg; | |
| 1296 | break :find_clang_arg; | |
| 1297 | } | |
| 1292 | 1298 | }, |
| 1293 | 1299 | .joined, .comma_joined => { |
| 1294 | 1300 | // joined example: --target=foo |
| ... | ... | @@ -1338,7 +1344,7 @@ pub const ClangArgIterator = extern struct { |
| 1338 | 1344 | break :find_clang_arg; |
| 1339 | 1345 | } |
| 1340 | 1346 | }, |
| 1341 | .separate => if (clang_arg.matchEql(arg)) { | |
| 1347 | .separate => if (clang_arg.matchEql(arg) > 0) { | |
| 1342 | 1348 | if (self.next_index >= self.argv_len) { |
| 1343 | 1349 | std.debug.warn("Expected parameter after '{}'\n", .{arg}); |
| 1344 | 1350 | process.exit(1); |
| ... | ... | @@ -1355,7 +1361,7 @@ pub const ClangArgIterator = extern struct { |
| 1355 | 1361 | @panic("TODO"); |
| 1356 | 1362 | } |
| 1357 | 1363 | }, |
| 1358 | .multi_arg => if (clang_arg.matchEql(arg)) { | |
| 1364 | .multi_arg => if (clang_arg.matchEql(arg) > 0) { | |
| 1359 | 1365 | @panic("TODO"); |
| 1360 | 1366 | }, |
| 1361 | 1367 | } |
src/codegen.cpp+1| ... | ... | @@ -9269,6 +9269,7 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9269 | 9269 | case BuildModeDebug: |
| 9270 | 9270 | // windows c runtime requires -D_DEBUG if using debug libraries |
| 9271 | 9271 | args.append("-D_DEBUG"); |
| 9272 | args.append("-Og"); | |
| 9272 | 9273 | |
| 9273 | 9274 | if (g->libc_link_lib != nullptr) { |
| 9274 | 9275 | args.append("-fstack-protector-strong"); |
src/main.cpp+41| ... | ... | @@ -580,6 +580,7 @@ static int main0(int argc, char **argv) { |
| 580 | 580 | return stage2_fmt(argc, argv); |
| 581 | 581 | } else if (argc >= 2 && strcmp(argv[1], "cc") == 0) { |
| 582 | 582 | emit_h = false; |
| 583 | strip = true; | |
| 583 | 584 | |
| 584 | 585 | bool c_arg = false; |
| 585 | 586 | Stage2ClangArgIterator it; |
| ... | ... | @@ -664,6 +665,42 @@ static int main0(int argc, char **argv) { |
| 664 | 665 | case Stage2ClangArgPreprocess: |
| 665 | 666 | only_preprocess = true; |
| 666 | 667 | break; |
| 668 | case Stage2ClangArgOptimize: | |
| 669 | // alright what release mode do they want? | |
| 670 | if (strcmp(it.only_arg, "Os") == 0) { | |
| 671 | build_mode = BuildModeSmallRelease; | |
| 672 | } else if (strcmp(it.only_arg, "O2") == 0 || | |
| 673 | strcmp(it.only_arg, "O3") == 0 || | |
| 674 | strcmp(it.only_arg, "O4") == 0) | |
| 675 | { | |
| 676 | build_mode = BuildModeFastRelease; | |
| 677 | } else if (strcmp(it.only_arg, "Og") == 0) { | |
| 678 | build_mode = BuildModeDebug; | |
| 679 | } else { | |
| 680 | for (size_t i = 0; i < it.other_args_len; i += 1) { | |
| 681 | clang_argv.append(it.other_args_ptr[i]); | |
| 682 | } | |
| 683 | } | |
| 684 | break; | |
| 685 | case Stage2ClangArgDebug: | |
| 686 | strip = false; | |
| 687 | if (strcmp(it.only_arg, "-g") == 0) { | |
| 688 | // we handled with strip = false above | |
| 689 | } else { | |
| 690 | for (size_t i = 0; i < it.other_args_len; i += 1) { | |
| 691 | clang_argv.append(it.other_args_ptr[i]); | |
| 692 | } | |
| 693 | } | |
| 694 | break; | |
| 695 | case Stage2ClangArgSanitize: | |
| 696 | if (strcmp(it.only_arg, "undefined") == 0) { | |
| 697 | want_sanitize_c = WantCSanitizeEnabled; | |
| 698 | } else { | |
| 699 | for (size_t i = 0; i < it.other_args_len; i += 1) { | |
| 700 | clang_argv.append(it.other_args_ptr[i]); | |
| 701 | } | |
| 702 | } | |
| 703 | break; | |
| 667 | 704 | } |
| 668 | 705 | } |
| 669 | 706 | // Parse linker args |
| ... | ... | @@ -715,6 +752,10 @@ static int main0(int argc, char **argv) { |
| 715 | 752 | } |
| 716 | 753 | } |
| 717 | 754 | |
| 755 | if (want_sanitize_c == WantCSanitizeEnabled && build_mode == BuildModeFastRelease) { | |
| 756 | build_mode = BuildModeSafeRelease; | |
| 757 | } | |
| 758 | ||
| 718 | 759 | if (!nostdlib && !have_libc) { |
| 719 | 760 | have_libc = true; |
| 720 | 761 | link_libs.append("c"); |
src/stage2.h+3| ... | ... | @@ -334,6 +334,9 @@ enum Stage2ClangArg { |
| 334 | 334 | Stage2ClangArgRDynamic, |
| 335 | 335 | Stage2ClangArgWL, |
| 336 | 336 | Stage2ClangArgPreprocess, |
| 337 | Stage2ClangArgOptimize, | |
| 338 | Stage2ClangArgDebug, | |
| 339 | Stage2ClangArgSanitize, | |
| 337 | 340 | }; |
| 338 | 341 | |
| 339 | 342 | // ABI warning |
tools/update_clang_options.zig+56| ... | ... | @@ -90,6 +90,62 @@ const known_options = [_]KnownOpt{ |
| 90 | 90 | .name = "assemble", |
| 91 | 91 | .ident = "driver_punt", |
| 92 | 92 | }, |
| 93 | .{ | |
| 94 | .name = "O1", | |
| 95 | .ident = "optimize", | |
| 96 | }, | |
| 97 | .{ | |
| 98 | .name = "O2", | |
| 99 | .ident = "optimize", | |
| 100 | }, | |
| 101 | .{ | |
| 102 | .name = "Og", | |
| 103 | .ident = "optimize", | |
| 104 | }, | |
| 105 | .{ | |
| 106 | .name = "O", | |
| 107 | .ident = "optimize", | |
| 108 | }, | |
| 109 | .{ | |
| 110 | .name = "Ofast", | |
| 111 | .ident = "optimize", | |
| 112 | }, | |
| 113 | .{ | |
| 114 | .name = "optimize", | |
| 115 | .ident = "optimize", | |
| 116 | }, | |
| 117 | .{ | |
| 118 | .name = "g", | |
| 119 | .ident = "debug", | |
| 120 | }, | |
| 121 | .{ | |
| 122 | .name = "debug", | |
| 123 | .ident = "debug", | |
| 124 | }, | |
| 125 | .{ | |
| 126 | .name = "g-dwarf", | |
| 127 | .ident = "debug", | |
| 128 | }, | |
| 129 | .{ | |
| 130 | .name = "g-dwarf-2", | |
| 131 | .ident = "debug", | |
| 132 | }, | |
| 133 | .{ | |
| 134 | .name = "g-dwarf-3", | |
| 135 | .ident = "debug", | |
| 136 | }, | |
| 137 | .{ | |
| 138 | .name = "g-dwarf-4", | |
| 139 | .ident = "debug", | |
| 140 | }, | |
| 141 | .{ | |
| 142 | .name = "g-dwarf-5", | |
| 143 | .ident = "debug", | |
| 144 | }, | |
| 145 | .{ | |
| 146 | .name = "fsanitize", | |
| 147 | .ident = "sanitize", | |
| 148 | }, | |
| 93 | 149 | }; |
| 94 | 150 | |
| 95 | 151 | const blacklisted_options = [_][]const u8{}; |