[ELF] --gc-sections: Work around SHT_PROGBITS .init_array
authorFangrui Song <i@maskray.me>
Tue, 21 Dec 2021 18:44:29 +0000 (10:44 -0800)
committerFangrui Song <i@maskray.me>
Tue, 21 Dec 2021 18:44:29 +0000 (10:44 -0800)
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

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

index 4a563f4..1a17f3b 100644 (file)
@@ -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");
   }
 }
index 86dd6f6..7896c03 100644 (file)
@@ -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",@progbits
+  .quad 0
+
 .section .preinit_array,"aw",@preinit_array
   .quad 0