[lld] r298154 - [ELF] Restore GC handling of LINK_ORDER, C-named sections.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 15:04:52 PDT 2017


Author: eugenis
Date: Fri Mar 17 17:04:52 2017
New Revision: 298154

URL: http://llvm.org/viewvc/llvm-project?rev=298154&view=rev
Log:
[ELF] Restore GC handling of LINK_ORDER, C-named sections.

__start_xxx symbol keeps section xxx alive only if it is not
SHF_LINK_ORDER. Such sections can be used for user metadata, when
__start_xxx is used to iterate over section contents at runtime, and
the liveness is determined solely by the linked (associated) section.

This was earlier implemented in r294592, and broken in r296723.

Differential Revision: https://reviews.llvm.org/D30964

Added:
    lld/trunk/test/ELF/gc-sections-metadata-startstop.s
Modified:
    lld/trunk/ELF/MarkLive.cpp

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=298154&r1=298153&r2=298154&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Fri Mar 17 17:04:52 2017
@@ -175,9 +175,6 @@ template <class ELFT> static bool isRese
   case SHT_PREINIT_ARRAY:
     return true;
   default:
-    if (Sec->Flags & SHF_LINK_ORDER)
-      return false;
-
     if (!(Sec->Flags & SHF_ALLOC))
       return true;
 
@@ -247,6 +244,8 @@ template <class ELFT> void elf::markLive
     // referred by .eh_frame here.
     if (auto *EH = dyn_cast_or_null<EhInputSection>(Sec))
       scanEhFrameSection<ELFT>(*EH, Enqueue);
+    if (Sec->Flags & SHF_LINK_ORDER)
+      continue;
     if (isReserved<ELFT>(Sec) || Script<ELFT>::X->shouldKeep(Sec))
       Enqueue({Sec, 0});
     else if (isValidCIdentifier(Sec->Name)) {

Added: lld/trunk/test/ELF/gc-sections-metadata-startstop.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-metadata-startstop.s?rev=298154&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-metadata-startstop.s (added)
+++ lld/trunk/test/ELF/gc-sections-metadata-startstop.s Fri Mar 17 17:04:52 2017
@@ -0,0 +1,33 @@
+# LINK_ORDER cnamed sections are not kept alive by the __start_* reference.
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld --gc-sections %t.o -o %t
+# RUN: llvm-objdump -section-headers -t %t | FileCheck  %s
+
+# CHECK: Sections:
+# CHECK-NOT: yy
+# CHECK: xx {{.*}} DATA
+# CHECK-NOT: yy
+
+# CHECK: SYMBOL TABLE:
+# CHECK: xx 00000000 __start_xx
+# CHECK: w *UND* 00000000 __start_yy
+
+.weak __start_xx
+.weak __start_yy
+
+.global _start
+_start:
+.quad __start_xx
+.quad __start_yy
+
+.section xx,"a"
+.quad 0
+
+.section .foo,"a"
+.quad 0
+
+.section yy,"am", at progbits,.foo
+.quad 0
+




More information about the llvm-commits mailing list