Skip to content

Commit

Permalink
Allow .eh_frame_hdr to be placed before .eh_frame
Browse files Browse the repository at this point in the history
Differential revision: https://reviews.llvm.org/D24041

llvm-svn: 280203
  • Loading branch information
eleviant777 committed Aug 31, 2016
1 parent 30ff4b4 commit e4f590f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lld/ELF/Writer.cpp
Expand Up @@ -1306,8 +1306,13 @@ template <class ELFT> void Writer<ELFT>::writeSections() {
}

for (OutputSectionBase<ELFT> *Sec : OutputSections)
if (Sec != Out<ELFT>::Opd)
if (Sec != Out<ELFT>::Opd && Sec != Out<ELFT>::EhFrameHdr)
Sec->writeTo(Buf + Sec->getFileOff());

// The .eh_frame_hdr depends on .eh_frame section contents, therefore
// it should be written after .eh_frame is written.
if (!Out<ELFT>::EhFrame->empty() && Out<ELFT>::EhFrameHdr)
Out<ELFT>::EhFrameHdr->writeTo(Buf + Out<ELFT>::EhFrameHdr->getFileOff());
}

template <class ELFT> void Writer<ELFT>::writeBuildId() {
Expand Down
20 changes: 20 additions & 0 deletions lld/test/ELF/linkerscript/linkerscript-eh-frame-hdr.s
@@ -0,0 +1,20 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo "SECTIONS { \
# RUN: .eh_frame_hdr : {} \
# RUN: .eh_frame : {} \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t
# RUN: llvm-objdump -s -section=".eh_frame_hdr" %t1 | FileCheck %s

# CHECK: 0158 011b033b 14000000 01000000 49000000
# CHECK-NEXT: 0168 30000000

.global _start
_start:
nop

.section .dah,"ax",@progbits
.cfi_startproc
nop
.cfi_endproc

0 comments on commit e4f590f

Please sign in to comment.