authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-25 17:07:33+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-25 17:07:33+02:00
log9924897c065af526f43c82d4b8328b5e72d100bd
tree57014d8d0c5834f0ef98c285b45218b44630ab9f
parent5d019abe4ec70373db7a75c2a8a3e2d76939817c
parent837e56431232e5257e988227dff45be6f4dececf
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24995 from alexrp/ubsan-rt-hidden

ubsan-rt: export symbols with hidden visibility

2 files changed, 11 insertions(+), 4 deletions(-)

lib/ubsan_rt.zig+3-3
......@@ -627,7 +627,7 @@ fn exportHandler(
627627 // Work around x86_64 backend limitation.
628628 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
629629 const N = "__ubsan_handle_" ++ sym_name;
630 @export(handler, .{ .name = N, .linkage = linkage });
630 @export(handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden });
631631}
632632
633633fn exportHandlerWithAbort(
......@@ -639,11 +639,11 @@ fn exportHandlerWithAbort(
639639 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
640640 {
641641 const N = "__ubsan_handle_" ++ sym_name;
642 @export(handler, .{ .name = N, .linkage = linkage });
642 @export(handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden });
643643 }
644644 {
645645 const N = "__ubsan_handle_" ++ sym_name ++ "_abort";
646 @export(abort_handler, .{ .name = N, .linkage = linkage });
646 @export(abort_handler, .{ .name = N, .linkage = linkage, .visibility = if (linkage == .internal) .default else .hidden });
647647 }
648648}
649649
src/Compilation.zig+8-1
......@@ -2048,7 +2048,14 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options
20482048 break :s .none; // only LLD can handle ubsan-rt for this target
20492049 } else true,
20502050 };
2051 if (have_zcu and (!need_llvm or use_llvm)) break :s .zcu;
2051 if (have_zcu and (!need_llvm or use_llvm)) {
2052 // ubsan-rt's exports use hidden visibility. If we're building a Windows DLL and
2053 // exported functions are going to be dllexported, LLVM will complain that
2054 // dllexported functions must use default or protected visibility. So we can't use
2055 // the ZCU strategy in this case.
2056 if (options.config.dll_export_fns) break :s .lib;
2057 break :s .zcu;
2058 }
20522059 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm
20532060 if (is_exe_or_dyn_lib) break :s .lib;
20542061 break :s .obj;