[PATCH] D122987: [OpenMP] Make offloading sections have the SHF_EXCLUDE flag

Joseph Huber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 15:07:40 PDT 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, MaskRay.
Herald added subscribers: StephenFan, pengfei, guansong, hiraditya, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122987

Files:
  llvm/include/llvm/MC/SectionKind.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/X86/offload_sections.ll


Index: llvm/test/CodeGen/X86/offload_sections.ll
===================================================================
--- llvm/test/CodeGen/X86/offload_sections.ll
+++ llvm/test/CodeGen/X86/offload_sections.ll
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
 
- at llvm.embedded.object = hidden constant [1 x i8] c"\00", section ".llvm.offloading.dummy"
+ at llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading"
 @llvm.compiler.used = appending global [1 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @llvm.embedded.object, i32 0, i32 0)], section "llvm.metadata"
 
-; CHECK-DAG: .section	.llvm.offloading.dummy,""
+; CHECK-DAG: .section	.llvm.offloading,"e"
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -446,10 +446,12 @@
                                       /*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 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,8 @@
   if (K.isMetadata())
     Flags |=
       COFF::IMAGE_SCN_MEM_DISCARDABLE;
+  else if (K.isExclude())
+    Flags |= COFF::IMAGE_SCN_LNK_REMOVE;
   else if (K.isText())
     Flags |=
       COFF::IMAGE_SCN_MEM_EXECUTE |
Index: llvm/include/llvm/MC/SectionKind.h
===================================================================
--- llvm/include/llvm/MC/SectionKind.h
+++ llvm/include/llvm/MC/SectionKind.h
@@ -24,6 +24,10 @@
     /// Metadata - Debug info sections or other metadata.
     Metadata,
 
+    /// Exclude - This section will be excluded from the final executable or
+    /// shared library.
+    Exclude,
+
     /// Text - Text section, used for functions and other executable code.
     Text,
 
@@ -118,6 +122,8 @@
 
   bool isMetadata() const { return K == Metadata; }
 
+  bool isExclude() const { return K == Exclude; }
+
   bool isText() const { return K == Text || K == ExecuteOnly; }
 
   bool isExecuteOnly() const { return K == ExecuteOnly; }
@@ -180,6 +186,7 @@
 public:
 
   static SectionKind getMetadata() { return get(Metadata); }
+  static SectionKind getExclude() { return get(Exclude); }
   static SectionKind getText() { return get(Text); }
   static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
   static SectionKind getReadOnly() { return get(ReadOnly); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122987.420013.patch
Type: text/x-patch
Size: 3203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220402/dd1c0d25/attachment.bin>


More information about the llvm-commits mailing list