[lld] 48161b7 - [ELF] --gc-sections: Work around SHT_PROGBITS .init_array

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 21 10:44:35 PST 2021


Author: Fangrui Song
Date: 2021-12-21T10:44:29-08:00
New Revision: 48161b7490e4aa174faf2b0e840e743a3ee56a4a

URL: https://github.com/llvm/llvm-project/commit/48161b7490e4aa174faf2b0e840e743a3ee56a4a
DIFF: https://github.com/llvm/llvm-project/commit/48161b7490e4aa174faf2b0e840e743a3ee56a4a.diff

LOG: [ELF] --gc-sections: Work around SHT_PROGBITS .init_array

Older Go cmd/link used SHT_PROGBITS for .init_array .
Work around the lack of https://golang.org/cl/373734 for a while.
It does not generate .fini_array or .preinit_array

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 4a563f4eaef40..1a17f3bbfdc50 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -177,8 +177,10 @@ static bool isReserved(InputSectionBase *sec) {
     // SHT_NOTE sections in a group are subject to garbage collection.
     return !sec->nextInSectionGroup;
   default:
+    // Support SHT_PROGBITS .init_array for a while
+    // (https://golang.org/issue/50295).
     StringRef s = sec->name;
-    return s == ".init" || s == ".fini" || s == ".jcr" ||
+    return s == ".init" || s == ".fini" || s == ".init_array" || s == ".jcr" ||
            s.startswith(".ctors") || s.startswith(".dtors");
   }
 }

diff  --git a/lld/test/ELF/gc-sections.s b/lld/test/ELF/gc-sections.s
index 86dd6f64c4d22..7896c03b0fc5a 100644
--- a/lld/test/ELF/gc-sections.s
+++ b/lld/test/ELF/gc-sections.s
@@ -17,6 +17,8 @@
 # NOGC: Name: .tbss
 # NOGC: Name: .ctors
 # NOGC: Name: .dtors
+# NOGC: Name: .init_array
+# NOGC: Name: .preinit_array
 # NOGC: Name: .jcr
 # NOGC: Name: .jcr_x
 # NOGC: Name: .debug_pubtypes
@@ -49,6 +51,8 @@
 # GC1:     Name: .tbss
 # GC1:     Name: .ctors
 # GC1:     Name: .dtors
+# GC1:     Name: .init_array
+# GC1:     Name: .preinit_array
 # GC1:     Name: .jcr
 # GC1:     Name: .debug_pubtypes
 # GC1:     Name: .comment
@@ -71,6 +75,8 @@
 # GC2:     Name: .tbss
 # GC2:     Name: .ctors
 # GC2:     Name: .dtors
+# GC2:     Name: .init_array
+# GC2:     Name: .preinit_array
 # GC2:     Name: .jcr
 # GC2:     Name: .debug_pubtypes
 # GC2:     Name: .comment
@@ -147,6 +153,10 @@ h:
 .section .fini,"ax"
   .quad 0
 
+# https://golang.org/cl/373734
+.section .init_array,"aw", at progbits
+  .quad 0
+
 .section .preinit_array,"aw", at preinit_array
   .quad 0
 


        


More information about the llvm-commits mailing list