From d8b81d6663a5675208d8ad8074cfacaf5e3b429c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 17 Nov 2016 14:18:08 +0000 Subject: [PATCH] Avoid accessing an end() iterator. llvm-svn: 287225 --- lld/ELF/LinkerScript.cpp | 4 +++- lld/test/ELF/linkerscript/no-pt-load.s | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/linkerscript/no-pt-load.s diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index c188dd9..2b7d246 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -706,8 +706,10 @@ void LinkerScript::assignAddresses(std::vector> &Phdrs) { std::find_if(Phdrs.begin(), Phdrs.end(), [](const PhdrEntry &E) { 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 // have both PHDRS and FILEHDR attributes then do nothing if (!Opt.PhdrsCommands.empty()) { diff --git a/lld/test/ELF/linkerscript/no-pt-load.s b/lld/test/ELF/linkerscript/no-pt-load.s new file mode 100644 index 0000000..c704025 --- /dev/null +++ b/lld/test/ELF/linkerscript/no-pt-load.s @@ -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 -- 2.7.4