Avoid an extra loop over the sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 30 Apr 2015 20:57:14 +0000 (20:57 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 30 Apr 2015 20:57:14 +0000 (20:57 +0000)
Add string to the section header string table as we add sections.

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

lib/MC/ELFObjectWriter.cpp

index 12950584fc7fb7be739e48a32dcc694e7c54398c..98d6c77698ad91956d2716260346e42a0f2206ef 100644 (file)
@@ -263,6 +263,7 @@ class ELFObjectWriter : public MCObjectWriter {
 
 unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
   SectionTable.push_back(Sec);
+  ShStrTabBuilder.add(Sec->getSectionName());
   return SectionTable.size();
 }
 
@@ -1310,14 +1311,7 @@ void ELFObjectWriter::writeRelocations(const MCAssembler &Asm,
 const MCSectionELF *
 ELFObjectWriter::createSectionHeaderStringTable(MCAssembler &Asm) {
   const MCSectionELF *ShstrtabSection = SectionTable[ShstrtabIndex - 1];
-
   Asm.getOrCreateSectionData(*ShstrtabSection);
-
-  for (MCSectionData &SD : Asm) {
-    const MCSectionELF &Section =
-        static_cast<const MCSectionELF &>(SD.getSection());
-    ShStrTabBuilder.add(Section.getSectionName());
-  }
   ShStrTabBuilder.finalize(StringTableBuilder::ELF);
   OS << ShStrTabBuilder.data();
   return ShstrtabSection;