aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2022-04-02 17:55:00 -0400
committerJoseph Huber <jhuber6@vols.utk.edu>2022-04-14 10:50:49 -0400
commit11f47b791f96ca04b4cf9233d72febc704606dcf (patch)
tree99dd08b147e729152002a937a415c4db39614c61 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parentef141aec3c81b33bd2022f258e6ca8d4b1611fd3 (diff)
downloadllvm-11f47b791f96ca04b4cf9233d72febc704606dcf.zip
llvm-11f47b791f96ca04b4cf9233d72febc704606dcf.tar.gz
llvm-11f47b791f96ca04b4cf9233d72febc704606dcf.tar.bz2
[OpenMP] Make offloading sections have the SHF_EXCLUDE flag
Offloading sections can be embedded in the host during codegen via a section. This section was originally marked as metadata to prevent it from being loaded, but these sections are completely unused at runtime so the linker should automatically drop them from the final executable or shard library. This flag adds support for the SHF_EXCLUDE flag in target lowering and uses it. Reviewed By: JonChesterfield, MaskRay Differential Revision: https://reviews.llvm.org/D122987
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3b21e94..3246d77 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -446,10 +446,12 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
/*AddSegmentInfo=*/false) ||
Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
/*AddSegmentInfo=*/false) ||
- Name == ".llvmbc" || Name == ".llvmcmd" ||
- Name.startswith(".llvm.offloading."))
+ Name == ".llvmbc" || Name == ".llvmcmd")
return SectionKind::getMetadata();
+ if (Name.startswith(".llvm.offloading"))
+ return SectionKind::getExclude();
+
if (Name.empty() || Name[0] != '.') return K;
// Default implementation based on some magic section names.
@@ -508,9 +510,12 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
static unsigned getELFSectionFlags(SectionKind K) {
unsigned Flags = 0;
- if (!K.isMetadata())
+ if (!K.isMetadata() && !K.isExclude())
Flags |= ELF::SHF_ALLOC;
+ if (K.isExclude())
+ Flags |= ELF::SHF_EXCLUDE;
+
if (K.isText())
Flags |= ELF::SHF_EXECINSTR;
@@ -1534,6 +1539,9 @@ getCOFFSectionFlags(SectionKind K, const TargetMachine &TM) {
if (K.isMetadata())
Flags |=
COFF::IMAGE_SCN_MEM_DISCARDABLE;
+ else if (K.isExclude())
+ Flags |=
+ COFF::IMAGE_SCN_LNK_REMOVE | COFF::IMAGE_SCN_MEM_DISCARDABLE;
else if (K.isText())
Flags |=
COFF::IMAGE_SCN_MEM_EXECUTE |