[llvm] r239174 - Refactor padding writing into a helper function.
Rafael Espindola
rafael.espindola at gmail.com
Fri Jun 5 11:21:00 PDT 2015
Author: rafael
Date: Fri Jun 5 13:21:00 2015
New Revision: 239174
URL: http://llvm.org/viewvc/llvm-project?rev=239174&view=rev
Log:
Refactor padding writing into a helper function.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=239174&r1=239173&r2=239174&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Jun 5 13:21:00 2015
@@ -133,6 +133,8 @@ class ELFObjectWriter : public MCObjectW
return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel);
}
+ void align(unsigned Alignment);
+
public:
ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS,
bool IsLittleEndian)
@@ -231,6 +233,11 @@ class ELFObjectWriter : public MCObjectW
};
}
+void ELFObjectWriter::align(unsigned Alignment) {
+ uint64_t Padding = OffsetToAlignment(OS.tell(), Alignment);
+ WriteZeros(Padding);
+}
+
unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
SectionTable.push_back(Sec);
StrTabBuilder.add(Sec->getSectionName());
@@ -758,10 +765,7 @@ void ELFObjectWriter::computeSymbolTable
SymtabSection->setAlignment(is64Bit() ? 8 : 4);
SymbolTableIndex = addToSectionTable(SymtabSection);
- uint64_t Padding =
- OffsetToAlignment(OS.tell(), SymtabSection->getAlignment());
- WriteZeros(Padding);
-
+ align(SymtabSection->getAlignment());
uint64_t SecStart = OS.tell();
// The first entry is the undefined symbol entry.
@@ -1196,8 +1200,7 @@ void ELFObjectWriter::writeObject(MCAsse
for (MCSection &Sec : Asm) {
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
- uint64_t Padding = OffsetToAlignment(OS.tell(), Section.getAlignment());
- WriteZeros(Padding);
+ align(Section.getAlignment());
// Remember the offset into the file for this section.
uint64_t SecStart = OS.tell();
@@ -1234,8 +1237,7 @@ void ELFObjectWriter::writeObject(MCAsse
}
for (MCSectionELF *Group : Groups) {
- uint64_t Padding = OffsetToAlignment(OS.tell(), Group->getAlignment());
- WriteZeros(Padding);
+ align(Group->getAlignment());
// Remember the offset into the file for this section.
uint64_t SecStart = OS.tell();
@@ -1256,8 +1258,7 @@ void ELFObjectWriter::writeObject(MCAsse
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap, SectionOffsets);
for (MCSectionELF *RelSection : Relocations) {
- uint64_t Padding = OffsetToAlignment(OS.tell(), RelSection->getAlignment());
- WriteZeros(Padding);
+ align(RelSection->getAlignment());
// Remember the offset into the file for this section.
uint64_t SecStart = OS.tell();
@@ -1276,8 +1277,7 @@ void ELFObjectWriter::writeObject(MCAsse
}
uint64_t NaturalAlignment = is64Bit() ? 8 : 4;
- uint64_t Padding = OffsetToAlignment(OS.tell(), NaturalAlignment);
- WriteZeros(Padding);
+ align(NaturalAlignment);
const unsigned SectionHeaderOffset = OS.tell();
More information about the llvm-commits
mailing list