[PATCH] D30885: [ELF] Fix crash when eh_frame or eh_frame_hdr is discarded in linker script
    Eugene Leviant via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Mon Mar 13 04:47:28 PDT 2017
    
    
  
evgeny777 created this revision.
evgeny777 added a project: lld.
This crash was introduced by https://reviews.llvm.org/D30627
Repository:
  rL LLVM
https://reviews.llvm.org/D30885
Files:
  ELF/Writer.cpp
  test/ELF/linkerscript/pt_gnu_eh_frame.s
Index: test/ELF/linkerscript/pt_gnu_eh_frame.s
===================================================================
--- test/ELF/linkerscript/pt_gnu_eh_frame.s
+++ test/ELF/linkerscript/pt_gnu_eh_frame.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { \
+# RUN:          /DISCARD/ : { *(.eh_frame*) *(.eh_frame_hdr*) } \
+# RUN:       }" > %t.script
+# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t
+
+.global _start
+_start:
+ nop
+
+.section .dah,"ax", at progbits
+.cfi_startproc
+ nop
+.cfi_endproc
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1350,7 +1350,8 @@
     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);
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30885.91535.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170313/1246be94/attachment.bin>
    
    
More information about the llvm-commits
mailing list