Fetch alignment directly out of MCSection. NFC.
[oota-llvm.git] / lib / MC / ELFObjectWriter.cpp
index c36da56f0cec7ffcdce2f682b491c9656deb0653..8afd00fb7e315cee0211c832b839a0396fb1dfa4 100644 (file)
@@ -133,8 +133,8 @@ class ELFObjectWriter : public MCObjectWriter {
     unsigned ShstrtabIndex;
 
     // Sections in the order they are to be output in the section table.
-    std::vector<const MCSectionELF *> SectionTable;
-    unsigned addToSectionTable(const MCSectionELF *Sec);
+    std::vector<MCSectionELF *> SectionTable;
+    unsigned addToSectionTable(MCSectionELF *Sec);
 
     // TargetObjectWriter wrappers.
     bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
@@ -221,8 +221,8 @@ class ELFObjectWriter : public MCObjectWriter {
                             const SectionIndexMapTy &SectionIndexMap,
                             const RevGroupMapTy &RevGroupMap);
 
-    const MCSectionELF *createRelocationSection(MCAssembler &Asm,
-                                                const MCSectionELF &Sec);
+    MCSectionELF *createRelocationSection(MCAssembler &Asm,
+                                          const MCSectionELF &Sec);
 
     const MCSectionELF *createSectionHeaderStringTable();
     const MCSectionELF *createStringTable(MCContext &Ctx);
@@ -255,13 +255,12 @@ class ELFObjectWriter : public MCObjectWriter {
     void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
     void writeSection(MCAssembler &Asm,
                       const SectionIndexMapTy &SectionIndexMap,
-                      uint32_t GroupSymbolIndex,
-                      uint64_t Offset, uint64_t Size, uint64_t Alignment,
+                      uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
                       const MCSectionELF &Section);
   };
 }
 
-unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
+unsigned ELFObjectWriter::addToSectionTable(MCSectionELF *Sec) {
   SectionTable.push_back(Sec);
   ShStrTabBuilder.add(Sec->getSectionName());
   return SectionTable.size();
@@ -549,7 +548,7 @@ void ELFObjectWriter::WriteSymbolTable(MCAssembler &Asm,
   unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
 
   // Symbol table
-  const MCSectionELF *SymtabSection =
+  MCSectionELF *SymtabSection =
       Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, EntrySize, "");
   MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection);
   SymtabSD.setAlignment(is64Bit() ? 8 : 4);
@@ -608,7 +607,7 @@ void ELFObjectWriter::WriteSymbolTable(MCAssembler &Asm,
     return;
 
   SecStart = OS.tell();
-  const MCSectionELF *SymtabShndxSection =
+  MCSectionELF *SymtabShndxSection =
       Ctx.getELFSection(".symtab_shndxr", ELF::SHT_SYMTAB_SHNDX, 0, 4, "");
   addToSectionTable(SymtabShndxSection);
   MCSectionData *SymtabShndxSD =
@@ -1064,7 +1063,7 @@ void ELFObjectWriter::computeSymbolTable(
     UndefinedSymbolData[i].Symbol->getData().setIndex(Index++);
 }
 
-const MCSectionELF *
+MCSectionELF *
 ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
                                          const MCSectionELF &Sec) {
   if (Relocations[&Sec].empty())
@@ -1085,7 +1084,7 @@ ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
   if (Sec.getFlags() & ELF::SHF_GROUP)
     Flags = ELF::SHF_GROUP;
 
-  const MCSectionELF *RelaSection = Ctx.createELFRelSection(
+  MCSectionELF *RelaSection = Ctx.createELFRelSection(
       RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
       Flags, EntrySize, Sec.getGroup(), &Sec);
   MCSectionData &RelSD = Asm.getOrCreateSectionData(*RelaSection);
@@ -1141,8 +1140,7 @@ prependCompressionHeader(uint64_t Size,
 void ELFObjectWriter::writeSectionData(const MCAssembler &Asm,
                                        const MCSectionData &SD,
                                        const MCAsmLayout &Layout) {
-  const MCSectionELF &Section =
-      static_cast<const MCSectionELF &>(SD.getSection());
+  MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
   StringRef SectionName = Section.getSectionName();
 
   // Compressing debug_frame requires handling alignment fragments which is
@@ -1245,7 +1243,7 @@ const MCSectionELF *ELFObjectWriter::createSectionHeaderStringTable() {
 }
 
 const MCSectionELF *ELFObjectWriter::createStringTable(MCContext &Ctx) {
-  const MCSectionELF *StrtabSection =
+  MCSectionELF *StrtabSection =
       Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
   StringTableIndex = addToSectionTable(StrtabSection);
   OS << StrTabBuilder.data();
@@ -1256,7 +1254,6 @@ void ELFObjectWriter::writeSection(MCAssembler &Asm,
                                    const SectionIndexMapTy &SectionIndexMap,
                                    uint32_t GroupSymbolIndex,
                                    uint64_t Offset, uint64_t Size,
-                                   uint64_t Alignment,
                                    const MCSectionELF &Section) {
   uint64_t sh_link = 0;
   uint64_t sh_info = 0;
@@ -1299,9 +1296,9 @@ void ELFObjectWriter::writeSection(MCAssembler &Asm,
     sh_link = SectionIndexMap.lookup(Section.getAssociatedSection());
 
   WriteSecHdrEntry(ShStrTabBuilder.getOffset(Section.getSectionName()),
-                   Section.getType(),
-                   Section.getFlags(), 0, Offset, Size, sh_link, sh_info,
-                   Alignment, Section.getEntrySize());
+                   Section.getType(), Section.getFlags(), 0, Offset, Size,
+                   sh_link, sh_info, Section.getAlignment(),
+                   Section.getEntrySize());
 }
 
 void ELFObjectWriter::writeSectionHeader(
@@ -1315,7 +1312,7 @@ void ELFObjectWriter::writeSectionHeader(
       (NumSections + 1) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0;
   WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
 
-  for (const MCSectionELF *Section : SectionTable) {
+  for (MCSectionELF *Section : SectionTable) {
     const MCSectionData &SD = Asm.getOrCreateSectionData(*Section);
     uint32_t GroupSymbolIndex;
     unsigned Type = Section->getType();
@@ -1330,14 +1327,14 @@ void ELFObjectWriter::writeSectionHeader(
                                             : Offsets.second - Offsets.first;
 
     writeSection(Asm, SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
-                 SD.getAlignment(), *Section);
+                 *Section);
   }
 }
 
 void ELFObjectWriter::WriteObject(MCAssembler &Asm,
                                   const MCAsmLayout &Layout) {
   MCContext &Ctx = Asm.getContext();
-  const MCSectionELF *ShstrtabSection =
+  MCSectionELF *ShstrtabSection =
       Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0);
   ShstrtabIndex = addToSectionTable(ShstrtabSection);
 
@@ -1353,8 +1350,7 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
   SectionOffsetsTy SectionOffsets;
   bool ComputedSymtab = false;
   for (const MCSectionData &SD : Asm) {
-    const MCSectionELF &Section =
-        static_cast<const MCSectionELF &>(SD.getSection());
+    MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
 
     uint64_t Padding = OffsetToAlignment(OS.tell(), SD.getAlignment());
     WriteZeros(Padding);
@@ -1388,13 +1384,13 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
     if (Type == ELF::SHT_GROUP || Type == ELF::SHT_REL || Type == ELF::SHT_RELA)
       continue;
 
-    const MCSectionELF *RelSection = createRelocationSection(Asm, Section);
+    MCSectionELF *RelSection = createRelocationSection(Asm, Section);
 
     if (SignatureSymbol) {
       Asm.getOrCreateSymbolData(*SignatureSymbol);
       unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
       if (!GroupIdx) {
-        const MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
+        MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
         GroupIdx = addToSectionTable(Group);
         MCSectionData *GroupD = &Asm.getOrCreateSectionData(*Group);
         GroupD->setAlignment(4);