diff --git a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h index eb3d16ad9537..2390d08ebc91 100644 --- a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h @@ -108,10 +108,10 @@ void ExecutableWriter::finalizeDefaultAtomValues() { endAtomIter == this->_layout->absoluteAtoms().end()) && "Unable to find the absolute atoms that have been added by lld"); - auto phe = this->_programHeader->findProgramHeader( - llvm::ELF::PT_LOAD, llvm::ELF::PF_W, llvm::ELF::PF_X); + auto phe = this->_programHeader + ->findProgramHeader(llvm::ELF::PT_LOAD, llvm::ELF::PF_W, llvm::ELF::PF_X); - assert(!(phe == this->_programHeader->end()) && + assert(!(phe == this->_programHeader->rend()) && "Can't find a data segment in the program header!"); (*bssStartAtomIter)->_virtualAddr = (*phe)->p_vaddr + (*phe)->p_filesz; diff --git a/lld/lib/ReaderWriter/ELF/HeaderChunks.h b/lld/lib/ReaderWriter/ELF/HeaderChunks.h index 742f828e167d..90bf2108ea0c 100644 --- a/lld/lib/ReaderWriter/ELF/HeaderChunks.h +++ b/lld/lib/ReaderWriter/ELF/HeaderChunks.h @@ -89,6 +89,7 @@ class ProgramHeader : public Chunk { public: typedef llvm::object::Elf_Phdr_Impl Elf_Phdr; typedef typename std::vector::iterator PhIterT; + typedef typename std::reverse_iterator ReversePhIterT; /// \brief Find a program header entry, given the type of entry that /// we are looking for @@ -132,8 +133,9 @@ public: void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer); /// \brief find a program header entry in the list of program headers - PhIterT findProgramHeader(uint64_t type, uint64_t flags, uint64_t flagClear) { - return std::find_if(_ph.begin(), _ph.end(), + ReversePhIterT + findProgramHeader(uint64_t type, uint64_t flags, uint64_t flagClear) { + return std::find_if(_ph.rbegin(), _ph.rend(), FindPhdr(type, flags, flagClear)); } @@ -145,6 +147,10 @@ public: return _ph.end(); } + ReversePhIterT rbegin() { return _ph.rbegin(); } + + ReversePhIterT rend() { return _ph.rend(); } + virtual void doPreFlight() {} void finalize() {}