aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-05-21 20:43:13 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-05-21 20:43:13 +0000
commit0a82ad798cb0ab2cfc0028d5281d73b2f1875f23 (patch)
tree880580f8ab8614f63561bdaec7e5fc900073cebe /llvm/lib/MC/ELFObjectWriter.cpp
parent71e0feb1ace06da5966f99c764082c6b352eebc8 (diff)
downloadllvm-0a82ad798cb0ab2cfc0028d5281d73b2f1875f23.zip
llvm-0a82ad798cb0ab2cfc0028d5281d73b2f1875f23.tar.gz
llvm-0a82ad798cb0ab2cfc0028d5281d73b2f1875f23.tar.bz2
Stop creating MCSectionData is the ELF writer.
Now is is just its use of MCSymbolData that requires it to take a non const MCAssembler. llvm-svn: 237951
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp80
1 files changed, 45 insertions, 35 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 7437aff..0e764de 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -221,7 +221,7 @@ class ELFObjectWriter : public MCObjectWriter {
const SectionIndexMapTy &SectionIndexMap,
const RevGroupMapTy &RevGroupMap);
- MCSectionELF *createRelocationSection(MCAssembler &Asm,
+ MCSectionELF *createRelocationSection(MCContext &Ctx,
const MCSectionELF &Sec);
const MCSectionELF *createSectionHeaderStringTable();
@@ -1058,12 +1058,11 @@ void ELFObjectWriter::computeSymbolTable(
}
MCSectionELF *
-ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
+ELFObjectWriter::createRelocationSection(MCContext &Ctx,
const MCSectionELF &Sec) {
if (Relocations[&Sec].empty())
return nullptr;
- MCContext &Ctx = Asm.getContext();
const StringRef SectionName = Sec.getSectionName();
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
RelaSectionName += SectionName;
@@ -1081,8 +1080,7 @@ ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
MCSectionELF *RelaSection = Ctx.createELFRelSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
Flags, EntrySize, Sec.getGroup(), &Sec);
- MCSectionData &RelSD = Asm.getOrCreateSectionData(*RelaSection);
- RelSD.setAlignment(is64Bit() ? 8 : 4);
+ RelaSection->setAlignment(is64Bit() ? 8 : 4);
return RelaSection;
}
@@ -1344,7 +1342,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
// ... then the sections ...
SectionOffsetsTy SectionOffsets;
- bool ComputedSymtab = false;
+ std::vector<MCSectionELF *> Groups;
+ std::vector<MCSectionELF *> Relocations;
for (const MCSectionData &SD : Asm) {
MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
@@ -1355,32 +1354,12 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
uint64_t SecStart = OS.tell();
const MCSymbol *SignatureSymbol = Section.getGroup();
- unsigned Type = Section.getType();
- if (Type == ELF::SHT_GROUP) {
- assert(SignatureSymbol);
- write(uint32_t(ELF::GRP_COMDAT));
- for (const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
- uint32_t SecIndex = SectionIndexMap.lookup(Member);
- write(SecIndex);
- }
- } else if (Type == ELF::SHT_REL || Type == ELF::SHT_RELA) {
- if (!ComputedSymtab) {
- // Compute symbol table information.
- computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
- ComputedSymtab = true;
- }
- writeRelocations(Asm, *Section.getAssociatedSection());
- } else {
- writeSectionData(Asm, SD, Layout);
- }
+ writeSectionData(Asm, SD, Layout);
uint64_t SecEnd = OS.tell();
SectionOffsets[&Section] = std::make_pair(SecStart, SecEnd);
- if (Type == ELF::SHT_GROUP || Type == ELF::SHT_REL || Type == ELF::SHT_RELA)
- continue;
-
- MCSectionELF *RelSection = createRelocationSection(Asm, Section);
+ MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
if (SignatureSymbol) {
Asm.getOrCreateSymbolData(*SignatureSymbol);
@@ -1388,8 +1367,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
if (!GroupIdx) {
MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
GroupIdx = addToSectionTable(Group);
- MCSectionData *GroupD = &Asm.getOrCreateSectionData(*Group);
- GroupD->setAlignment(4);
+ Group->setAlignment(4);
+ Groups.push_back(Group);
}
GroupMembers[SignatureSymbol].push_back(&Section);
if (RelSection)
@@ -1397,14 +1376,45 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
}
SectionIndexMap[&Section] = addToSectionTable(&Section);
- if (RelSection)
+ if (RelSection) {
SectionIndexMap[RelSection] = addToSectionTable(RelSection);
+ Relocations.push_back(RelSection);
+ }
+ }
+
+ for (MCSectionELF *Group : Groups) {
+ uint64_t Padding = OffsetToAlignment(OS.tell(), Group->getAlignment());
+ WriteZeros(Padding);
+
+ // Remember the offset into the file for this section.
+ uint64_t SecStart = OS.tell();
+
+ const MCSymbol *SignatureSymbol = Group->getGroup();
+ assert(SignatureSymbol);
+ write(uint32_t(ELF::GRP_COMDAT));
+ for (const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
+ uint32_t SecIndex = SectionIndexMap.lookup(Member);
+ write(SecIndex);
+ }
+
+ uint64_t SecEnd = OS.tell();
+ SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
}
- if (!ComputedSymtab) {
- // Compute symbol table information.
- computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
- ComputedSymtab = true;
+ // Compute symbol table information.
+ computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
+
+ for (MCSectionELF *RelSection : Relocations) {
+ uint64_t Padding = OffsetToAlignment(OS.tell(), RelSection->getAlignment());
+ WriteZeros(Padding);
+
+ // Remember the offset into the file for this section.
+ uint64_t SecStart = OS.tell();
+
+ writeRelocations(Asm, *RelSection->getAssociatedSection());
+
+ uint64_t SecEnd = OS.tell();
+ SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
}
writeSymbolTable(Ctx, Layout, SectionOffsets);