aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-08-24 14:02:59 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-09-19 09:37:53 -0700
commit66312c0b51c43feb40892c8873f018619b8d3fed (patch)
tree1cf3d8471fe141ed4dabf3a4c260941b1d67ee5c /src/Compilation.zig
parent75b8b21cc1db3413578b5b42a39a40fb8b140da4 (diff)
downloadzig-66312c0b51c43feb40892c8873f018619b8d3fed.tar.gz
zig-66312c0b51c43feb40892c8873f018619b8d3fed.zip
clang: -fno-sanitize=function workaround
It is very common, and well-defined, for a pointer on one side of a C ABI to have a different but compatible element type. Examples include: - `char*` vs `uint8_t*` on a system with 8-bit bytes - `const char*` vs `char*` - `char*` vs `unsigned char*` Without this flag, Clang would invoke UBSAN when such an extern function was called. Might be nice to file an upstream issue and find out if there is a more precise way to disable the problematic check. `-fsanitize-cfi-icall-generalize-pointers` looks promising according to the documentation, but empirically it does not work.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index d6157fec82..177c71f4d1 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -4457,9 +4457,18 @@ pub fn addCCArgs(
if (comp.sanitize_c and !comp.bin_file.options.tsan) {
try argv.append("-fsanitize=undefined");
try argv.append("-fsanitize-trap=undefined");
+ // It is very common, and well-defined, for a pointer on one side of a C ABI
+ // to have a different but compatible element type. Examples include:
+ // `char*` vs `uint8_t*` on a system with 8-bit bytes
+ // `const char*` vs `char*`
+ // `char*` vs `unsigned char*`
+ // Without this flag, Clang would invoke UBSAN when such an extern
+ // function was called.
+ try argv.append("-fno-sanitize=function");
} else if (comp.sanitize_c and comp.bin_file.options.tsan) {
try argv.append("-fsanitize=undefined,thread");
try argv.append("-fsanitize-trap=undefined");
+ try argv.append("-fno-sanitize=function");
} else if (!comp.sanitize_c and comp.bin_file.options.tsan) {
try argv.append("-fsanitize=thread");
}