[lld] r287225 - Avoid accessing an end() iterator.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 06:18:08 PST 2016


Author: rafael
Date: Thu Nov 17 08:18:08 2016
New Revision: 287225

URL: http://llvm.org/viewvc/llvm-project?rev=287225&view=rev
Log:
Avoid accessing an end() iterator.

Added:
    lld/trunk/test/ELF/linkerscript/no-pt-load.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=287225&r1=287224&r2=287225&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Nov 17 08:18:08 2016
@@ -706,8 +706,10 @@ void LinkerScript<ELFT>::assignAddresses
       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()) {

Added: lld/trunk/test/ELF/linkerscript/no-pt-load.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/no-pt-load.s?rev=287225&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/no-pt-load.s (added)
+++ lld/trunk/test/ELF/linkerscript/no-pt-load.s Thu Nov 17 08:18:08 2016
@@ -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




More information about the llvm-commits mailing list