Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -1355,7 +1355,8 @@ Ret.push_back(std::move(RelRo)); // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. - if (!In::EhFrame->empty() && In::EhFrameHdr) + if (!In::EhFrame->empty() && In::EhFrameHdr && + In::EhFrame->OutSec && In::EhFrameHdr->OutSec) AddHdr(PT_GNU_EH_FRAME, In::EhFrameHdr->OutSec->getPhdrFlags()) ->add(In::EhFrameHdr->OutSec); Index: lld/trunk/test/ELF/linkerscript/pt_gnu_eh_frame.s =================================================================== --- lld/trunk/test/ELF/linkerscript/pt_gnu_eh_frame.s +++ lld/trunk/test/ELF/linkerscript/pt_gnu_eh_frame.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { /DISCARD/ : { *(.eh_frame*) *(.eh_frame_hdr*) } }" > %t.script +# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t + +.global _start +_start: + nop + +.section .dah,"ax",@progbits +.cfi_startproc + nop +.cfi_endproc