authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-16 02:44:55+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-26 22:54:34+02:00
logb3537d0f4adeff824348a4918b495976ae230731
tree4635a2febd416352452e5b909afad138db43b601
parent23440fbb99a501fac9cfb6af85c6303732cf0b06

compiler: Allow configuring UBSan mode at the module level.

* Accept -fsanitize-c=trap|full in addition to the existing form. * Accept -f(no-)sanitize-trap=undefined in zig cc. * Change type of std.Build.Module.sanitize_c to std.zig.SanitizeC. * Add some missing Compilation.Config fields to the cache. Closes #23216.

15 files changed, 176 insertions(+), 57 deletions(-)

lib/std/Build/Module.zig+8-3
......@@ -22,7 +22,7 @@ unwind_tables: ?std.builtin.UnwindTables,
2222single_threaded: ?bool,
2323stack_protector: ?bool,
2424stack_check: ?bool,
25sanitize_c: ?bool,
25sanitize_c: ?std.zig.SanitizeC,
2626sanitize_thread: ?bool,
2727fuzz: ?bool,
2828code_model: std.builtin.CodeModel,
......@@ -256,7 +256,7 @@ pub const CreateOptions = struct {
256256 code_model: std.builtin.CodeModel = .default,
257257 stack_protector: ?bool = null,
258258 stack_check: ?bool = null,
259 sanitize_c: ?bool = null,
259 sanitize_c: ?std.zig.SanitizeC = null,
260260 sanitize_thread: ?bool = null,
261261 fuzz: ?bool = null,
262262 /// Whether to emit machine code that integrates with Valgrind.
......@@ -559,13 +559,18 @@ pub fn appendZigProcessFlags(
559559 try addFlag(zig_args, m.stack_protector, "-fstack-protector", "-fno-stack-protector");
560560 try addFlag(zig_args, m.omit_frame_pointer, "-fomit-frame-pointer", "-fno-omit-frame-pointer");
561561 try addFlag(zig_args, m.error_tracing, "-ferror-tracing", "-fno-error-tracing");
562 try addFlag(zig_args, m.sanitize_c, "-fsanitize-c", "-fno-sanitize-c");
563562 try addFlag(zig_args, m.sanitize_thread, "-fsanitize-thread", "-fno-sanitize-thread");
564563 try addFlag(zig_args, m.fuzz, "-ffuzz", "-fno-fuzz");
565564 try addFlag(zig_args, m.valgrind, "-fvalgrind", "-fno-valgrind");
566565 try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC");
567566 try addFlag(zig_args, m.red_zone, "-mred-zone", "-mno-red-zone");
568567
568 if (m.sanitize_c) |sc| switch (sc) {
569 .off => try zig_args.append("-fno-sanitize-c"),
570 .trap => try zig_args.append("-fsanitize-c=trap"),
571 .full => try zig_args.append("-fsanitize-c=full"),
572 };
573
569574 if (m.dwarf_format) |dwarf_format| {
570575 try zig_args.append(switch (dwarf_format) {
571576 .@"32" => "-gdwarf32",
lib/std/zig.zig+6
......@@ -236,6 +236,12 @@ pub fn binNameAlloc(allocator: Allocator, options: BinNameOptions) error{OutOfMe
236236 }
237237}
238238
239pub const SanitizeC = enum {
240 off,
241 trap,
242 full,
243};
244
239245pub const BuildId = union(enum) {
240246 none,
241247 fast,
src/Compilation.zig+35-28
......@@ -1287,7 +1287,14 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
12871287 const any_unwind_tables = options.config.any_unwind_tables or options.root_mod.unwind_tables != .none;
12881288 const any_non_single_threaded = options.config.any_non_single_threaded or !options.root_mod.single_threaded;
12891289 const any_sanitize_thread = options.config.any_sanitize_thread or options.root_mod.sanitize_thread;
1290 const any_sanitize_c = options.config.any_sanitize_c or options.root_mod.sanitize_c;
1290 const any_sanitize_c: std.zig.SanitizeC = switch (options.config.any_sanitize_c) {
1291 .off => options.root_mod.sanitize_c,
1292 .trap => if (options.root_mod.sanitize_c == .full)
1293 .full
1294 else
1295 .trap,
1296 .full => .full,
1297 };
12911298 const any_fuzz = options.config.any_fuzz or options.root_mod.fuzz;
12921299
12931300 const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables;
......@@ -1346,7 +1353,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
13461353 // and this reduces unnecessary bloat.
13471354 const ubsan_rt_strat: RtStrat = s: {
13481355 const is_spirv = options.root_mod.resolved_target.result.cpu.arch.isSpirV();
1349 const want_ubsan_rt = options.want_ubsan_rt orelse (!is_spirv and any_sanitize_c and is_exe_or_dyn_lib);
1356 const want_ubsan_rt = options.want_ubsan_rt orelse (!is_spirv and any_sanitize_c == .full and is_exe_or_dyn_lib);
13501357 if (!want_ubsan_rt) break :s .none;
13511358 if (options.skip_linker_dependencies) break :s .none;
13521359 if (have_zcu) break :s .zcu;
......@@ -1418,6 +1425,10 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14181425 cache.hash.add(options.config.lto);
14191426 cache.hash.add(options.config.link_mode);
14201427 cache.hash.add(options.config.any_unwind_tables);
1428 cache.hash.add(options.config.any_non_single_threaded);
1429 cache.hash.add(options.config.any_sanitize_thread);
1430 cache.hash.add(options.config.any_sanitize_c);
1431 cache.hash.add(options.config.any_fuzz);
14211432 cache.hash.add(options.function_sections);
14221433 cache.hash.add(options.data_sections);
14231434 cache.hash.add(link_libc);
......@@ -6048,7 +6059,7 @@ pub fn addCCArgs(
60486059 {
60496060 var san_arg: std.ArrayListUnmanaged(u8) = .empty;
60506061 const prefix = "-fsanitize=";
6051 if (mod.sanitize_c) {
6062 if (mod.sanitize_c != .off) {
60526063 if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);
60536064 try san_arg.appendSlice(arena, "undefined,");
60546065 }
......@@ -6064,37 +6075,33 @@ pub fn addCCArgs(
60646075 if (san_arg.pop()) |_| {
60656076 try argv.append(san_arg.items);
60666077
6067 // These args have to be added after the `-fsanitize` arg or
6068 // they won't take effect.
6069 if (mod.sanitize_c) {
6070 // This check requires implementing the Itanium C++ ABI.
6071 // We would make it `-fsanitize-trap=vptr`, however this check requires
6072 // a full runtime due to the type hashing involved.
6073 try argv.append("-fno-sanitize=vptr");
6074
6075 // It is very common, and well-defined, for a pointer on one side of a C ABI
6076 // to have a different but compatible element type. Examples include:
6077 // `char*` vs `uint8_t*` on a system with 8-bit bytes
6078 // `const char*` vs `char*`
6079 // `char*` vs `unsigned char*`
6080 // Without this flag, Clang would invoke UBSAN when such an extern
6081 // function was called.
6082 try argv.append("-fno-sanitize=function");
6083
6084 if (mod.optimize_mode == .ReleaseSafe) {
6085 // It's recommended to use the minimal runtime in production
6086 // environments due to the security implications of the full runtime.
6087 // The minimal runtime doesn't provide much benefit over simply
6088 // trapping, however, so we do that instead.
6078 switch (mod.sanitize_c) {
6079 .off => {},
6080 .trap => {
60896081 try argv.append("-fsanitize-trap=undefined");
6090 } else {
6082 },
6083 .full => {
6084 // This check requires implementing the Itanium C++ ABI.
6085 // We would make it `-fsanitize-trap=vptr`, however this check requires
6086 // a full runtime due to the type hashing involved.
6087 try argv.append("-fno-sanitize=vptr");
6088
6089 // It is very common, and well-defined, for a pointer on one side of a C ABI
6090 // to have a different but compatible element type. Examples include:
6091 // `char*` vs `uint8_t*` on a system with 8-bit bytes
6092 // `const char*` vs `char*`
6093 // `char*` vs `unsigned char*`
6094 // Without this flag, Clang would invoke UBSAN when such an extern
6095 // function was called.
6096 try argv.append("-fno-sanitize=function");
6097
60916098 // This is necessary because, by default, Clang instructs LLVM to embed
60926099 // a COFF link dependency on `libclang_rt.ubsan_standalone.a` when the
60936100 // UBSan runtime is used.
60946101 if (target.os.tag == .windows) {
60956102 try argv.append("-fno-rtlib-defaultlib");
60966103 }
6097 }
6104 },
60986105 }
60996106 }
61006107
......@@ -6797,7 +6804,7 @@ pub fn build_crt_file(
67976804 .strip = comp.compilerRtStrip(),
67986805 .stack_check = false,
67996806 .stack_protector = 0,
6800 .sanitize_c = false,
6807 .sanitize_c = .off,
68016808 .sanitize_thread = false,
68026809 .red_zone = comp.root_mod.red_zone,
68036810 // Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer.
src/Compilation/Config.zig+2-2
......@@ -32,7 +32,7 @@ any_non_single_threaded: bool,
3232/// per-Module setting.
3333any_error_tracing: bool,
3434any_sanitize_thread: bool,
35any_sanitize_c: bool,
35any_sanitize_c: std.zig.SanitizeC,
3636any_fuzz: bool,
3737pie: bool,
3838/// If this is true then linker code is responsible for making an LLVM IR
......@@ -86,7 +86,7 @@ pub const Options = struct {
8686 ensure_libcpp_on_non_freestanding: bool = false,
8787 any_non_single_threaded: bool = false,
8888 any_sanitize_thread: bool = false,
89 any_sanitize_c: bool = false,
89 any_sanitize_c: std.zig.SanitizeC = .off,
9090 any_fuzz: bool = false,
9191 any_unwind_tables: bool = false,
9292 any_dyn_libs: bool = false,
src/Package/Module.zig+13-4
......@@ -24,7 +24,7 @@ omit_frame_pointer: bool,
2424stack_check: bool,
2525stack_protector: u32,
2626red_zone: bool,
27sanitize_c: bool,
27sanitize_c: std.zig.SanitizeC,
2828sanitize_thread: bool,
2929fuzz: bool,
3030unwind_tables: std.builtin.UnwindTables,
......@@ -92,7 +92,7 @@ pub const CreateOptions = struct {
9292 stack_protector: ?u32 = null,
9393 red_zone: ?bool = null,
9494 unwind_tables: ?std.builtin.UnwindTables = null,
95 sanitize_c: ?bool = null,
95 sanitize_c: ?std.zig.SanitizeC = null,
9696 sanitize_thread: ?bool = null,
9797 fuzz: ?bool = null,
9898 structured_cfg: ?bool = null,
......@@ -113,6 +113,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
113113 if (options.inherited.fuzz == true) assert(options.global.any_fuzz);
114114 if (options.inherited.single_threaded == false) assert(options.global.any_non_single_threaded);
115115 if (options.inherited.unwind_tables) |uwt| if (uwt != .none) assert(options.global.any_unwind_tables);
116 if (options.inherited.sanitize_c) |sc| if (sc != .off) assert(options.global.any_sanitize_c != .off);
116117 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing);
117118
118119 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target;
......@@ -249,10 +250,18 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
249250 .ReleaseFast, .ReleaseSmall => false,
250251 };
251252
252 const sanitize_c = b: {
253 const sanitize_c: std.zig.SanitizeC = b: {
253254 if (options.inherited.sanitize_c) |x| break :b x;
254255 if (options.parent) |p| break :b p.sanitize_c;
255 break :b is_safe_mode;
256 break :b switch (optimize_mode) {
257 .Debug => .full,
258 // It's recommended to use the minimal runtime in production
259 // environments due to the security implications of the full runtime.
260 // The minimal runtime doesn't provide much benefit over simply
261 // trapping, however, so we do that instead.
262 .ReleaseSafe => .trap,
263 .ReleaseFast, .ReleaseSmall => .off,
264 };
256265 };
257266
258267 const stack_check = b: {
src/clang_options_data.zig+18-4
......@@ -3682,7 +3682,14 @@ flagpd1("fno-sanitize-stats"),
36823682flagpd1("fno-sanitize-thread-atomics"),
36833683flagpd1("fno-sanitize-thread-func-entry-exit"),
36843684flagpd1("fno-sanitize-thread-memory-access"),
3685flagpd1("fno-sanitize-trap"),
3685.{
3686 .name = "fno-sanitize-trap",
3687 .syntax = .flag,
3688 .zig_equivalent = .no_sanitize_trap,
3689 .pd1 = true,
3690 .pd2 = false,
3691 .psl = false,
3692},
36863693flagpd1("fno-sanitize-undefined-trap-on-error"),
36873694flagpd1("fno-save-main-program"),
36883695flagpd1("fno-save-optimization-record"),
......@@ -4024,7 +4031,14 @@ flagpd1("fsanitize-stats"),
40244031flagpd1("fsanitize-thread-atomics"),
40254032flagpd1("fsanitize-thread-func-entry-exit"),
40264033flagpd1("fsanitize-thread-memory-access"),
4027flagpd1("fsanitize-trap"),
4034.{
4035 .name = "fsanitize-trap",
4036 .syntax = .flag,
4037 .zig_equivalent = .sanitize_trap,
4038 .pd1 = true,
4039 .pd2 = false,
4040 .psl = false,
4041},
40284042flagpd1("fsanitize-undefined-trap-on-error"),
40294043flagpd1("fsave-main-program"),
40304044flagpd1("fsave-optimization-record"),
......@@ -6592,7 +6606,7 @@ joinpd1("fmacro-prefix-map="),
65926606.{
65936607 .name = "fno-sanitize-trap=",
65946608 .syntax = .comma_joined,
6595 .zig_equivalent = .other,
6609 .zig_equivalent = .no_sanitize_trap,
65966610 .pd1 = true,
65976611 .pd2 = false,
65986612 .psl = false,
......@@ -6864,7 +6878,7 @@ joinpd1("frecord-marker="),
68646878.{
68656879 .name = "fsanitize-trap=",
68666880 .syntax = .comma_joined,
6867 .zig_equivalent = .other,
6881 .zig_equivalent = .sanitize_trap,
68686882 .pd1 = true,
68696883 .pd2 = false,
68706884 .psl = false,
src/glibc.zig+1-1
......@@ -1231,7 +1231,7 @@ fn buildSharedLib(
12311231 .strip = strip,
12321232 .stack_check = false,
12331233 .stack_protector = 0,
1234 .sanitize_c = false,
1234 .sanitize_c = .off,
12351235 .sanitize_thread = false,
12361236 .red_zone = comp.root_mod.red_zone,
12371237 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
src/libcxx.zig+2-2
......@@ -182,7 +182,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
182182 .strip = strip,
183183 .stack_check = false,
184184 .stack_protector = 0,
185 .sanitize_c = false,
185 .sanitize_c = .off,
186186 .sanitize_thread = comp.config.any_sanitize_thread,
187187 .red_zone = comp.root_mod.red_zone,
188188 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
......@@ -396,7 +396,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
396396 .strip = strip,
397397 .stack_check = false,
398398 .stack_protector = 0,
399 .sanitize_c = false,
399 .sanitize_c = .off,
400400 .sanitize_thread = comp.config.any_sanitize_thread,
401401 .red_zone = comp.root_mod.red_zone,
402402 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
src/libtsan.zig+1-1
......@@ -95,7 +95,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
9595 .strip = strip,
9696 .stack_check = false,
9797 .stack_protector = 0,
98 .sanitize_c = false,
98 .sanitize_c = .off,
9999 .sanitize_thread = false,
100100 .red_zone = comp.root_mod.red_zone,
101101 .omit_frame_pointer = optimize_mode != .Debug and !target.os.tag.isDarwin(),
src/libunwind.zig+1-1
......@@ -64,7 +64,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
6464 .red_zone = comp.root_mod.red_zone,
6565 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
6666 .valgrind = false,
67 .sanitize_c = false,
67 .sanitize_c = .off,
6868 .sanitize_thread = false,
6969 // necessary so that libunwind can unwind through its own stack frames
7070 // The old 32-bit x86 variant of SEH doesn't use tables.
src/main.zig+75-5
......@@ -526,7 +526,9 @@ const usage_build_generic =
526526 \\ -fno-stack-protector Disable stack protection in safe builds
527527 \\ -fvalgrind Include valgrind client requests in release builds
528528 \\ -fno-valgrind Omit valgrind client requests in debug builds
529 \\ -fsanitize-c Enable C undefined behavior detection in unsafe builds
529 \\ -fsanitize-c[=mode] Enable C undefined behavior detection in unsafe builds
530 \\ trap Insert trap instructions on undefined behavior
531 \\ full (Default) Insert runtime calls on undefined behavior
530532 \\ -fno-sanitize-c Disable C undefined behavior detection in safe builds
531533 \\ -fsanitize-thread Enable Thread Sanitizer
532534 \\ -fno-sanitize-thread Disable Thread Sanitizer
......@@ -1464,9 +1466,18 @@ fn buildOutputType(
14641466 } else if (mem.eql(u8, arg, "-fno-omit-frame-pointer")) {
14651467 mod_opts.omit_frame_pointer = false;
14661468 } else if (mem.eql(u8, arg, "-fsanitize-c")) {
1467 mod_opts.sanitize_c = true;
1469 mod_opts.sanitize_c = .full;
1470 } else if (mem.startsWith(u8, arg, "-fsanitize-c=")) {
1471 const mode = arg["-fsanitize-c=".len..];
1472 if (mem.eql(u8, mode, "trap")) {
1473 mod_opts.sanitize_c = .trap;
1474 } else if (mem.eql(u8, mode, "full")) {
1475 mod_opts.sanitize_c = .full;
1476 } else {
1477 fatal("Invalid -fsanitize-c mode: '{s}'. Must be 'trap' or 'full'.", .{mode});
1478 }
14681479 } else if (mem.eql(u8, arg, "-fno-sanitize-c")) {
1469 mod_opts.sanitize_c = false;
1480 mod_opts.sanitize_c = .off;
14701481 } else if (mem.eql(u8, arg, "-fvalgrind")) {
14711482 mod_opts.valgrind = true;
14721483 } else if (mem.eql(u8, arg, "-fno-valgrind")) {
......@@ -2236,7 +2247,7 @@ fn buildOutputType(
22362247 var recognized_any = false;
22372248 while (san_it.next()) |sub_arg| {
22382249 if (mem.eql(u8, sub_arg, "undefined")) {
2239 mod_opts.sanitize_c = enable;
2250 mod_opts.sanitize_c = if (enable) .full else .off;
22402251 recognized_any = true;
22412252 } else if (mem.eql(u8, sub_arg, "thread")) {
22422253 mod_opts.sanitize_thread = enable;
......@@ -2250,6 +2261,49 @@ fn buildOutputType(
22502261 try cc_argv.appendSlice(arena, it.other_args);
22512262 }
22522263 },
2264 .sanitize_trap, .no_sanitize_trap => |t| {
2265 const enable = t == .sanitize_trap;
2266 var san_it = std.mem.splitScalar(u8, it.only_arg, ',');
2267 var recognized_any = false;
2268 while (san_it.next()) |sub_arg| {
2269 // This logic doesn't match Clang 1:1, but it's probably good enough, and avoids
2270 // significantly complicating the resolution of the options.
2271 if (mem.eql(u8, sub_arg, "undefined")) {
2272 if (mod_opts.sanitize_c) |sc| switch (sc) {
2273 .off => if (enable) {
2274 mod_opts.sanitize_c = .trap;
2275 },
2276 .trap => if (!enable) {
2277 mod_opts.sanitize_c = .full;
2278 },
2279 .full => if (enable) {
2280 mod_opts.sanitize_c = .trap;
2281 },
2282 } else {
2283 if (enable) {
2284 mod_opts.sanitize_c = .trap;
2285 } else {
2286 // This means we were passed `-fno-sanitize-trap=undefined` and nothing else. In
2287 // this case, ideally, we should use whatever value `sanitize_c` resolves to by
2288 // default, except change `trap` to `full`. However, we don't yet know what
2289 // `sanitize_c` will resolve to! So we either have to pick `off` or `full`.
2290 //
2291 // `full` has the potential to be problematic if `optimize_mode` turns out to
2292 // be `ReleaseFast`/`ReleaseSmall` because the user will get a slower and larger
2293 // binary than expected. On the other hand, if `optimize_mode` turns out to be
2294 // `Debug`/`ReleaseSafe`, `off` would mean UBSan would unexpectedly be disabled.
2295 //
2296 // `off` seems very slightly less bad, so let's go with that.
2297 mod_opts.sanitize_c = .off;
2298 }
2299 }
2300 recognized_any = true;
2301 }
2302 }
2303 if (!recognized_any) {
2304 try cc_argv.appendSlice(arena, it.other_args);
2305 }
2306 },
22532307 .linker_script => linker_script = it.only_arg,
22542308 .verbose => {
22552309 verbose_link = true;
......@@ -2766,7 +2820,7 @@ fn buildOutputType(
27662820 }
27672821
27682822 if (mod_opts.sanitize_c) |wsc| {
2769 if (wsc and mod_opts.optimize_mode == .ReleaseFast) {
2823 if (wsc != .off and mod_opts.optimize_mode == .ReleaseFast) {
27702824 mod_opts.optimize_mode = .ReleaseSafe;
27712825 }
27722826 }
......@@ -2915,6 +2969,13 @@ fn buildOutputType(
29152969 create_module.opts.any_non_single_threaded = true;
29162970 if (mod_opts.sanitize_thread == true)
29172971 create_module.opts.any_sanitize_thread = true;
2972 if (mod_opts.sanitize_c) |sc| switch (sc) {
2973 .off => {},
2974 .trap => if (create_module.opts.any_sanitize_c == .off) {
2975 create_module.opts.any_sanitize_c = .trap;
2976 },
2977 .full => create_module.opts.any_sanitize_c = .full,
2978 };
29182979 if (mod_opts.fuzz == true)
29192980 create_module.opts.any_fuzz = true;
29202981 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
......@@ -5941,6 +6002,8 @@ pub const ClangArgIterator = struct {
59416002 gdwarf64,
59426003 sanitize,
59436004 no_sanitize,
6005 sanitize_trap,
6006 no_sanitize_trap,
59446007 linker_script,
59456008 dry_run,
59466009 verbose,
......@@ -7728,6 +7791,13 @@ fn handleModArg(
77287791 create_module.opts.any_non_single_threaded = true;
77297792 if (mod_opts.sanitize_thread == true)
77307793 create_module.opts.any_sanitize_thread = true;
7794 if (mod_opts.sanitize_c) |sc| switch (sc) {
7795 .off => {},
7796 .trap => if (create_module.opts.any_sanitize_c == .off) {
7797 create_module.opts.any_sanitize_c = .trap;
7798 },
7799 .full => create_module.opts.any_sanitize_c = .full,
7800 };
77317801 if (mod_opts.fuzz == true)
77327802 create_module.opts.any_fuzz = true;
77337803 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
src/musl.zig+1-1
......@@ -231,7 +231,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
231231 .strip = strip,
232232 .stack_check = false,
233233 .stack_protector = 0,
234 .sanitize_c = false,
234 .sanitize_c = .off,
235235 .sanitize_thread = false,
236236 .red_zone = comp.root_mod.red_zone,
237237 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
test/link/elf.zig+2-2
......@@ -2052,7 +2052,7 @@ fn testLargeBss(b: *Build, opts: Options) *Step {
20522052 exe.linkLibC();
20532053 // Disabled to work around the ELF linker crashing.
20542054 // Can be reproduced on a x86_64-linux host by commenting out the line below.
2055 exe.root_module.sanitize_c = false;
2055 exe.root_module.sanitize_c = .off;
20562056
20572057 const run = addRunArtifact(exe);
20582058 run.expectExitCode(0);
......@@ -3558,7 +3558,7 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
35583558 exe.linkLibC();
35593559 // Disabled to work around the ELF linker crashing.
35603560 // Can be reproduced on a x86_64-linux host by commenting out the line below.
3561 exe.root_module.sanitize_c = false;
3561 exe.root_module.sanitize_c = .off;
35623562
35633563 const run = addRunArtifact(exe);
35643564 run.expectStdOutEqual("3 0 5 0 0 0\n");
test/link/glibc_compat/build.zig+3-3
......@@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void {
2525 // We disable UBSAN for these tests as the libc being tested here is
2626 // so old, it doesn't even support compiling our UBSAN implementation.
2727 exe.bundle_ubsan_rt = false;
28 exe.root_module.sanitize_c = false;
28 exe.root_module.sanitize_c = .off;
2929 exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
3030 // TODO: actually test the output
3131 _ = exe.getEmittedBin();
......@@ -69,7 +69,7 @@ pub fn build(b: *std.Build) void {
6969 // We disable UBSAN for these tests as the libc being tested here is
7070 // so old, it doesn't even support compiling our UBSAN implementation.
7171 exe.bundle_ubsan_rt = false;
72 exe.root_module.sanitize_c = false;
72 exe.root_module.sanitize_c = .off;
7373 exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
7474
7575 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
......@@ -172,7 +172,7 @@ pub fn build(b: *std.Build) void {
172172 // We disable UBSAN for these tests as the libc being tested here is
173173 // so old, it doesn't even support compiling our UBSAN implementation.
174174 exe.bundle_ubsan_rt = false;
175 exe.root_module.sanitize_c = false;
175 exe.root_module.sanitize_c = .off;
176176
177177 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
178178 // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453
tools/update_clang_options.zig+8
......@@ -288,6 +288,14 @@ const known_options = [_]KnownOpt{
288288 .name = "fno-sanitize",
289289 .ident = "no_sanitize",
290290 },
291 .{
292 .name = "fsanitize-trap",
293 .ident = "sanitize_trap",
294 },
295 .{
296 .name = "fno-sanitize-trap",
297 .ident = "no_sanitize_trap",
298 },
291299 .{
292300 .name = "T",
293301 .ident = "linker_script",