Skip to content

Commit 13967a7

Browse files
committed
[Clang] Put offloading globals in the .llvm.rodata.offloading section
Summary: For our offloading entries, we currently store all the string names of kernels that the runtime will need to load from the target executable. These are available via pointer in the `__tgt_offload_entry` struct, however this makes it difficult to obtain from the object itself. This patch simply puts the strings in a named section so they can be easily queried. The motivation behind this is that when the linker wrapper is doing linking, it wants to know which kernels the host executable is calling. We *could* get this already via the `.relaomp_offloading_entires` section and trawling through the string table, but that's quite annoying and not portable. The follow-up to this should be to make the linker wrapper get a list of all used symbols the device link job should count as "needed" so we can handle static linking more directly.
1 parent c04b640 commit 13967a7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

llvm/lib/Frontend/Offloading/Utility.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ offloading::getOffloadingEntryInitializer(Module &M, Constant *Addr,
5353
auto *Str =
5454
new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
5555
GlobalValue::InternalLinkage, AddrName, Prefix);
56+
StringRef SectionName = ".llvm.rodata.offloading";
5657
Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
58+
Str->setSection(SectionName);
59+
Str->setAlignment(Align(1));
60+
61+
// Make a metadata node for these constants so it can be queried from IR.
62+
NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.offloading.symbols");
63+
Metadata *MDVals[] = {ConstantAsMetadata::get(Str)};
64+
MD->addOperand(llvm::MDNode::get(M.getContext(), MDVals));
5765

5866
// Construct the offloading entry.
5967
Constant *EntryData[] = {

0 commit comments

Comments
 (0)