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()) {
--- /dev/null
+# 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