Avoid accessing an end() iterator.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 17 Nov 2016 14:18:08 +0000 (14:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 17 Nov 2016 14:18:08 +0000 (14:18 +0000)
llvm-svn: 287225

lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/no-pt-load.s [new file with mode: 0644]

index c188dd9..2b7d246 100644 (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) {
         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 (file)
index 0000000..c704025
--- /dev/null
@@ -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