diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-09-16 19:46:31 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-09-16 19:46:31 +0000 |
commit | 71859c640f6a36251aca223fd503c58dc314e296 (patch) | |
tree | 8e19e6b378c0ef3660347aeb0045a71a73ca8a54 /lib/MC/ELFObjectWriter.cpp | |
parent | b86f57c606911cafb4d0fba5dd848e6bb6fbc0fb (diff) |
Print the address of sections as 0 and create the metadata sections in the
same order as gnu as.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114109 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index feabd6008b..8295dacd15 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -205,7 +205,8 @@ namespace { const MCAsmLayout &Layout); void WriteSymbolTable(MCDataFragment *F, const MCAssembler &Asm, - const MCAsmLayout &Layout); + const MCAsmLayout &Layout, + unsigned NumRegularSections); void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, @@ -405,7 +406,8 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD, void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F, const MCAssembler &Asm, - const MCAsmLayout &Layout) { + const MCAsmLayout &Layout, + unsigned NumRegularSections) { // The string table must be emitted first because we need the index // into the string table for all the symbol names. assert(StringTable.size() && "Missing string table"); @@ -423,20 +425,16 @@ void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F, WriteSymbol(F, MSD, Layout); } - // Write out a symbol table entry for each section. - // leaving out the just added .symtab which is at - // the very end + // Write out a symbol table entry for each regular section. unsigned Index = 1; - for (MCAssembler::const_iterator it = Asm.begin(), - ie = Asm.end(); it != ie; ++it, ++Index) { + for (MCAssembler::const_iterator it = Asm.begin(); + Index <= NumRegularSections; ++it, ++Index) { const MCSectionELF &Section = static_cast<const MCSectionELF&>(it->getSection()); // Leave out relocations so we don't have indexes within // the relocations messed up if (Section.getType() == ELF::SHT_RELA || Section.getType() == ELF::SHT_REL) continue; - if (Index == Asm.size()) - continue; WriteSymbolEntry(F, 0, ELF::STT_SECTION, 0, 0, ELF::STV_DEFAULT, Index); LastLocalSymbolIndex++; } @@ -785,48 +783,41 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm, const MCSection *SymtabSection; unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32; + unsigned NumRegularSections = Asm.size(); + + // We construct .shstrtab, .symtab and .strtab is this order to match gnu as. + const MCSection *ShstrtabSection; + ShstrtabSection = Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0, + SectionKind::getReadOnly(), false); + MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection); + ShstrtabSD.setAlignment(1); + ShstrtabIndex = Asm.size(); + SymtabSection = Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, SectionKind::getReadOnly(), false, EntrySize); - MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection); - SymtabSD.setAlignment(Is64Bit ? 8 : 4); - F = new MCDataFragment(&SymtabSD); - - // Symbol table - WriteSymbolTable(F, Asm, Layout); - Asm.AddSectionToTheEnd(SymtabSD, Layout); - const MCSection *StrtabSection; StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0, SectionKind::getReadOnly(), false); - MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection); StrtabSD.setAlignment(1); - - // FIXME: This isn't right. If the sections get rearranged this will - // be wrong. We need a proper lookup. StringTableIndex = Asm.size(); + + // Symbol table + F = new MCDataFragment(&SymtabSD); + WriteSymbolTable(F, Asm, Layout, NumRegularSections); + Asm.AddSectionToTheEnd(SymtabSD, Layout); + F = new MCDataFragment(&StrtabSD); F->getContents().append(StringTable.begin(), StringTable.end()); Asm.AddSectionToTheEnd(StrtabSD, Layout); - const MCSection *ShstrtabSection; - ShstrtabSection = Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0, - SectionKind::getReadOnly(), false); - - MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection); - ShstrtabSD.setAlignment(1); - F = new MCDataFragment(&ShstrtabSD); - // FIXME: This isn't right. If the sections get rearranged this will - // be wrong. We need a proper lookup. - ShstrtabIndex = Asm.size(); - // Section header string table. // // The first entry of a string table holds a null character so skip @@ -974,7 +965,7 @@ void ELFObjectWriterImpl::WriteObject(const MCAssembler &Asm, WriteSecHdrEntry(SectionStringTableIndex[&it->getSection()], Section.getType(), Section.getFlags(), - Layout.getSectionAddress(&SD), + 0, SectionOffsetMap.lookup(&SD.getSection()), Layout.getSectionSize(&SD), sh_link, sh_info, SD.getAlignment(), |