[llvm] r340904 - [llvm-mc] - Allow to set custom flags for debug sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 01:42:02 PDT 2018


Author: grimar
Date: Wed Aug 29 01:42:02 2018
New Revision: 340904

URL: http://llvm.org/viewvc/llvm-project?rev=340904&view=rev
Log:
[llvm-mc] - Allow to set custom flags for debug sections.

I am experimenting with a single split dwarf (.dwo sections in .o files).
I want to make linker to ignore .dwo sections in .o, for that I am trying to add
SHF_EXCLUDE flag ("E") for them in my asm sample.

I found that currently, it is impossible to add any flag for debug sections using llvm-mc.

That happens because we have a set of predefined unique sections created early with default flags:
https://github.com/llvm-mirror/llvm/blob/master/lib/MC/MCObjectFileInfo.cpp#L391

This patch allows a user to add any flags he wants.

I had to edit TargetLoweringObjectFileImpl.cpp to set MetaData type for debug sections.
Their kind was Data by default (so they were allocatable) and so after changes introduced by
this patch the SHF_ALLOC flag was applied for them, what does not make sense for debug sections.
One of OrcJITTests tests failed because of that.

Differential revision: https://reviews.llvm.org/D51361

Added:
    llvm/trunk/test/MC/ELF/section-flags.s
Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/trunk/lib/MC/MCContext.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=340904&r1=340903&r2=340904&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Wed Aug 29 01:42:02 2018
@@ -424,6 +424,9 @@ static SectionKind getELFKindForNamedSec
       Name.startswith(".llvm.linkonce.tb."))
     return SectionKind::getThreadBSS();
 
+  if (Name.startswith(".debug_"))
+    return SectionKind::getMetadata();
+
   return K;
 }
 

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=340904&r1=340903&r2=340904&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Wed Aug 29 01:42:02 2018
@@ -394,6 +394,15 @@ MCSectionELF *MCContext::getELFSection(c
   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(c
   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) {

Added: llvm/trunk/test/MC/ELF/section-flags.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-flags.s?rev=340904&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-flags.s (added)
+++ llvm/trunk/test/MC/ELF/section-flags.s Wed Aug 29 01:42:02 2018
@@ -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", at progbits,1
+nop




More information about the llvm-commits mailing list