Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -624,6 +624,11 @@ if (CurAddressState->OutSec->Flags & SHF_COMPRESSED) return; + // The Size was previously calculated for compressed debug sections. We now + // reset it, because unused synthetic sections may have since been removed, + // leaving the Size invalid. + Sec->Size = 0; + for (BaseCommand *C : Sec->Commands) process(*C); } Index: test/ELF/linkerscript/unused-synthetic.s =================================================================== --- test/ELF/linkerscript/unused-synthetic.s +++ test/ELF/linkerscript/unused-synthetic.s @@ -13,6 +13,16 @@ # CHECK: .text # CHECK-NEXT: .dynsym +# Test that the size of a removed unused synthetic input section does not get +# added to the output section size, if the output section has symbol +# assignments, preventing removal of the output section. +# RUN: echo "SECTIONS { \ +# RUN: .got.plt : { a_sym = .; *(.got.plt) } \ +# RUN: }" > %t2.script +# RUN: ld.lld -shared -o %t2.so --script %t2.script %t.o +# RUN: llvm-objdump -section-headers %t2.so | FileCheck %s --check-prefix=CHECK2 +# CHECK2: .got.plt 00000000 + .global _start _start: nop