Skip to content

Commit

Permalink
[ELF] - Do not try to create .eh_frame_hdr for relocatable output.
Browse files Browse the repository at this point in the history
.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

llvm-svn: 297365
  • Loading branch information
George Rimar committed Mar 9, 2017
1 parent e2de03f commit 1c74c2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lld/ELF/Writer.cpp
Expand Up @@ -435,12 +435,11 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
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);
}
Expand Down
11 changes: 11 additions & 0 deletions lld/test/ELF/relocatable-eh-frame-hdr.s
@@ -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",@progbits
.cfi_startproc
.cfi_endproc

0 comments on commit 1c74c2f

Please sign in to comment.