Skip to content

Commit 3c6ac5e

Browse files
committed
Compilation: fix regression in addCCArgs
`-fno-sanitize=function` must come after `-fsanitize=undefined` or it has no effect.
1 parent 84ca719 commit 3c6ac5e

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Compilation.zig

+17-10
Original file line numberDiff line numberDiff line change
@@ -5626,15 +5626,6 @@ pub fn addCCArgs(
56265626
if (mod.sanitize_c) {
56275627
if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);
56285628
try san_arg.appendSlice(arena, "undefined,");
5629-
try argv.append("-fsanitize-trap=undefined");
5630-
// It is very common, and well-defined, for a pointer on one side of a C ABI
5631-
// to have a different but compatible element type. Examples include:
5632-
// `char*` vs `uint8_t*` on a system with 8-bit bytes
5633-
// `const char*` vs `char*`
5634-
// `char*` vs `unsigned char*`
5635-
// Without this flag, Clang would invoke UBSAN when such an extern
5636-
// function was called.
5637-
try argv.append("-fno-sanitize=function");
56385629
}
56395630
if (mod.sanitize_thread) {
56405631
if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);
@@ -5645,7 +5636,23 @@ pub fn addCCArgs(
56455636
try san_arg.appendSlice(arena, "fuzzer-no-link,");
56465637
}
56475638
// Chop off the trailing comma and append to argv.
5648-
if (san_arg.popOrNull()) |_| try argv.append(san_arg.items);
5639+
if (san_arg.popOrNull()) |_| {
5640+
try argv.append(san_arg.items);
5641+
5642+
// These args have to be added after the `-fsanitize` arg or
5643+
// they won't take effect.
5644+
if (mod.sanitize_c) {
5645+
try argv.append("-fsanitize-trap=undefined");
5646+
// It is very common, and well-defined, for a pointer on one side of a C ABI
5647+
// to have a different but compatible element type. Examples include:
5648+
// `char*` vs `uint8_t*` on a system with 8-bit bytes
5649+
// `const char*` vs `char*`
5650+
// `char*` vs `unsigned char*`
5651+
// Without this flag, Clang would invoke UBSAN when such an extern
5652+
// function was called.
5653+
try argv.append("-fno-sanitize=function");
5654+
}
5655+
}
56495656
}
56505657

56515658
if (mod.red_zone) {

0 commit comments

Comments
 (0)