From 1cb994899db9cc173982ce9bce4099059e2700af Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 22 Jul 2024 13:26:07 -0700 Subject: Compilation: fix regression in addCCArgs `-fno-sanitize=function` must come after `-fsanitize=undefined` or it has no effect. --- src/Compilation.zig | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 8ef8adfa53..a0141a5dad 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5626,15 +5626,6 @@ pub fn addCCArgs( if (mod.sanitize_c) { if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix); try san_arg.appendSlice(arena, "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"); } if (mod.sanitize_thread) { if (san_arg.items.len == 0) try san_arg.appendSlice(arena, prefix); @@ -5645,7 +5636,23 @@ pub fn addCCArgs( try san_arg.appendSlice(arena, "fuzzer-no-link,"); } // Chop off the trailing comma and append to argv. - if (san_arg.popOrNull()) |_| try argv.append(san_arg.items); + if (san_arg.popOrNull()) |_| { + try argv.append(san_arg.items); + + // These args have to be added after the `-fsanitize` arg or + // they won't take effect. + if (mod.sanitize_c) { + 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"); + } + } } if (mod.red_zone) { -- cgit v1.2.3