From 703296aedaaa9cc4e991c4a0d50abd0b125b22c4 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 20 Jul 2016 19:36:39 +0000 Subject: [PATCH] Return a vector from createPhdrs instead of return nothing. This way is consistent with createSections. llvm-svn: 276164 --- lld/ELF/Writer.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 4cb1406..63489cc 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -56,7 +56,7 @@ private: void addPredefinedSections(); bool needsGot(); - void createPhdrs(); + std::vector createPhdrs(); void assignAddresses(); void assignFileOffsets(); void setPhdrs(); @@ -231,10 +231,9 @@ template void Writer::run() { if (Config->Relocatable) { assignFileOffsets(); } else { - if (Script::X->hasPhdrsCommands()) - Phdrs = Script::X->createPhdrs(OutputSections); - else - createPhdrs(); + Phdrs = Script::X->hasPhdrsCommands() + ? Script::X->createPhdrs(OutputSections) + : createPhdrs(); fixHeaders(); if (ScriptConfig->DoLayout) { Script::X->assignAddresses(OutputSections); @@ -949,9 +948,13 @@ template bool elf::needsPtLoad(OutputSectionBase *Sec) { // Decide which program headers to create and which sections to include in each // one. -template void Writer::createPhdrs() { - auto AddHdr = [this](unsigned Type, unsigned Flags) { - return &*Phdrs.emplace(Phdrs.end(), Type, Flags); +template +std::vector> Writer::createPhdrs() { + std::vector Ret; + + auto AddHdr = [&](unsigned Type, unsigned Flags) -> Phdr * { + Ret.emplace_back(Type, Flags); + return &Ret.back(); }; // The first phdr entry is PT_PHDR which describes the program header itself. @@ -1003,7 +1006,7 @@ template void Writer::createPhdrs() { // Add the TLS segment unless it's empty. if (TlsHdr.First) - Phdrs.push_back(std::move(TlsHdr)); + Ret.push_back(std::move(TlsHdr)); // Add an entry for .dynamic. if (isOutputDynamic()) { @@ -1014,7 +1017,7 @@ template void Writer::createPhdrs() { // PT_GNU_RELRO includes all sections that should be marked as // read-only by dynamic linker after proccessing relocations. if (RelRo.First) - Phdrs.push_back(std::move(RelRo)); + Ret.push_back(std::move(RelRo)); // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. if (!Out::EhFrame->empty() && Out::EhFrameHdr) { @@ -1029,7 +1032,8 @@ template void Writer::createPhdrs() { AddHdr(PT_GNU_STACK, PF_R | PF_W); if (Note.First) - Phdrs.push_back(std::move(Note)); + Ret.push_back(std::move(Note)); + return Ret; } // The first section of each PT_LOAD and the first section after PT_GNU_RELRO -- 2.7.4