diff --git a/llvm/include/llvm/MC/SectionKind.h b/llvm/include/llvm/MC/SectionKind.h --- a/llvm/include/llvm/MC/SectionKind.h +++ b/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); } diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/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 | diff --git a/llvm/test/CodeGen/X86/offload_sections.ll b/llvm/test/CodeGen/X86/offload_sections.ll --- a/llvm/test/CodeGen/X86/offload_sections.ll +++ b/llvm/test/CodeGen/X86/offload_sections.ll @@ -1,6 +1,8 @@ -; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s +; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefix=CHECK-ELF +; RUN: llc < %s -mtriple=x86_64-win32-gnu | FileCheck %s --check-prefix=CHECK-COFF -@llvm.embedded.object = hidden constant [1 x i8] c"\00", section ".llvm.offloading.dummy" +@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-ELF-DAG: .section .llvm.offloading,"e" +; CHECK-COFF-DAG: .section .llvm.offloading,"dr"