Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -291,6 +291,9 @@ size_t SizeBefore = Ret.size(); for (InputSectionBase *Sec : InputSections) { + if (!isa(Sec)) + continue; + if (Sec->Assigned) continue; Index: test/ELF/linkerscript/merge-sections.s =================================================================== --- test/ELF/linkerscript/merge-sections.s +++ test/ELF/linkerscript/merge-sections.s @@ -31,6 +31,16 @@ # 0x19E = begin + sizeof(.foo) = 0x190 + 0xE # CHECK-NEXT: Value: 0x19E +# Check that we don't crash with --gc-sections +# RUN: ld.lld -gc-sections -o %t2 --script %t.script %t -shared +# RUN: llvm-readobj -s -t %t2 | FileCheck %s --check-prefix=GC + +# GC: Name: .foo +# GC-NEXT: Type: SHT_PROGBITS +# GC-NEXT: Flags [ +# GC-NEXT: SHF_ALLOC +# GC-NEXT: ] + .section .foo.1a,"aMS",@progbits,1 .asciz "foo"