[PATCH] D30627: [ELF] Properly handle .eh_frame in linker scripts
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 5 17:27:52 PST 2017
phosek created this revision.
phosek added a project: lld.
Using .eh_frame input section pattern in linker script currently causes a crash; this is because .eh_frame input sections require special handling since they're all combined into a synthetic section rather than regular output section.
Repository:
rL LLVM
https://reviews.llvm.org/D30627
Files:
ELF/LinkerScript.cpp
ELF/OutputSections.cpp
test/ELF/linkerscript/eh-frame.s
Index: test/ELF/linkerscript/eh-frame.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/eh-frame.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { \
+# RUN: .eh_frame : { *(.eh_frame) } \
+# RUN: }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -s -section=".eh_frame" %t1 | FileCheck %s
+
+# CHECK: 0000 14000000 00000000 017a5200 01781001
+# CHECK-NEXT: 0010 1b0c0708 90010000
+
+.global _start
+_start:
+ nop
+
+.section .dah,"ax", at progbits
+.cfi_startproc
+ nop
+.cfi_endproc
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -326,7 +326,7 @@
static bool canMergeToProgbits(unsigned Type) {
return Type == SHT_NOBITS || Type == SHT_PROGBITS || Type == SHT_INIT_ARRAY ||
Type == SHT_PREINIT_ARRAY || Type == SHT_FINI_ARRAY ||
- Type == SHT_NOTE;
+ Type == SHT_NOTE || Type == SHT_X86_64_UNWIND;
}
template <class ELFT> static void reportDiscarded(InputSectionBase *IS) {
@@ -343,6 +343,10 @@
reportDiscarded<ELFT>(IS);
return;
}
+ if (IS->kind() == InputSectionBase::EHFrame) {
+ In<ELFT>::EhFrame->addSection(IS);
+ return;
+ }
SectionKey Key = createKey<ELFT>(IS, OutsecName);
uint64_t Flags = getOutFlags<ELFT>(IS);
@@ -360,12 +364,7 @@
}
Sec->Flags |= Flags;
} else {
- uint32_t Type = IS->Type;
- if (IS->kind() == InputSectionBase::EHFrame) {
- In<ELFT>::EhFrame->addSection(IS);
- return;
- }
- Sec = make<OutputSection>(Key.Name, Type, Flags);
+ Sec = make<OutputSection>(Key.Name, IS->Type, Flags);
OutputSections.push_back(Sec);
}
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -493,6 +493,11 @@
if (Sec->empty())
continue;
+ // We skip all eh_frame input sections since those are part of and handled
+ // by the EhFrameSection synthetic section.
+ if (IB->kind() == InputSectionBase::EHFrame)
+ continue;
+
if (!IB->Live)
continue;
assert(CurOutSec == IB->OutSec || AlreadyOutputOS.count(IB->OutSec));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30627.90632.patch
Type: text/x-patch
Size: 2368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170306/06cea9fa/attachment.bin>
More information about the llvm-commits
mailing list