[llvm] [Clang] Prevent `mlink-builtin-bitcode` from internalizing the RPC client (PR #118661)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 8 16:06:12 PST 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/118661
>From 3df20f04ea50100fdfcf8a4452849c3dde267b7e Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 4 Dec 2024 10:10:11 -0600
Subject: [PATCH] [Clang] Prevent `mlink-builtin-bitcode` from internalizing
the RPC client
Summary:
Currently, we only use `-mmlink-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 habe a clang attribute for `externally_inititliazed` 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.
---
llvm/lib/Transforms/IPO/Internalize.cpp | 2 ++
offload/DeviceRTL/src/Misc.cpp | 6 ++----
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/Internalize.cpp b/llvm/lib/Transforms/IPO/Internalize.cpp
index 4cdd1fa6110627..7935cc08a3d071 100644
--- a/llvm/lib/Transforms/IPO/Internalize.cpp
+++ b/llvm/lib/Transforms/IPO/Internalize.cpp
@@ -232,6 +232,8 @@ bool InternalizePass::internalizeModule(Module &M) {
AlwaysPreserved.insert("__ssp_canary_word");
else
AlwaysPreserved.insert("__stack_chk_guard");
+ // For GPU host callbacks.
+ AlwaysPreserved.insert("__llvm_rpc_server");
// Mark all functions not in the api as internal.
IsWasm = Triple(M.getTargetTriple()).isOSBinFormatWasm();
diff --git a/offload/DeviceRTL/src/Misc.cpp b/offload/DeviceRTL/src/Misc.cpp
index c1df477365bcb6..c66bc22ba9e363 100644
--- a/offload/DeviceRTL/src/Misc.cpp
+++ b/offload/DeviceRTL/src/Misc.cpp
@@ -113,10 +113,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`
-[[gnu::visibility("protected"), gnu::weak,
- gnu::retain]] rpc::Client Client asm("__llvm_rpc_client");
+[[gnu::visibility("protected"),
+ gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
} // namespace impl
} // namespace ompx
More information about the llvm-commits
mailing list