Index: lld/ELF/MarkLive.cpp =================================================================== --- lld/ELF/MarkLive.cpp +++ lld/ELF/MarkLive.cpp @@ -71,12 +71,13 @@ SS->getFile()->IsNeeded = true; if (auto *D = dyn_cast(&B)) { - if (!D->Section) + auto *RelSec = dyn_cast_or_null(D->Section); + if (!RelSec) return; uint64_t Offset = D->Value; if (D->isSection()) Offset += getAddend(Sec, Rel); - Fn(cast(D->Section), Offset); + Fn(RelSec, Offset); return; } Index: lld/test/ELF/gc-sections-linker-defined-symbol.s =================================================================== --- lld/test/ELF/gc-sections-linker-defined-symbol.s +++ lld/test/ELF/gc-sections-linker-defined-symbol.s @@ -13,4 +13,6 @@ # CHECK-NEXT: Section: .dynamic .data + .globl g + g: .quad _end