Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -555,6 +555,9 @@ // other REL[A] sections created by linker itself. if (!isa(IS) && (IS->Type == SHT_REL || IS->Type == SHT_RELA)) { + if (!Config->Relocatable && + OutsecName.find(".eh_frame") != std::string::npos) + return createSection(IS, OutsecName); auto *Sec = cast(IS); OutputSection *Out = Sec->getRelocatedSection()->getOutputSection(); Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -98,6 +98,8 @@ !isa(S)) { OutputSection *Out = cast(S)->getRelocatedSection()->getOutputSection(); + if (!Out) + return S->Name; if (S->Type == SHT_RELA) return Saver.save(".rela" + Out->Name); return Saver.save(".rel" + Out->Name); Index: test/ELF/emit-relocs-eh-frame.s =================================================================== --- /dev/null +++ test/ELF/emit-relocs-eh-frame.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld --emit-relocs %t1.o -o %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section {{.*}} .rela.eh_frame { +# CHECK-NEXT: 0x{{.*}} R_X86_64_PC32 .text 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.globl _start +.text +_start: + .cfi_startproc + nop + .cfi_endproc Index: test/ELF/linkerscript/eh-frame-emit-relocs.s =================================================================== --- /dev/null +++ test/ELF/linkerscript/eh-frame-emit-relocs.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: echo "SECTIONS { .foo : { *(.eh_frame) } }" > %t.script +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld --emit-relocs %t.o -T %t.script -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +# CHECK-NOT: eh_frame +# CHECK: .rela.foo +# CHECK-NOT: eh_frame + +.text + .cfi_startproc + .cfi_endproc