authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-22 13:26:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-22 14:26:17-07:00
log1cb994899db9cc173982ce9bce4099059e2700af
treeb7595b0e117580dd6683923b06c89b54b4848f25
parentae09f9bbce52e7221b889dbb479aca9acec4085b

Compilation: fix regression in addCCArgs

`-fno-sanitize=function` must come after `-fsanitize=undefined` or it has no effect.

1 files changed, 17 insertions(+), 10 deletions(-)

src/Compilation.zig+17-10
...@@ -5626,15 +5626,6 @@ pub fn addCCArgs(...@@ -5626,15 +5626,6 @@ pub fn addCCArgs(
5626 if (mod.sanitize_c) {5626 if (mod.sanitize_c) {
5627 if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);5627 if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);
5628 try san_arg.appendSlice(arena, "undefined,");5628 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");
5638 }5629 }
5639 if (mod.sanitize_thread) {5630 if (mod.sanitize_thread) {
5640 if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);5631 if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix);
...@@ -5645,7 +5636,23 @@ pub fn addCCArgs(...@@ -5645,7 +5636,23 @@ pub fn addCCArgs(
5645 try san_arg.appendSlice(arena, "fuzzer-no-link,");5636 try san_arg.appendSlice(arena, "fuzzer-no-link,");
5646 }5637 }
5647 // Chop off the trailing comma and append to argv.5638 // 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 }
5649 }5656 }
56505657
5651 if (mod.red_zone) {5658 if (mod.red_zone) {