<div dir="ltr">FYI, some of the LLDB developers reported on lldb-dev@ that this revision regressed tests. Rafael is away from a computer and on that thread said we should go ahead and revert them, so I'm reverting this and a few other revisions to get things back to green.<div><br></div><div>Rafael, ping here if you've any trouble reproducing when you're back. I've CC-ed LLDB folks so they'll see and make sure we get to the root cause.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 11, 2015 at 3:17 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Wed Feb 11 17:17:48 2015<br>
New Revision: 228886<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228886&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=228886&view=rev</a><br>
Log:<br>
Create the Seciton -> Rel Section map when it is first needed. NFC.<br>
<br>
Saves a walk over every section.<br>
<br>
Modified:<br>
    llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
<br>
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=228886&r1=228885&r2=228886&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=228886&r1=228885&r2=228886&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Feb 11 17:17:48 2015<br>
@@ -247,11 +247,12 @@ class ELFObjectWriter : public MCObjectW<br>
                             const RevGroupMapTy &RevGroupMap,<br>
                             unsigned NumRegularSections);<br>
<br>
-    void ComputeIndexMap(MCAssembler &Asm,<br>
+    void computeIndexMap(MCAssembler &Asm,<br>
                          SectionIndexMapTy &SectionIndexMap,<br>
-                         const RelMapTy &RelMap);<br>
+                         RelMapTy &RelMap);<br>
<br>
-    void CreateRelocationSections(MCAssembler &Asm, RelMapTy &RelMap);<br>
+    MCSectionData *createRelocationSection(MCAssembler &Asm,<br>
+                                           const MCSectionData &SD);<br>
<br>
     void CompressDebugSections(MCAssembler &Asm, MCAsmLayout &Layout);<br>
<br>
@@ -263,11 +264,11 @@ class ELFObjectWriter : public MCObjectW<br>
<br>
     // Create the sections that show up in the symbol table. Currently<br>
     // those are the .note.GNU-stack section and the group sections.<br>
-    void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout,<br>
+    void createIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout,<br>
                                GroupMapTy &GroupMap,<br>
                                RevGroupMapTy &RevGroupMap,<br>
                                SectionIndexMapTy &SectionIndexMap,<br>
-                               const RelMapTy &RelMap);<br>
+                               RelMapTy &RelMap);<br>
<br>
     void ExecutePostLayoutBinding(MCAssembler &Asm,<br>
                                   const MCAsmLayout &Layout) override;<br>
@@ -941,9 +942,9 @@ bool ELFObjectWriter::isLocal(const MCSy<br>
   return true;<br>
 }<br>
<br>
-void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,<br>
+void ELFObjectWriter::computeIndexMap(MCAssembler &Asm,<br>
                                       SectionIndexMapTy &SectionIndexMap,<br>
-                                      const RelMapTy &RelMap) {<br>
+                                      RelMapTy &RelMap) {<br>
   unsigned Index = 1;<br>
   for (MCAssembler::iterator it = Asm.begin(),<br>
          ie = Asm.end(); it != ie; ++it) {<br>
@@ -956,16 +957,20 @@ void ELFObjectWriter::ComputeIndexMap(MC<br>
<br>
   for (MCAssembler::iterator it = Asm.begin(),<br>
          ie = Asm.end(); it != ie; ++it) {<br>
+    const MCSectionData &SD = *it;<br>
     const MCSectionELF &Section =<br>
-      static_cast<const MCSectionELF &>(it->getSection());<br>
+      static_cast<const MCSectionELF &>(SD.getSection());<br>
     if (Section.getType() == ELF::SHT_GROUP ||<br>
         Section.getType() == ELF::SHT_REL ||<br>
         Section.getType() == ELF::SHT_RELA)<br>
       continue;<br>
     SectionIndexMap[&Section] = Index++;<br>
-    const MCSectionELF *RelSection = RelMap.lookup(&Section);<br>
-    if (RelSection)<br>
+    if (MCSectionData *RelSD = createRelocationSection(Asm, SD)) {<br>
+      const MCSectionELF *RelSection =<br>
+          static_cast<const MCSectionELF *>(&RelSD->getSection());<br>
+      RelMap[&Section] = RelSection;<br>
       SectionIndexMap[RelSection] = Index++;<br>
+    }<br>
   }<br>
 }<br>
<br>
@@ -1115,42 +1120,37 @@ ELFObjectWriter::computeSymbolTable(MCAs<br>
     UndefinedSymbolData[i].SymbolData->setIndex(Index++);<br>
 }<br>
<br>
-void ELFObjectWriter::CreateRelocationSections(MCAssembler &Asm,<br>
-                                               RelMapTy &RelMap) {<br>
-  for (MCAssembler::const_iterator it = Asm.begin(),<br>
-         ie = Asm.end(); it != ie; ++it) {<br>
-    const MCSectionData &SD = *it;<br>
-    if (Relocations[&SD].empty())<br>
-      continue;<br>
-<br>
-    MCContext &Ctx = Asm.getContext();<br>
-    const MCSectionELF &Section =<br>
-      static_cast<const MCSectionELF&>(SD.getSection());<br>
+MCSectionData *<br>
+ELFObjectWriter::createRelocationSection(MCAssembler &Asm,<br>
+                                         const MCSectionData &SD) {<br>
+  if (Relocations[&SD].empty())<br>
+    return nullptr;<br>
<br>
-    const StringRef SectionName = Section.getSectionName();<br>
-    std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";<br>
-    RelaSectionName += SectionName;<br>
-<br>
-    unsigned EntrySize;<br>
-    if (hasRelocationAddend())<br>
-      EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);<br>
-    else<br>
-      EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);<br>
+  MCContext &Ctx = Asm.getContext();<br>
+  const MCSectionELF &Section =<br>
+      static_cast<const MCSectionELF &>(SD.getSection());<br>
<br>
-    unsigned Flags = 0;<br>
-    StringRef Group = "";<br>
-    if (Section.getFlags() & ELF::SHF_GROUP) {<br>
-      Flags = ELF::SHF_GROUP;<br>
-      Group = Section.getGroup()->getName();<br>
-    }<br>
+  const StringRef SectionName = Section.getSectionName();<br>
+  std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";<br>
+  RelaSectionName += SectionName;<br>
+<br>
+  unsigned EntrySize;<br>
+  if (hasRelocationAddend())<br>
+    EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);<br>
+  else<br>
+    EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);<br>
<br>
-    const MCSectionELF *RelaSection =<br>
-      Ctx.getELFSection(RelaSectionName, hasRelocationAddend() ?<br>
-                        ELF::SHT_RELA : ELF::SHT_REL, Flags,<br>
-                        EntrySize, Group);<br>
-    RelMap[&Section] = RelaSection;<br>
-    Asm.getOrCreateSectionData(*RelaSection);<br>
+  unsigned Flags = 0;<br>
+  StringRef Group = "";<br>
+  if (Section.getFlags() & ELF::SHF_GROUP) {<br>
+    Flags = ELF::SHF_GROUP;<br>
+    Group = Section.getGroup()->getName();<br>
   }<br>
+<br>
+  const MCSectionELF *RelaSection = Ctx.getELFSection(<br>
+      RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,<br>
+      Flags, EntrySize, Group);<br>
+  return &Asm.getOrCreateSectionData(*RelaSection);<br>
 }<br>
<br>
 static SmallVector<char, 128><br>
@@ -1445,12 +1445,12 @@ void ELFObjectWriter::CreateMetadataSect<br>
                           ShStrTabBuilder.data().end());<br>
 }<br>
<br>
-void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,<br>
+void ELFObjectWriter::createIndexedSections(MCAssembler &Asm,<br>
                                             MCAsmLayout &Layout,<br>
                                             GroupMapTy &GroupMap,<br>
                                             RevGroupMapTy &RevGroupMap,<br>
                                             SectionIndexMapTy &SectionIndexMap,<br>
-                                            const RelMapTy &RelMap) {<br>
+                                            RelMapTy &RelMap) {<br>
   MCContext &Ctx = Asm.getContext();<br>
<br>
   // Build the groups<br>
@@ -1474,7 +1474,7 @@ void ELFObjectWriter::CreateIndexedSecti<br>
     GroupMap[Group] = SignatureSymbol;<br>
   }<br>
<br>
-  ComputeIndexMap(Asm, SectionIndexMap, RelMap);<br>
+  computeIndexMap(Asm, SectionIndexMap, RelMap);<br>
<br>
   // Add sections to the groups<br>
   for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end();<br>
@@ -1716,10 +1716,8 @@ void ELFObjectWriter::WriteObject(MCAsse<br>
   CompressDebugSections(Asm, const_cast<MCAsmLayout &>(Layout));<br>
<br>
   DenseMap<const MCSectionELF*, const MCSectionELF*> RelMap;<br>
-  CreateRelocationSections(Asm, RelMap);<br>
-<br>
   const unsigned NumUserAndRelocSections = Asm.size();<br>
-  CreateIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,<br>
+  createIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,<br>
                         RevGroupMap, SectionIndexMap, RelMap);<br>
   const unsigned AllSections = Asm.size();<br>
   const unsigned NumIndexedSections = AllSections - NumUserAndRelocSections;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>