Skip to content

Commit 760a786

Browse files
authored
[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.
1 parent 7873d3b commit 760a786

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

llvm/lib/Transforms/IPO/Internalize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ bool InternalizePass::internalizeModule(Module &M) {
233233
else
234234
AlwaysPreserved.insert("__stack_chk_guard");
235235

236+
// Preserve the RPC interface for GPU host callbacks when internalizing.
237+
if (Triple(M.getTargetTriple()).isNVPTX())
238+
AlwaysPreserved.insert("__llvm_rpc_server");
239+
236240
// Mark all functions not in the api as internal.
237241
IsWasm = Triple(M.getTargetTriple()).isOSBinFormatWasm();
238242
for (Function &I : M) {

offload/DeviceRTL/src/Misc.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,8 @@ void *indirectCallLookup(void *HstPtr) {
105105
}
106106

107107
/// The openmp client instance used to communicate with the server.
108-
/// FIXME: This is marked as 'retain' so that it is not removed via
109-
/// `-mlink-builtin-bitcode`
110-
#ifdef __NVPTX__
111-
[[gnu::visibility("protected"), gnu::weak,
112-
gnu::retain]] rpc::Client Client asm("__llvm_rpc_client");
113-
#else
114-
[[gnu::visibility("protected"), gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
115-
#endif
108+
[[gnu::visibility("protected"),
109+
gnu::weak]] rpc::Client Client asm("__llvm_rpc_client");
116110

117111
} // namespace impl
118112
} // namespace ompx

0 commit comments

Comments
 (0)