Special case the creation of relocation sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Mar 2015 13:39:16 +0000 (13:39 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Mar 2015 13:39:16 +0000 (13:39 +0000)
These sections are never looked up and we know when have to create them. Use
that to save adding them to the regular map and avoid a symbol->string->symbol
conversion for the group symbol.

This also makes the implementation independent of the details of how unique
sections are implemented.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233539 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCContext.cpp

index ca4eae53a887bf11faf049662a926ccdec01a3bf..a17e05d87c111398c6c018aab611a881985c0934 100644 (file)
@@ -194,6 +194,7 @@ namespace llvm {
     StringMap<const MCSectionMachO*> MachOUniquingMap;
     std::map<ELFSectionKey, const MCSectionELF *> ELFUniquingMap;
     std::map<COFFSectionKey, const MCSectionCOFF *> COFFUniquingMap;
+    StringMap<bool> ELFRelSecNames;
 
     /// Do automatic reset in destructor
     bool AutoReset;
@@ -304,6 +305,10 @@ namespace llvm {
                                       StringRef Group, bool Unique,
                                       const char *BeginSymName = nullptr);
 
+    const MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
+                                            unsigned Flags, unsigned EntrySize,
+                                            const MCSymbol *Group);
+
     void renameELFSection(const MCSectionELF *Section, StringRef Name);
 
     const MCSectionELF *CreateELFGroupSection();
index c99a3ee5e2601818f525b12d2c14dd9447b051b4..6be37bfd641ba7b16d2908bddb7ddbb9058f074f 100644 (file)
@@ -1167,15 +1167,12 @@ ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
     EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
 
   unsigned Flags = 0;
-  StringRef Group = "";
-  if (Section.getFlags() & ELF::SHF_GROUP) {
+  if (Section.getFlags() & ELF::SHF_GROUP)
     Flags = ELF::SHF_GROUP;
-    Group = Section.getGroup()->getName();
-  }
 
-  const MCSectionELF *RelaSection = Ctx.getELFSection(
+  const MCSectionELF *RelaSection = Ctx.createELFRelSection(
       RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
-      Flags, EntrySize, Group, true);
+      Flags, EntrySize, Section.getGroup());
   return &Asm.getOrCreateSectionData(*RelaSection);
 }
 
index 09de4ee05e6167ab0e9b5c5f9495e090d295a04f..2afa21219fc4dbddd43e240a64fdc44ce428e9d0 100644 (file)
@@ -275,6 +275,18 @@ void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
   const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
 }
 
+const MCSectionELF *
+MCContext::createELFRelSection(StringRef Name, unsigned Type, unsigned Flags,
+                               unsigned EntrySize, const MCSymbol *Group) {
+  StringMap<bool>::iterator I;
+  bool Inserted;
+  std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true));
+
+  return new (*this)
+      MCSectionELF(I->getKey(), Type, Flags, SectionKind::getReadOnly(),
+                   EntrySize, Group, true, nullptr);
+}
+
 const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
                                              unsigned Flags, unsigned EntrySize,
                                              StringRef Group, bool Unique,