diff options
author | Eugene Leviant <eleviant@accesssoftek.com> | 2017-03-14 08:49:09 +0000 |
---|---|---|
committer | Eugene Leviant <eleviant@accesssoftek.com> | 2017-03-14 08:49:09 +0000 |
commit | 30c1b436add85460c33b52565691adaa71a22236 (patch) | |
tree | 89ed83a01f6a2e7e7284ef3582b94052fbad2d46 | |
parent | 29685479972e71c1ff3442dbb11aed91186355bc (diff) | |
download | bcm5719-llvm-30c1b436add85460c33b52565691adaa71a22236.tar.gz bcm5719-llvm-30c1b436add85460c33b52565691adaa71a22236.zip |
[ELF] Fix crash when .eh_frame(_hdr) is discarded
lld crashes when .eh_frame or .eh_frame_hdr section is discarded
in linker script and there is no PHDRS directive.
Differential revision: https://reviews.llvm.org/D30885
llvm-svn: 297712
-rw-r--r-- | lld/ELF/Writer.cpp | 3 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/pt_gnu_eh_frame.s | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 344f86fa5ca..3375fc25b54 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1355,7 +1355,8 @@ template <class ELFT> std::vector<PhdrEntry> Writer<ELFT>::createPhdrs() { Ret.push_back(std::move(RelRo)); // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. - if (!In<ELFT>::EhFrame->empty() && In<ELFT>::EhFrameHdr) + if (!In<ELFT>::EhFrame->empty() && In<ELFT>::EhFrameHdr && + In<ELFT>::EhFrame->OutSec && In<ELFT>::EhFrameHdr->OutSec) AddHdr(PT_GNU_EH_FRAME, In<ELFT>::EhFrameHdr->OutSec->getPhdrFlags()) ->add(In<ELFT>::EhFrameHdr->OutSec); diff --git a/lld/test/ELF/linkerscript/pt_gnu_eh_frame.s b/lld/test/ELF/linkerscript/pt_gnu_eh_frame.s new file mode 100644 index 00000000000..81b4c6307d4 --- /dev/null +++ b/lld/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 |