[llvm] [Clang] Put offloading globals in the `.llvm.rodata.offloading` section (PR #111890)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 14:26:59 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/111890
>From 13967a731608b6c5fbc72febf74a237f58b104f1 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 10 Oct 2024 13:42:22 -0500
Subject: [PATCH] [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.
---
llvm/lib/Frontend/Offloading/Utility.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/llvm/lib/Frontend/Offloading/Utility.cpp b/llvm/lib/Frontend/Offloading/Utility.cpp
index 010c0bfd3be76b..7a0a7afcfcb5c9 100644
--- a/llvm/lib/Frontend/Offloading/Utility.cpp
+++ b/llvm/lib/Frontend/Offloading/Utility.cpp
@@ -53,7 +53,15 @@ offloading::getOffloadingEntryInitializer(Module &M, Constant *Addr,
auto *Str =
new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
GlobalValue::InternalLinkage, AddrName, Prefix);
+ StringRef SectionName = ".llvm.rodata.offloading";
Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
+ Str->setSection(SectionName);
+ Str->setAlignment(Align(1));
+
+ // Make a metadata node for these constants so it can be queried from IR.
+ NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.offloading.symbols");
+ Metadata *MDVals[] = {ConstantAsMetadata::get(Str)};
+ MD->addOperand(llvm::MDNode::get(M.getContext(), MDVals));
// Construct the offloading entry.
Constant *EntryData[] = {
More information about the llvm-commits
mailing list