[lld] r297365 - [ELF] - Do not try to create .eh_frame_hdr for relocatable output.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 00:45:26 PST 2017


Author: grimar
Date: Thu Mar  9 02:45:25 2017
New Revision: 297365

URL: http://llvm.org/viewvc/llvm-project?rev=297365&view=rev
Log:
[ELF] - Do not try to create .eh_frame_hdr for relocatable output.

.eh_frame_hdr is a header constructed for .eh_frame sections.
We do not proccess .eh_frame when doing relocatable output,
so should not try to create .eh_frame_hdr too.
Previous behavior without this patch is segfault.

Fixes PR32118.

Differential revision: https://reviews.llvm.org/D30566

Added:
    lld/trunk/test/ELF/relocatable-eh-frame-hdr.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297365&r1=297364&r2=297365&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Mar  9 02:45:25 2017
@@ -435,12 +435,11 @@ template <class ELFT> void Writer<ELFT>:
   In<ELFT>::Iplt = make<PltSection<ELFT>>(0);
   Add(In<ELFT>::Iplt);
 
-  if (Config->EhFrameHdr) {
-    In<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>();
-    Add(In<ELFT>::EhFrameHdr);
-  }
-
   if (!Config->Relocatable) {
+    if (Config->EhFrameHdr) {
+      In<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>();
+      Add(In<ELFT>::EhFrameHdr);
+    }
     In<ELFT>::EhFrame = make<EhFrameSection<ELFT>>();
     Add(In<ELFT>::EhFrame);
   }

Added: lld/trunk/test/ELF/relocatable-eh-frame-hdr.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-eh-frame-hdr.s?rev=297365&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-eh-frame-hdr.s (added)
+++ lld/trunk/test/ELF/relocatable-eh-frame-hdr.s Thu Mar  9 02:45:25 2017
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld --eh-frame-hdr -r %t.o -o %t
+# RUN: llvm-readobj -s %t | FileCheck %s
+
+# CHECK:       Sections [
+# CHECK-NOT:    Name: .eh_frame_hdr
+
+.section .foo,"ax", at progbits
+.cfi_startproc
+.cfi_endproc




More information about the llvm-commits mailing list