[clang] [llvm] [Clang] Prevent `mlink-builtin-bitcode` from internalizing the RPC client (PR #118661)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 4 08:13:38 PST 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/118661
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.
>From 85e5c83b1e5e0997d6b933593ed0516a6dde0baa 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.
---
clang/lib/CodeGen/CodeGenAction.cpp | 3 ++-
offload/DeviceRTL/src/Misc.cpp | 5 +----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index cc927f44e0326e..db762b22560f28 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -246,7 +246,8 @@ bool BackendConsumer::LinkInModules(llvm::Module *M) {
*M, std::move(LM.Module), LM.LinkFlags,
[](llvm::Module &M, const llvm::StringSet<> &GVS) {
internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
- return !GV.hasName() || (GVS.count(GV.getName()) == 0);
+ return !GV.hasName() || (GVS.count(GV.getName()) == 0) ||
+ GV.getName().starts_with("__llvm_rpc_client");
});
});
} else
diff --git a/offload/DeviceRTL/src/Misc.cpp b/offload/DeviceRTL/src/Misc.cpp
index c1df477365bcb6..e6f1a341e4d769 100644
--- a/offload/DeviceRTL/src/Misc.cpp
+++ b/offload/DeviceRTL/src/Misc.cpp
@@ -113,10 +113,7 @@ 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 cfe-commits
mailing list