[llvm] r236148 - Write the string table directly to the output file.
Rafael Espindola
rafael.espindola at gmail.com
Wed Apr 29 13:34:31 PDT 2015
Author: rafael
Date: Wed Apr 29 15:34:31 2015
New Revision: 236148
URL: http://llvm.org/viewvc/llvm-project?rev=236148&view=rev
Log:
Write the string table directly to the output file.
There is no need to accumulate it in fragments first.
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=236148&r1=236147&r2=236148&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Apr 29 15:34:31 2015
@@ -250,6 +250,8 @@ class ELFObjectWriter : public MCObjectW
void
createSectionHeaderStringTable(MCAssembler &Asm,
std::vector<const MCSectionELF *> &Sections);
+ void createStringTable(MCAssembler &Asm,
+ std::vector<const MCSectionELF *> &Sections);
void CreateMetadataSections(MCAssembler &Asm, const MCAsmLayout &Layout,
std::vector<const MCSectionELF *> &Sections);
@@ -1388,6 +1390,17 @@ void ELFObjectWriter::createSectionHeade
OS << ShStrTabBuilder.data();
}
+void ELFObjectWriter::createStringTable(
+ MCAssembler &Asm, std::vector<const MCSectionELF *> &Sections) {
+ MCContext &Ctx = Asm.getContext();
+ const MCSectionELF *StrtabSection =
+ Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
+ Asm.getOrCreateSectionData(*StrtabSection);
+ Sections.push_back(StrtabSection);
+ StringTableIndex = Sections.size();
+ OS << StrTabBuilder.data();
+}
+
void ELFObjectWriter::CreateMetadataSections(
MCAssembler &Asm, const MCAsmLayout &Layout,
std::vector<const MCSectionELF *> &Sections) {
@@ -1396,6 +1409,7 @@ void ELFObjectWriter::CreateMetadataSect
unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
+ // Symbol table
const MCSectionELF *SymtabSection =
Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
EntrySize, "");
@@ -1403,21 +1417,8 @@ void ELFObjectWriter::CreateMetadataSect
SymtabSD.setAlignment(is64Bit() ? 8 : 4);
SymbolTableIndex = Sections.size() + 1;
Sections.push_back(SymtabSection);
-
- const MCSectionELF *StrtabSection;
- StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
- MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection);
- StrtabSD.setAlignment(1);
- StringTableIndex = Sections.size() + 1;
- Sections.push_back(StrtabSection);
-
- // Symbol table
F = new MCDataFragment(&SymtabSD);
WriteSymbolTable(F, Asm, Layout, Sections);
-
- F = new MCDataFragment(&StrtabSD);
- F->getContents().append(StrTabBuilder.data().begin(),
- StrTabBuilder.data().end());
}
void ELFObjectWriter::createIndexedSections(
@@ -1576,7 +1577,7 @@ void ELFObjectWriter::WriteObject(MCAsse
CreateMetadataSections(Asm, Layout, Sections);
- unsigned NumSections = Asm.size() + 1;
+ unsigned NumSections = Asm.size() + 2;
SectionOffsetsTy SectionOffsets;
// Write out the ELF header ...
@@ -1595,6 +1596,13 @@ void ELFObjectWriter::WriteObject(MCAsse
uint64_t SecEnd = OS.tell();
SectionOffsets.push_back(std::make_pair(SecStart, SecEnd));
}
+
+ {
+ uint64_t SecStart = OS.tell();
+ createStringTable(Asm, Sections);
+ uint64_t SecEnd = OS.tell();
+ SectionOffsets.push_back(std::make_pair(SecStart, SecEnd));
+ }
{
uint64_t SecStart = OS.tell();
More information about the llvm-commits
mailing list