diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -370,8 +370,11 @@ bool isLinkOrder = (sec->flags & SHF_LINK_ORDER); bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA); - if (!isAlloc && !isLinkOrder && !isRel && !sec->nextInSectionGroup) + if (!isAlloc && !isLinkOrder && !isRel && !sec->nextInSectionGroup) { sec->markLive(); + for (InputSection *isec : sec->dependentSections) + isec->markLive(); + } } // Follow the graph to mark all live sections. diff --git a/lld/test/ELF/emit-relocs-gc.s b/lld/test/ELF/emit-relocs-gc.s --- a/lld/test/ELF/emit-relocs-gc.s +++ b/lld/test/ELF/emit-relocs-gc.s @@ -28,3 +28,6 @@ .global _start _start: nop + +.section .nonalloc +.quad .text diff --git a/lld/test/ELF/gc-sections-linkorder2.s b/lld/test/ELF/gc-sections-linkorder2.s --- a/lld/test/ELF/gc-sections-linkorder2.s +++ b/lld/test/ELF/gc-sections-linkorder2.s @@ -14,3 +14,9 @@ .quad 0 .section .zed,"ao",@progbits,.foo .quad 0 + +.section .nonalloc +.quad 0 + +.section .nonalloc_linkorder,"o",@progbits,.nonalloc +.quad 0