[lld] r282391 - Linkerscript: do not GC non-allocated sections

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 26 01:32:41 PDT 2016


Author: evgeny777
Date: Mon Sep 26 03:32:41 2016
New Revision: 282391

URL: http://llvm.org/viewvc/llvm-project?rev=282391&view=rev
Log:
Linkerscript: do not GC non-allocated sections

Differential revision: https://reviews.llvm.org/D24733

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

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=282391&r1=282390&r2=282391&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Mon Sep 26 03:32:41 2016
@@ -166,8 +166,9 @@ scanEhFrameSection(EhInputSection<ELFT>
     scanEhFrameSection(EH, EObj.rels(EH.RelocSection), Enqueue);
 }
 
-// Sections listed below are special because they are used by the loader
-// just by being in an ELF file. They should not be garbage-collected.
+// We do not garbage-collect two types of sections:
+// 1) Sections used by the loader (.init, .fini, .ctors, .dtors, .jcr)
+// 2) Not allocatable sections which typically contain debugging information
 template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
   switch (Sec->getSectionHdr()->sh_type) {
   case SHT_FINI_ARRAY:
@@ -183,7 +184,8 @@ template <class ELFT> static bool isRese
     if (isValidCIdentifier(S))
       return true;
 
-    return S.startswith(".ctors") || S.startswith(".dtors") ||
+    bool IsAllocSec = Sec->getSectionHdr()->sh_flags & SHF_ALLOC;
+    return !IsAllocSec || S.startswith(".ctors") || S.startswith(".dtors") ||
            S.startswith(".init") || S.startswith(".fini") ||
            S.startswith(".jcr");
   }

Modified: lld/trunk/test/ELF/gc-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections.s?rev=282391&r1=282390&r2=282391&view=diff
==============================================================================
--- lld/trunk/test/ELF/gc-sections.s (original)
+++ lld/trunk/test/ELF/gc-sections.s Mon Sep 26 03:32:41 2016
@@ -14,6 +14,8 @@
 # NOGC: Name: .dtors
 # NOGC: Name: .init
 # NOGC: Name: .fini
+# NOGC: Name: .debug_pubtypes
+# NOGC: Name: .comment
 # NOGC: Name: a
 # NOGC: Name: b
 # NOGC: Name: c
@@ -29,6 +31,8 @@
 # GC1:     Name: .dtors
 # GC1:     Name: .init
 # GC1:     Name: .fini
+# GC1:     Name: .debug_pubtypes
+# GC1:     Name: .comment
 # GC1:     Name: a
 # GC1:     Name: b
 # GC1:     Name: c
@@ -44,6 +48,8 @@
 # GC2:     Name: .dtors
 # GC2:     Name: .init
 # GC2:     Name: .fini
+# GC2:     Name: .debug_pubtypes
+# GC2:     Name: .comment
 # GC2:     Name: a
 # GC2:     Name: b
 # GC2:     Name: c
@@ -100,3 +106,9 @@ y:
 
 .section .eh_frame,"a", at unwind
   .quad 0
+
+.section .debug_pubtypes,"", at progbits
+  .quad 0
+
+.section .comment,"MS", at progbits,8
+  .quad 0




More information about the llvm-commits mailing list