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

ubsan-rt: export symbols with hidden visibility
This commit is contained in:
Alex Rønne Petersen 2025-08-25 17:07:33 +02:00 committed by GitHub
commit 9924897c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -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 });
}
}

View File

@ -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;