From: Rui Ueyama Date: Tue, 1 Nov 2016 23:17:45 +0000 (+0000) Subject: Split writeResult. NFC. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f83aca42e6bf4aff0af10a5f8d0844896928c32a;p=platform%2Fupstream%2Fllvm.git Split writeResult. NFC. This is now doable because this code doesn't have to be in the dynamic scope of Writer::run(). llvm-svn: 285766 --- diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 186bb34..5a74403 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -49,6 +49,7 @@ public: private: typedef PhdrEntry Phdr; + void createSyntheticSections(); void copyLocalSymbols(); void addReservedSymbols(); void addInputSec(InputSectionBase *S); @@ -126,83 +127,6 @@ template static bool needsInterpSection() { } template void elf::writeResult() { - typedef typename ELFT::uint uintX_t; - typedef typename ELFT::Ehdr Elf_Ehdr; - - // Initialize all pointers with NULL. - memset(&Out::First, 0, sizeof(Out)); - - // Create singleton output sections. - Out::Bss = - make>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); - Out::Dynamic = make>(); - Out::EhFrame = make>(); - Out::Got = make>(); - Out::Plt = make>(); - Out::RelaDyn = make>( - Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); - Out::ShStrTab = make>(".shstrtab", false); - Out::VerSym = make>(); - Out::VerNeed = make>(); - - Out::ElfHeader = make>("", 0, SHF_ALLOC); - Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); - Out::ProgramHeaders = make>("", 0, SHF_ALLOC); - Out::ProgramHeaders->updateAlignment(sizeof(uintX_t)); - - if (needsInterpSection()) - Out::Interp = make>(); - - if (!Symtab::X->getSharedFiles().empty() || Config->Pic) { - Out::DynStrTab = make>(".dynstr", true); - Out::DynSymTab = - make>(*Out::DynStrTab); - } - - if (Config->EhFrameHdr) - Out::EhFrameHdr = make>(); - - if (Config->GnuHash) - Out::GnuHashTab = make>(); - if (Config->SysvHash) - Out::HashTab = make>(); - if (Config->GdbIndex) - Out::GdbIndex = make>(); - - StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt"; - Out::GotPlt = make>(); - Out::RelaPlt = make>(S, false /*Sort*/); - if (Config->Strip != StripPolicy::All) { - Out::StrTab = make>(".strtab", false); - Out::SymTab = make>(*Out::StrTab); - } - - if (Config->EMachine == EM_MIPS && !Config->Shared) { - // This is a MIPS specific section to hold a space within the data segment - // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry. - // See "Dynamic section" in Chapter 5 in the following document: - // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf - Out::MipsRldMap = make>(".rld_map", SHT_PROGBITS, - SHF_ALLOC | SHF_WRITE); - Out::MipsRldMap->setSize(sizeof(uintX_t)); - Out::MipsRldMap->updateAlignment(sizeof(uintX_t)); - } - if (!Config->VersionDefinitions.empty()) - Out::VerDef = make>(); - - // Initialize linker generated sections - if (Config->BuildId == BuildIdKind::Fast) - In::BuildId = make>(); - else if (Config->BuildId == BuildIdKind::Md5) - In::BuildId = make>(); - else if (Config->BuildId == BuildIdKind::Sha1) - In::BuildId = make>(); - else if (Config->BuildId == BuildIdKind::Uuid) - In::BuildId = make>(); - else if (Config->BuildId == BuildIdKind::Hexstring) - In::BuildId = make>(); - In::Sections = {In::BuildId}; - Writer().run(); } @@ -216,6 +140,7 @@ template static std::vector getCommonSymbols() { // The main function of the writer. template void Writer::run() { + createSyntheticSections(); addReservedSymbols(); if (Target->NeedsThunks) @@ -284,6 +209,84 @@ template void Writer::run() { } } +// Initialize Out members. +template void Writer::createSyntheticSections() { + // Initialize all pointers with NULL. This is needed because + // you can call lld::elf::main more than once as a library. + memset(&Out::First, 0, sizeof(Out)); + + // Create singleton output sections. + Out::Bss = + make>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); + Out::Dynamic = make>(); + Out::EhFrame = make>(); + Out::Got = make>(); + Out::Plt = make>(); + Out::RelaDyn = make>( + Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); + Out::ShStrTab = make>(".shstrtab", false); + Out::VerSym = make>(); + Out::VerNeed = make>(); + + Out::ElfHeader = make>("", 0, SHF_ALLOC); + Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); + Out::ProgramHeaders = make>("", 0, SHF_ALLOC); + Out::ProgramHeaders->updateAlignment(sizeof(uintX_t)); + + if (needsInterpSection()) + Out::Interp = make>(); + + if (!Symtab::X->getSharedFiles().empty() || Config->Pic) { + Out::DynStrTab = make>(".dynstr", true); + Out::DynSymTab = + make>(*Out::DynStrTab); + } + + if (Config->EhFrameHdr) + Out::EhFrameHdr = make>(); + + if (Config->GnuHash) + Out::GnuHashTab = make>(); + if (Config->SysvHash) + Out::HashTab = make>(); + if (Config->GdbIndex) + Out::GdbIndex = make>(); + + StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt"; + Out::GotPlt = make>(); + Out::RelaPlt = make>(S, false /*Sort*/); + if (Config->Strip != StripPolicy::All) { + Out::StrTab = make>(".strtab", false); + Out::SymTab = make>(*Out::StrTab); + } + + if (Config->EMachine == EM_MIPS && !Config->Shared) { + // This is a MIPS specific section to hold a space within the data segment + // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry. + // See "Dynamic section" in Chapter 5 in the following document: + // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf + Out::MipsRldMap = make>(".rld_map", SHT_PROGBITS, + SHF_ALLOC | SHF_WRITE); + Out::MipsRldMap->setSize(sizeof(uintX_t)); + Out::MipsRldMap->updateAlignment(sizeof(uintX_t)); + } + if (!Config->VersionDefinitions.empty()) + Out::VerDef = make>(); + + // Initialize linker generated sections + if (Config->BuildId == BuildIdKind::Fast) + In::BuildId = make>(); + else if (Config->BuildId == BuildIdKind::Md5) + In::BuildId = make>(); + else if (Config->BuildId == BuildIdKind::Sha1) + In::BuildId = make>(); + else if (Config->BuildId == BuildIdKind::Uuid) + In::BuildId = make>(); + else if (Config->BuildId == BuildIdKind::Hexstring) + In::BuildId = make>(); + In::Sections = {In::BuildId}; +} + template static bool shouldKeepInSymtab(InputSectionBase *Sec, StringRef SymName, const SymbolBody &B) {