Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -498,7 +498,9 @@ // When control reaches here, mergeable sections have already been merged into // synthetic sections. For relocatable case we want to create one output // section per syntetic section so that they have a valid sh_entsize. - if (Config->Relocatable && (IS->Flags & SHF_MERGE)) + if (Config->Relocatable && (IS->Flags & SHF_MERGE) && + !((IS->Flags & SHF_STRINGS) && + (IS->Name.startswith(".debug") || IS->Name.startswith(".zdebug")))) return createSection(IS, OutsecName); // The ELF spec just says Index: test/ELF/merge-relocatable-O0.s =================================================================== --- test/ELF/merge-relocatable-O0.s +++ test/ELF/merge-relocatable-O0.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o +# RUN: ld.lld -r -O0 %t.o %t2.o -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=RODATA +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=DEBUG_STR + +# RODATA: .rodata.1 +# RODATA: .rodata.1 +# DEBUG_STR: .debug_str +# DEBUG_STR-NOT: .debug_str + +.section .rodata.1,"aM",@progbits,4 + .align 4 + .long 0x42 +.section .debug_str,"MS",@progbits,1 + .asciz "string"