Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -72,6 +72,7 @@ void assignAddresses(); void assignAddressesRelocatable(); void assignPhdrs(); + void fixDummiesSections(); void fixSectionAlignments(); void fixAbsoluteSymbols(); bool openFile(); @@ -215,8 +216,11 @@ addReservedSymbols(); if (!createSections()) return; - if (!Config->Relocatable) { + if (!Config->Relocatable) createPhdrs(); + fixDummiesSections(); + + if (!Config->Relocatable) { fixSectionAlignments(); assignAddresses(); } else { @@ -1380,11 +1384,16 @@ return FileOff; } +template void Writer::fixDummiesSections() { + Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); + size_t PhdrSize = sizeof(Elf_Phdr) * Phdrs.size(); + Out::ProgramHeaders->setSize(PhdrSize); +} + // Used for relocatable output (-r). In this case we create only ELF file // header, do not create program headers. Also assign of section addresses // is very straightforward: we just put all sections sequentually to the file. template void Writer::assignAddressesRelocatable() { - Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); uintX_t FileOff = 0; for (OutputSectionBase *Sec : OutputSections) FileOff = fixFileOff(FileOff, Sec->getAlign(), Sec); @@ -1395,10 +1404,6 @@ // Visits all headers in PhdrTable and assigns the adresses to // the output sections. Also creates common and special headers. template void Writer::assignAddresses() { - Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); - size_t PhdrSize = sizeof(Elf_Phdr) * Phdrs.size(); - Out::ProgramHeaders->setSize(PhdrSize); - uintX_t ThreadBssOffset = 0; uintX_t VA = Target->getVAStart(); uintX_t FileOff = 0;