Avoid accessing an end() iterator.

llvm-svn: 287225
This commit is contained in:
Rafael Espindola 2016-11-17 14:18:08 +00:00
parent 67ef3b984a
commit d8b81d6663
2 changed files with 8 additions and 1 deletions

View File

@ -706,8 +706,10 @@ void LinkerScript<ELFT>::assignAddresses(std::vector<PhdrEntry<ELFT>> &Phdrs) {
std::find_if(Phdrs.begin(), Phdrs.end(), [](const PhdrEntry<ELFT> &E) { std::find_if(Phdrs.begin(), Phdrs.end(), [](const PhdrEntry<ELFT> &E) {
return E.H.p_type == PT_LOAD; return E.H.p_type == PT_LOAD;
}); });
if (FirstPTLoad == Phdrs.end())
return;
if (HeaderSize <= MinVA && FirstPTLoad != Phdrs.end()) { if (HeaderSize <= MinVA) {
// If linker script specifies program headers and first PT_LOAD doesn't // If linker script specifies program headers and first PT_LOAD doesn't
// have both PHDRS and FILEHDR attributes then do nothing // have both PHDRS and FILEHDR attributes then do nothing
if (!Opt.PhdrsCommands.empty()) { if (!Opt.PhdrsCommands.empty()) {

View File

@ -0,0 +1,5 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "PHDRS {foo PT_DYNAMIC ;} " \
# RUN: "SECTIONS { .text : { *(.text) } : foo }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t.o