Refactor padding writing into a helper function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239174 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-06-05 18:21:00 +00:00
parent fffd691439
commit aa4466db93

View File

@ -133,6 +133,8 @@ class ELFObjectWriter : public MCObjectWriter {
return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel); return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel);
} }
void align(unsigned Alignment);
public: public:
ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS, ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS,
bool IsLittleEndian) bool IsLittleEndian)
@ -231,6 +233,11 @@ class ELFObjectWriter : public MCObjectWriter {
}; };
} }
void ELFObjectWriter::align(unsigned Alignment) {
uint64_t Padding = OffsetToAlignment(OS.tell(), Alignment);
WriteZeros(Padding);
}
unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) { unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
SectionTable.push_back(Sec); SectionTable.push_back(Sec);
StrTabBuilder.add(Sec->getSectionName()); StrTabBuilder.add(Sec->getSectionName());
@ -758,10 +765,7 @@ void ELFObjectWriter::computeSymbolTable(
SymtabSection->setAlignment(is64Bit() ? 8 : 4); SymtabSection->setAlignment(is64Bit() ? 8 : 4);
SymbolTableIndex = addToSectionTable(SymtabSection); SymbolTableIndex = addToSectionTable(SymtabSection);
uint64_t Padding = align(SymtabSection->getAlignment());
OffsetToAlignment(OS.tell(), SymtabSection->getAlignment());
WriteZeros(Padding);
uint64_t SecStart = OS.tell(); uint64_t SecStart = OS.tell();
// The first entry is the undefined symbol entry. // The first entry is the undefined symbol entry.
@ -1196,8 +1200,7 @@ void ELFObjectWriter::writeObject(MCAssembler &Asm,
for (MCSection &Sec : Asm) { for (MCSection &Sec : Asm) {
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec); MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
uint64_t Padding = OffsetToAlignment(OS.tell(), Section.getAlignment()); align(Section.getAlignment());
WriteZeros(Padding);
// Remember the offset into the file for this section. // Remember the offset into the file for this section.
uint64_t SecStart = OS.tell(); uint64_t SecStart = OS.tell();
@ -1234,8 +1237,7 @@ void ELFObjectWriter::writeObject(MCAssembler &Asm,
} }
for (MCSectionELF *Group : Groups) { for (MCSectionELF *Group : Groups) {
uint64_t Padding = OffsetToAlignment(OS.tell(), Group->getAlignment()); align(Group->getAlignment());
WriteZeros(Padding);
// Remember the offset into the file for this section. // Remember the offset into the file for this section.
uint64_t SecStart = OS.tell(); uint64_t SecStart = OS.tell();
@ -1256,8 +1258,7 @@ void ELFObjectWriter::writeObject(MCAssembler &Asm,
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap, SectionOffsets); computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap, SectionOffsets);
for (MCSectionELF *RelSection : Relocations) { for (MCSectionELF *RelSection : Relocations) {
uint64_t Padding = OffsetToAlignment(OS.tell(), RelSection->getAlignment()); align(RelSection->getAlignment());
WriteZeros(Padding);
// Remember the offset into the file for this section. // Remember the offset into the file for this section.
uint64_t SecStart = OS.tell(); uint64_t SecStart = OS.tell();
@ -1276,8 +1277,7 @@ void ELFObjectWriter::writeObject(MCAssembler &Asm,
} }
uint64_t NaturalAlignment = is64Bit() ? 8 : 4; uint64_t NaturalAlignment = is64Bit() ? 8 : 4;
uint64_t Padding = OffsetToAlignment(OS.tell(), NaturalAlignment); align(NaturalAlignment);
WriteZeros(Padding);
const unsigned SectionHeaderOffset = OS.tell(); const unsigned SectionHeaderOffset = OS.tell();