From bed8171d4e41a2bb6759c96076f957920e039bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 25 Aug 2025 03:50:18 +0200 Subject: [PATCH 1/2] ubsan-rt: export symbols with hidden visibility see 092352ec63d3a4e9ff59a5d8ad8f119bf0eda468 --- lib/ubsan_rt.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ubsan_rt.zig b/lib/ubsan_rt.zig index 63f1d466cb..ffca7eff28 100644 --- a/lib/ubsan_rt.zig +++ b/lib/ubsan_rt.zig @@ -627,7 +627,7 @@ fn exportHandler( // Work around x86_64 backend limitation. const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak; const N = "__ubsan_handle_" ++ sym_name; - @export(handler, .{ .name = N, .linkage = linkage }); + @export(handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden }); } fn exportHandlerWithAbort( @@ -639,11 +639,11 @@ fn exportHandlerWithAbort( const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak; { const N = "__ubsan_handle_" ++ sym_name; - @export(handler, .{ .name = N, .linkage = linkage }); + @export(handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden }); } { const N = "__ubsan_handle_" ++ sym_name ++ "_abort"; - @export(abort_handler, .{ .name = N, .linkage = linkage }); + @export(abort_handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden }); } } From 837e56431232e5257e988227dff45be6f4dececf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 25 Aug 2025 06:45:00 +0200 Subject: [PATCH 2/2] Compilation: avoid ZCU strategy for ubsan-rt in Windows DLLs --- src/Compilation.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index db15eee954..20bd820d10 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2048,7 +2048,14 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options break :s .none; // only LLD can handle ubsan-rt for this target } else true, }; - if (have_zcu and (!need_llvm or use_llvm)) break :s .zcu; + if (have_zcu and (!need_llvm or use_llvm)) { + // ubsan-rt's exports use hidden visibility. If we're building a Windows DLL and + // exported functions are going to be dllexported, LLVM will complain that + // dllexported functions must use default or protected visibility. So we can't use + // the ZCU strategy in this case. + if (options.config.dll_export_fns) break :s .lib; + break :s .zcu; + } if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm if (is_exe_or_dyn_lib) break :s .lib; break :s .obj;