From ac9fb458fb1e400e69b013474c1c1e9429ff88e3 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 25 Jan 2016 23:38:34 +0000 Subject: Define a helper function to make it visually shorter. NFC. llvm-svn: 258748 --- lld/ELF/OutputSections.cpp | 87 ++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index df54d0792df..a3160c3b89a 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -604,62 +604,60 @@ template void DynamicSection::finalize() { Out::DynStrTab->reserve(F->getSoName()); Out::DynStrTab->finalize(); + auto Add = [=](Entry E) { Entries.push_back(E); }; + if (Out::RelaDyn->hasRelocs()) { bool IsRela = Out::RelaDyn->isRela(); - Entries.push_back({IsRela ? DT_RELA : DT_REL, Out::RelaDyn}); - Entries.push_back( - {IsRela ? DT_RELASZ : DT_RELSZ, Out::RelaDyn->getSize()}); - Entries.push_back({IsRela ? DT_RELAENT : DT_RELENT, - uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); + Add({IsRela ? DT_RELA : DT_REL, Out::RelaDyn}); + Add({IsRela ? DT_RELASZ : DT_RELSZ, Out::RelaDyn->getSize()}); + Add({IsRela ? DT_RELAENT : DT_RELENT, + uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); } if (Out::RelaPlt && Out::RelaPlt->hasRelocs()) { - Entries.push_back({DT_JMPREL, Out::RelaPlt}); - Entries.push_back({DT_PLTRELSZ, Out::RelaPlt->getSize()}); - Entries.push_back({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, - Out::GotPlt}); - Entries.push_back( - {DT_PLTREL, Out::RelaPlt->isRela() ? DT_RELA : DT_REL}); + Add({DT_JMPREL, Out::RelaPlt}); + Add({DT_PLTRELSZ, Out::RelaPlt->getSize()}); + Add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, + Out::GotPlt}); + Add({DT_PLTREL, Out::RelaPlt->isRela() ? DT_RELA : DT_REL}); } - Entries.push_back({DT_SYMTAB, Out::DynSymTab}); - Entries.push_back({DT_SYMENT, sizeof(Elf_Sym)}); - Entries.push_back({DT_STRTAB, Out::DynStrTab}); - Entries.push_back({DT_STRSZ, Out::DynStrTab->getSize()}); + Add({DT_SYMTAB, Out::DynSymTab}); + Add({DT_SYMENT, sizeof(Elf_Sym)}); + Add({DT_STRTAB, Out::DynStrTab}); + Add({DT_STRSZ, Out::DynStrTab->getSize()}); if (Out::GnuHashTab) - Entries.push_back({DT_GNU_HASH, Out::GnuHashTab}); + Add({DT_GNU_HASH, Out::GnuHashTab}); if (Out::HashTab) - Entries.push_back({DT_HASH, Out::HashTab}); + Add({DT_HASH, Out::HashTab}); if (!Config->RPath.empty()) - Entries.push_back({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, - Out::DynStrTab->addString(Config->RPath)}); + Add({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, + Out::DynStrTab->addString(Config->RPath)}); if (!Config->SoName.empty()) - Entries.push_back( - {DT_SONAME, Out::DynStrTab->addString(Config->SoName)}); + Add({DT_SONAME, Out::DynStrTab->addString(Config->SoName)}); if (PreInitArraySec) { - Entries.push_back({DT_PREINIT_ARRAY, PreInitArraySec}); - Entries.push_back({DT_PREINIT_ARRAYSZ, PreInitArraySec->getSize()}); + Add({DT_PREINIT_ARRAY, PreInitArraySec}); + Add({DT_PREINIT_ARRAYSZ, PreInitArraySec->getSize()}); } if (InitArraySec) { - Entries.push_back({DT_INIT_ARRAY, InitArraySec}); - Entries.push_back({DT_INIT_ARRAYSZ, (uintX_t)InitArraySec->getSize()}); + Add({DT_INIT_ARRAY, InitArraySec}); + Add({DT_INIT_ARRAYSZ, (uintX_t)InitArraySec->getSize()}); } if (FiniArraySec) { - Entries.push_back({DT_FINI_ARRAY, FiniArraySec}); - Entries.push_back({DT_FINI_ARRAYSZ, (uintX_t)FiniArraySec->getSize()}); + Add({DT_FINI_ARRAY, FiniArraySec}); + Add({DT_FINI_ARRAYSZ, (uintX_t)FiniArraySec->getSize()}); } for (const std::unique_ptr> &F : SymTab.getSharedFiles()) if (F->isNeeded()) - Entries.push_back( - {DT_NEEDED, Out::DynStrTab->addString(F->getSoName())}); + Add({DT_NEEDED, Out::DynStrTab->addString(F->getSoName())}); if (SymbolBody *B = SymTab.find(Config->Init)) - Entries.push_back({DT_INIT, B}); + Add({DT_INIT, B}); if (SymbolBody *B = SymTab.find(Config->Fini)) - Entries.push_back({DT_FINI, B}); + Add({DT_FINI, B}); uint32_t DtFlags = 0; uint32_t DtFlags1 = 0; @@ -677,29 +675,26 @@ template void DynamicSection::finalize() { } if (DtFlags) - Entries.push_back({DT_FLAGS, DtFlags}); + Add({DT_FLAGS, DtFlags}); if (DtFlags1) - Entries.push_back({DT_FLAGS_1, DtFlags1}); + Add({DT_FLAGS_1, DtFlags1}); if (!Config->Entry.empty()) - Entries.push_back({DT_DEBUG, (uintX_t)0}); + Add({DT_DEBUG, (uintX_t)0}); if (Config->EMachine == EM_MIPS) { - Entries.push_back({DT_MIPS_RLD_VERSION, 1}); - Entries.push_back({DT_MIPS_FLAGS, RHF_NOTPOT}); - Entries.push_back({DT_MIPS_BASE_ADDRESS, (uintX_t)Target->getVAStart()}); - Entries.push_back( - {DT_MIPS_SYMTABNO, Out::DynSymTab->getNumSymbols()}); - Entries.push_back( - {DT_MIPS_LOCAL_GOTNO, Out::Got->getMipsLocalEntriesNum()}); + Add({DT_MIPS_RLD_VERSION, 1}); + Add({DT_MIPS_FLAGS, RHF_NOTPOT}); + Add({DT_MIPS_BASE_ADDRESS, (uintX_t)Target->getVAStart()}); + Add({DT_MIPS_SYMTABNO, Out::DynSymTab->getNumSymbols()}); + Add({DT_MIPS_LOCAL_GOTNO, Out::Got->getMipsLocalEntriesNum()}); if (const SymbolBody *B = Out::Got->getMipsFirstGlobalEntry()) - Entries.push_back({DT_MIPS_GOTSYM, B->DynamicSymbolTableIndex}); + Add({DT_MIPS_GOTSYM, B->DynamicSymbolTableIndex}); else - Entries.push_back( - {DT_MIPS_GOTSYM, Out::DynSymTab->getNumSymbols()}); - Entries.push_back({DT_PLTGOT, Out::Got}); + Add({DT_MIPS_GOTSYM, Out::DynSymTab->getNumSymbols()}); + Add({DT_PLTGOT, Out::Got}); if (Out::MipsRldMap) - Entries.push_back({DT_MIPS_RLD_MAP, Out::MipsRldMap}); + Add({DT_MIPS_RLD_MAP, Out::MipsRldMap}); } // +1 for DT_NULL -- cgit v1.2.1