From 1ce057f0535f3a0a57cb5c9ed34d3b7fecfb967c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Mar 2026 10:52:21 -0700 Subject: [PATCH] build: disable ubsan and bundled runtimes for MSVC targets Zig's ubsan instrumentation emits ELF-style /exclude-symbols linker directives into the compiled object files, causing LNK4229 warnings with the MSVC linker. The bundled compiler_rt also produces COMDAT sections that are incompatible with MSVC, causing fatal LNK1143. Disable sanitize_c entirely on the root module for MSVC targets and skip bundling both compiler_rt and ubsan_rt since MSVC provides its own runtime. --- src/build/GhosttyLibVt.zig | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/build/GhosttyLibVt.zig b/src/build/GhosttyLibVt.zig index a574bbf0c..cc27557d3 100644 --- a/src/build/GhosttyLibVt.zig +++ b/src/build/GhosttyLibVt.zig @@ -94,25 +94,28 @@ fn initLib( ); if (kind == .static) { - const is_msvc_abi = target.result.abi == .msvc; - // These must be bundled since we're compiling into a static lib. // Otherwise, you get undefined symbol errors. This could cause // problems if you're linking multiple static Zig libraries but // we'll cross that bridge when we get to it. - // - // On MSVC targets, the MSVC runtime provides these, and Zig's - // bundled versions produce object files with ELF-style linker - // directives (e.g. /exclude-symbols) and COMDAT sections that - // are incompatible with the MSVC linker (LNK1143, LNK4229). - lib.bundle_compiler_rt = !is_msvc_abi; - lib.bundle_ubsan_rt = !is_msvc_abi; + lib.bundle_compiler_rt = true; + lib.bundle_ubsan_rt = true; // Enable PIC so the static library can be linked into PIE // executables, which is the default on most Linux distributions. lib.root_module.pic = true; } + if (target.result.os.tag == .windows) { + // Zig's ubsan emits /exclude-symbols linker directives and + // its compiler_rt produces COMDAT sections that are + // incompatible with the MSVC linker (LNK1143, LNK4229). + // Skip bundling these runtimes on Windows since consumers + // link against the MSVC runtime. + lib.bundle_compiler_rt = false; + lib.bundle_ubsan_rt = false; + } + if (lib.rootModuleTarget().abi.isAndroid()) { // Support 16kb page sizes, required for Android 15+. lib.link_z_max_page_size = 16384; // 16kb