Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1248,6 +1248,11 @@ H.p_memsz = alignTo(H.p_memsz, H.p_align); } } + + Phdrs.erase( + std::remove_if(Phdrs.begin(), Phdrs.end(), + [](Phdr &P) { return !P.First && P.H.p_type == PT_LOAD; }), + Phdrs.end()); } template static typename ELFT::uint getEntryAddr() { Index: test/ELF/linkerscript/empty-load.s =================================================================== --- test/ELF/linkerscript/empty-load.s +++ test/ELF/linkerscript/empty-load.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { .rw : { *(.rw) } .text : { *(.text) } }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -private-headers %t1 | FileCheck %s + +## We expect 2 PT_LOAD segments +# CHECK: PHDR +# CHECK-NEXT: filesz +# CHECK-NEXT: LOAD +# CHECK-NEXT: filesz +# CHECK-NEXT: LOAD +# CHECK-NEXT: filesz +# CHECK-NEXT: STACK +# CHECK-NEXT: filesz + +.globl _start +_start: + jmp _start + +.section .rw, "aw" + .quad 0