[PATCH] D89841: [ELF] --gc-sections: retain dependent sections of non-SHF_ALLOC sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 18:12:24 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

Fix http://lists.llvm.org/pipermail/llvm-dev/2020-October/145908.html

Currently non-SHF_ALLOC SHT_REL[A] (due to --emit-relocs) and SHF_LINK_ORDER are not
marked live.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89841

Files:
  lld/ELF/MarkLive.cpp
  lld/test/ELF/emit-relocs-gc.s
  lld/test/ELF/gc-sections-linkorder2.s


Index: lld/test/ELF/gc-sections-linkorder2.s
===================================================================
--- lld/test/ELF/gc-sections-linkorder2.s
+++ lld/test/ELF/gc-sections-linkorder2.s
@@ -14,3 +14,9 @@
 .quad 0
 .section .zed,"ao", at progbits,.foo
 .quad 0
+
+.section .nonalloc
+.quad 0
+
+.section .nonalloc_linkorder,"o", at progbits,.nonalloc
+.quad 0
Index: lld/test/ELF/emit-relocs-gc.s
===================================================================
--- lld/test/ELF/emit-relocs-gc.s
+++ lld/test/ELF/emit-relocs-gc.s
@@ -28,3 +28,6 @@
 .global _start
 _start:
  nop
+
+.section .nonalloc
+.quad .text
Index: lld/ELF/MarkLive.cpp
===================================================================
--- lld/ELF/MarkLive.cpp
+++ 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89841.299531.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/221ca35d/attachment.bin>


More information about the llvm-commits mailing list