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(...@@ -627,7 +627,7 @@ fn exportHandler(
627 // Work around x86_64 backend limitation.627 // Work around x86_64 backend limitation.
628 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;628 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
629 const N = "__ubsan_handle_" ++ sym_name;629 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 });
631}631}
632632
633fn exportHandlerWithAbort(633fn exportHandlerWithAbort(
...@@ -639,11 +639,11 @@ fn exportHandlerWithAbort(...@@ -639,11 +639,11 @@ fn exportHandlerWithAbort(
639 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;639 const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
640 {640 {
641 const N = "__ubsan_handle_" ++ sym_name;641 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 });
643 }643 }
644 {644 {
645 const N = "__ubsan_handle_" ++ sym_name ++ "_abort";645 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 });
647 }647 }
648}648}
649649
src/Compilation.zig+8-1
...@@ -2048,7 +2048,14 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options...@@ -2048,7 +2048,14 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options
2048 break :s .none; // only LLD can handle ubsan-rt for this target2048 break :s .none; // only LLD can handle ubsan-rt for this target
2049 } else true,2049 } else true,
2050 };2050 };
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 }
2052 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm2059 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm
2053 if (is_exe_or_dyn_lib) break :s .lib;2060 if (is_exe_or_dyn_lib) break :s .lib;
2054 break :s .obj;2061 break :s .obj;