Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -92,6 +92,9 @@ template StringRef elf::getOutputSectionName(InputSectionBase *S) { StringRef Name = S->Name; + if (Config->Relocatable) + return Name; + for (StringRef V : {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.", ".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.", Index: test/ELF/relocatable-sections.s =================================================================== --- test/ELF/relocatable-sections.s +++ test/ELF/relocatable-sections.s @@ -0,0 +1,30 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld -r %t1.o -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +# CHECK: .text +# CHECK-NEXT: .text._init +# CHECK-NEXT: .text._fini +# CHECK-NEXT: .rela.text +# CHECK-NEXT: .rela.text._init +# CHECK-NEXT: .rela.text._fini + +.globl _start +_start: + call foo + nop + +.section .xxx,"a" + .quad 0 + +.section .text._init,"ax" + .quad .xxx +foo: + call bar + nop + + +.section .text._fini,"ax" + .quad .xxx +bar: + nop