Skip to content

Commit 3df20f0

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 b6dfdd2 commit 3df20f0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Transforms/IPO/Internalize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ bool InternalizePass::internalizeModule(Module &M) {
232232
AlwaysPreserved.insert("__ssp_canary_word");
233233
else
234234
AlwaysPreserved.insert("__stack_chk_guard");
235+
// For GPU host callbacks.
236+
AlwaysPreserved.insert("__llvm_rpc_server");
235237

236238
// Mark all functions not in the api as internal.
237239
IsWasm = Triple(M.getTargetTriple()).isOSBinFormatWasm();

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)