[lld] r256373 - [ELF] Don't reclaim .ctors/.dtors sections.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 24 01:52:11 PST 2015


Author: davide
Date: Thu Dec 24 03:52:11 2015
New Revision: 256373

URL: http://llvm.org/viewvc/llvm-project?rev=256373&view=rev
Log:
[ELF] Don't reclaim .ctors/.dtors sections.

In FreeBSD, rtld expects .ctors containing -1 (0xffffffff), and a
.ctors section containing the correct bits is provided to the linker as
input (/usr/lib/crtbegin.o).

Contents of section .ctors:
 0000 ffffffff ffffffff                    ........

This section is not stripped even if not referenced or empty, also in
gold or ld.bfd. It would be nice to strip it when not needed but
since existing object files rely on that we can't do better to keep it
around.

Differential Revision:   http://reviews.llvm.org/D15767

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=256373&r1=256372&r2=256373&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Dec 24 03:52:11 2015
@@ -70,7 +70,8 @@ template <class ELFT> static bool isRese
     return true;
   default:
     StringRef S = Sec->getSectionName();
-    return S.startswith(".init") || S.startswith(".fini") ||
+    return 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=256373&r1=256372&r2=256373&view=diff
==============================================================================
--- lld/trunk/test/ELF/gc-sections.s (original)
+++ lld/trunk/test/ELF/gc-sections.s Thu Dec 24 03:52:11 2015
@@ -10,6 +10,8 @@
 
 # NOGC: Name: .eh_frame
 # NOGC: Name: .text
+# NOGC: Name: .ctors
+# NOGC: Name: .dtors
 # NOGC: Name: .init
 # NOGC: Name: .fini
 # NOGC: Name: a
@@ -23,6 +25,8 @@
 
 # GC1:     Name: .eh_frame
 # GC1:     Name: .text
+# GC1:     Name: .ctors
+# GC1:     Name: .dtors
 # GC1:     Name: .init
 # GC1:     Name: .fini
 # GC1:     Name: a
@@ -36,6 +40,8 @@
 
 # GC2:     Name: .eh_frame
 # GC2:     Name: .text
+# GC2:     Name: .ctors
+# GC2:     Name: .dtors
 # GC2:     Name: .init
 # GC2:     Name: .fini
 # GC2:     Name: a
@@ -77,6 +83,12 @@ x:
 y:
   call x
 
+.section .ctors,"aw", at progbits
+  .quad 0
+
+.section .dtors,"aw", at progbits
+  .quad 0
+
 .section .init,"aw", at init_array
   .quad 0
 




More information about the llvm-commits mailing list