Changeset View
Changeset View
Standalone View
Standalone View
lib/MC/ELFObjectWriter.cpp
Show First 20 Lines • Show All 1,147 Lines • ▼ Show 20 Lines | void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap, | ||||
case ELF::SHT_DYNAMIC: | case ELF::SHT_DYNAMIC: | ||||
llvm_unreachable("SHT_DYNAMIC in a relocatable object"); | llvm_unreachable("SHT_DYNAMIC in a relocatable object"); | ||||
case ELF::SHT_REL: | case ELF::SHT_REL: | ||||
case ELF::SHT_RELA: { | case ELF::SHT_RELA: { | ||||
sh_link = SymbolTableIndex; | sh_link = SymbolTableIndex; | ||||
assert(sh_link && ".symtab not found"); | assert(sh_link && ".symtab not found"); | ||||
const MCSectionELF *InfoSection = Section.getAssociatedSection(); | const MCSectionELF *InfoSection = Section.getRelInfoSection(); | ||||
sh_info = SectionIndexMap.lookup(InfoSection); | sh_info = SectionIndexMap.lookup(InfoSection); | ||||
break; | break; | ||||
} | } | ||||
case ELF::SHT_SYMTAB: | case ELF::SHT_SYMTAB: | ||||
case ELF::SHT_DYNSYM: | case ELF::SHT_DYNSYM: | ||||
sh_link = StringTableIndex; | sh_link = StringTableIndex; | ||||
sh_info = LastLocalSymbolIndex; | sh_info = LastLocalSymbolIndex; | ||||
break; | break; | ||||
case ELF::SHT_SYMTAB_SHNDX: | case ELF::SHT_SYMTAB_SHNDX: | ||||
sh_link = SymbolTableIndex; | sh_link = SymbolTableIndex; | ||||
break; | break; | ||||
case ELF::SHT_GROUP: | case ELF::SHT_GROUP: | ||||
sh_link = SymbolTableIndex; | sh_link = SymbolTableIndex; | ||||
sh_info = GroupSymbolIndex; | sh_info = GroupSymbolIndex; | ||||
break; | break; | ||||
} | } | ||||
if (Section.getFlags() & ELF::SHF_LINK_ORDER) | if (Section.getFlags() & ELF::SHF_LINK_ORDER) { | ||||
sh_link = SectionIndexMap.lookup(Section.getAssociatedSection()); | const MCSymbol *Sym = Section.getAssociatedSymbol(); | ||||
assert(Sym && Sym->isInSection()); | |||||
const MCSectionELF *Sec = dyn_cast<MCSectionELF>(&Sym->getSection()); | |||||
sh_link = SectionIndexMap.lookup(Sec); | |||||
} | |||||
WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getSectionName()), | WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getSectionName()), | ||||
Section.getType(), Section.getFlags(), 0, Offset, Size, | Section.getType(), Section.getFlags(), 0, Offset, Size, | ||||
sh_link, sh_info, Section.getAlignment(), | sh_link, sh_info, Section.getAlignment(), | ||||
Section.getEntrySize()); | Section.getEntrySize()); | ||||
} | } | ||||
void ELFObjectWriter::writeSectionHeader( | void ELFObjectWriter::writeSectionHeader( | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | 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) { | ||||
align(RelSection->getAlignment()); | align(RelSection->getAlignment()); | ||||
// Remember the offset into the file for this section. | // Remember the offset into the file for this section. | ||||
uint64_t SecStart = getStream().tell(); | uint64_t SecStart = getStream().tell(); | ||||
writeRelocations(Asm, *RelSection->getAssociatedSection()); | writeRelocations(Asm, *RelSection->getRelInfoSection()); | ||||
uint64_t SecEnd = getStream().tell(); | uint64_t SecEnd = getStream().tell(); | ||||
SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd); | SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd); | ||||
} | } | ||||
{ | { | ||||
uint64_t SecStart = getStream().tell(); | uint64_t SecStart = getStream().tell(); | ||||
const MCSectionELF *Sec = createStringTable(Ctx); | const MCSectionELF *Sec = createStringTable(Ctx); | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |