[Clang] Prevent mlink-builtin-bitcode from internalizing the RPC client (#118661)

Summary:
Currently, we only use `-mlink-builtin-bitcode` for non-LTO NVIDIA
compiliations. This has the problem that it will internalize the RPC
client symbol which needs to be visible to the host. To counteract that,
I put `retain` on it, but this also prevents optimizations on the global
itself, so the passes we have that remove the symbol don't work on
OpenMP anymore. This patch does the dumbest solution, adding a special
string check for it in clang. Not the best solution, the runner up would
be to have a clang attribute for `externally_initialized` because those
can't be internalized, but that might have some unfortunate
side-effects. Alternatively we could make NVIDIA compilations do LTO all
the time, but that would affect some users and it's harder than I
thought.
This commit is contained in:
Joseph Huber
2025-01-27 19:30:59 -06:00
committed by GitHub
parent 7873d3b50b
commit 760a786d15
2 changed files with 6 additions and 8 deletions

View File

@@ -233,6 +233,10 @@ bool InternalizePass::internalizeModule(Module &M) {
else
AlwaysPreserved.insert("__stack_chk_guard");
// Preserve the RPC interface for GPU host callbacks when internalizing.
if (Triple(M.getTargetTriple()).isNVPTX())
AlwaysPreserved.insert("__llvm_rpc_server");
// Mark all functions not in the api as internal.
IsWasm = Triple(M.getTargetTriple()).isOSBinFormatWasm();
for (Function &I : M) {

View File

@@ -105,14 +105,8 @@ void *indirectCallLookup(void *HstPtr) {
}
/// The openmp client instance used to communicate with the server.
/// FIXME: This is marked as 'retain' so that it is not removed via
/// `-mlink-builtin-bitcode`
#ifdef __NVPTX__
[[gnu::visibility("protected"), gnu::weak,
gnu::retain]] rpc::Client Client asm("__llvm_rpc_client");
#else
[[gnu::visibility("protected"), gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
#endif
[[gnu::visibility("protected"),
gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
} // namespace impl
} // namespace ompx