Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -367,6 +367,20 @@ Out::Bss->setSize(Off); } +template +static StringRef getOutputSection(InputSection *Sec) { + StringRef S = Sec->getSectionName(); + if (S.startswith(".text.")) + return ".text"; + if (S.startswith(".rodata.")) + return ".rodata"; + if (S.startswith(".data.")) + return ".data"; + if (S.startswith(".bss.")) + return ".bss"; + return S; +} + // Create output section objects and add them to OutputSections. template void Writer::createSections() { // .interp needs to be on the first page in the output file. @@ -401,7 +415,7 @@ continue; const Elf_Shdr *H = C->getSectionHdr(); uintX_t OutFlags = H->sh_flags & ~SHF_GROUP; - SectionKey Key{C->getSectionName(), H->sh_type, OutFlags}; + SectionKey Key{getOutputSection(C), H->sh_type, OutFlags}; OutputSection *&Sec = Map[Key]; if (!Sec) { Sec = new (CAlloc.Allocate()) Index: test/elf2/section-name.s =================================================================== --- /dev/null +++ test/elf2/section-name.s @@ -0,0 +1,30 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld2 %t -o %tout +# RUN: llvm-readobj -sections %tout | FileCheck %s +# REQUIRES: x86 + +.global _start +.text +_start: + +.section .text.a,"ax" +.section .text.,"ax" +.section .rodata.a,"a" +.section .rodata,"a" +.section .data.a,"aw" +.section .data,"aw" +.section .bss.a,"",@nobits +.section .bss,"",@nobits +.section .foo.a,"aw" +.section .foo,"aw" + +// CHECK: Name: .rodata +// CHECK-NOT: Name: .rodata.a +// CHECK: Name: .text +// CHECK-NOT: Name: .text.a +// CHECK: Name: .data +// CHECK-NOT: Name: .data.a +// CHECK: Name: .foo +// CHECK: Name: .foo +// CHECK: Name: .bss +// CHECK-NOT: Name: .bss.a