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)); 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 static void reportDiscarded(InputSectionBase *IS) { @@ -343,6 +343,10 @@ reportDiscarded(IS); return; } + if (IS->kind() == InputSectionBase::EHFrame) { + In::EhFrame->addSection(IS); + return; + } SectionKey Key = createKey(IS, OutsecName); uint64_t Flags = getOutFlags(IS); @@ -360,12 +364,7 @@ } Sec->Flags |= Flags; } else { - uint32_t Type = IS->Type; - if (IS->kind() == InputSectionBase::EHFrame) { - In::EhFrame->addSection(IS); - return; - } - Sec = make(Key.Name, Type, Flags); + Sec = make(Key.Name, IS->Type, Flags); OutputSections.push_back(Sec); } 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",@progbits +.cfi_startproc + nop +.cfi_endproc