summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp3
-rw-r--r--llvm/lib/MC/MCContext.cpp16
-rw-r--r--llvm/test/MC/ELF/section-flags.s12
3 files changed, 27 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 7a5fd2985c7..6944c532c08 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -424,6 +424,9 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
Name.startswith(".llvm.linkonce.tb."))
return SectionKind::getThreadBSS();
+ if (Name.startswith(".debug_"))
+ return SectionKind::getMetadata();
+
return K;
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 341a1a4e3b4..ef919d00923 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -394,6 +394,15 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
auto IterBool = ELFUniquingMap.insert(
std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr));
auto &Entry = *IterBool.first;
+ MCSectionELF *&Sec = Entry.second;
+ if (!IterBool.second) {
+ // We want to let users add additional flags even for sections with
+ // defaults. For example, .debug_str has "MS" flags by default and user
+ // might want to add "E".
+ Sec->setFlags(Sec->getFlags() | Flags);
+ return Sec;
+ }
+
if (!IterBool.second)
return Entry.second;
@@ -407,10 +416,9 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
else
Kind = SectionKind::getReadOnly();
- MCSectionELF *Result = createELFSectionImpl(
- CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
- Entry.second = Result;
- return Result;
+ Sec = createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
+ UniqueID, Associated);
+ return Sec;
}
MCSectionELF *MCContext::createELFGroupSection(const MCSymbolELF *Group) {
diff --git a/llvm/test/MC/ELF/section-flags.s b/llvm/test/MC/ELF/section-flags.s
new file mode 100644
index 00000000000..077a9b497d5
--- /dev/null
+++ b/llvm/test/MC/ELF/section-flags.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -triple x86_64-pc-linux-gnu %s -filetype=obj -o %t.o
+# RUN: llvm-readobj -s --elf-output-style=GNU %t.o | FileCheck %s
+
+## Check we are able to set the custom flag ('E') for debug sections.
+# CHECK: .debug_info {{.*}} E
+# CHECK: .debug_str {{.*}} EMS
+
+.section .debug_info,"e"
+nop
+
+.section .debug_str,"eMS",@progbits,1
+nop
OpenPOWER on IntegriCloud