Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -93,6 +93,10 @@ !Name.startswith(".debug_")) return; + // We call maybeCompress() early and for linkerscript case need to assign offsets, + // because that was not done yet. That finalizes mergeable synthetic sections. + assignOffsets(); + // Create a section header. ZDebugHeader.resize(sizeof(Elf_Chdr)); auto *Hdr = reinterpret_cast(ZDebugHeader.data()); Index: test/ELF/linkerscript/Inputs/compress-debug-sections.s =================================================================== --- test/ELF/linkerscript/Inputs/compress-debug-sections.s +++ test/ELF/linkerscript/Inputs/compress-debug-sections.s @@ -0,0 +1,5 @@ +.section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "CCCCCCCCCCCCCCCCCCCCCCCCCCC" +.Linfo_string1: + .asciz "DDDDDDDDDDDDDDDDDDDDDDDDDDD" Index: test/ELF/linkerscript/compress-debug-sections.s =================================================================== --- test/ELF/linkerscript/compress-debug-sections.s +++ test/ELF/linkerscript/compress-debug-sections.s @@ -0,0 +1,20 @@ +# REQUIRES: x86, zlib + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +# RUN: %S/Inputs/compress-debug-sections.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +# RUN: echo "SECTIONS { .debug_str 0 : { *(.debug_str) } }" > %t.script +# RUN: ld.lld %t1.o %t2.o %t.script -o %t --compress-debug-sections=zlib + +# RUN: llvm-dwarfdump %t -debug-dump=str | FileCheck %s +# CHECK: .debug_str contents: +# CHECK-NEXT: CCCCCCCCCCCCCCCCCCCCCCCCCCC +# CHECK-NEXT: DDDDDDDDDDDDDDDDDDDDDDDDDDD +# CHECK-NEXT: AAAAAAAAAAAAAAAAAAAAAAAAAAA +# CHECK-NEXT: BBBBBBBBBBBBBBBBBBBBBBBBBBB + +.section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "AAAAAAAAAAAAAAAAAAAAAAAAAAA" +.Linfo_string1: + .asciz "BBBBBBBBBBBBBBBBBBBBBBBBBBB"