From 0f7b43e9c70a1fd4c8a525f72caca0a4247ce434 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 24 Apr 2026 09:51:58 -0700 Subject: [PATCH] build: always disable ubsan with no libc --- src/build/SharedDeps.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/build/SharedDeps.zig b/src/build/SharedDeps.zig index 2d6dce1c2..eac28ec3d 100644 --- a/src/build/SharedDeps.zig +++ b/src/build/SharedDeps.zig @@ -869,14 +869,16 @@ pub fn addSimd( (b.lazyImport(@import("../../build.zig"), "simdutf") orelse unreachable).noLibcFlags(), ); - // Disable ubsan for Windows C/C++ objects to avoid undefined - // __ubsan_handle_* references. The Zig libraries on Windows don't - // currently bundle a matching UBSan runtime for these objects in - // our build configurations (this affects both MSVC and GNU ABIs). - if (target.result.os.tag == .windows) try flags.appendSlice(b.allocator, &.{ - "-fno-sanitize=undefined", - "-fno-sanitize-trap=undefined", - }); + // Disable ubsan for C/C++ objects when there is no libc (or on + // Windows) to avoid undefined __ubsan_handle_* references. Debug- + // mode compiles emit these calls and there is no matching UBSan + // runtime available in these configurations. + if (simd_libc == .no_libc or target.result.os.tag == .windows) { + try flags.appendSlice(b.allocator, &.{ + "-fno-sanitize=undefined", + "-fno-sanitize-trap=undefined", + }); + } // SIMD C++ files if (simd_libc == .no_libc) {