Skip to content

Commit 9749143

Browse files
committed
[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.
1 parent 3dc9755 commit 9749143

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ bool BackendConsumer::LinkInModules(llvm::Module *M) {
246246
*M, std::move(LM.Module), LM.LinkFlags,
247247
[](llvm::Module &M, const llvm::StringSet<> &GVS) {
248248
internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
249-
return !GV.hasName() || (GVS.count(GV.getName()) == 0);
249+
return !GV.hasName() || (GVS.count(GV.getName()) == 0) ||
250+
GV.getName().starts_with("__llvm_rpc_client");
250251
});
251252
});
252253
} else

offload/DeviceRTL/src/Misc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ void *indirectCallLookup(void *HstPtr) {
113113
}
114114

115115
/// The openmp client instance used to communicate with the server.
116-
/// FIXME: This is marked as 'retain' so that it is not removed via
117-
/// `-mlink-builtin-bitcode`
118-
[[gnu::visibility("protected"), gnu::weak,
119-
gnu::retain]] rpc::Client Client asm("__llvm_rpc_client");
116+
[[gnu::visibility("protected"),
117+
gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
120118

121119
} // namespace impl
122120
} // namespace ompx

0 commit comments

Comments
 (0)