[lld] de92a13 - [ELF] --gc-sections: Work around SHT_PROGBITS .init_array.N for Rust

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 28 16:40:56 PST 2021


Author: Fangrui Song
Date: 2021-12-28T16:40:51-08:00
New Revision: de92a13fec72a0aa80a466e7f228f5af435cebc9

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

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

See https://github.com/rust-lang/rust/issues/92181

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 b63f2beb9dcb..d2622e95e1e8 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -177,11 +177,12 @@ 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).
+    // Support SHT_PROGBITS .init_array (https://golang.org/issue/50295) and
+    // .init_array.N (https://github.com/rust-lang/rust/issues/92181) for a
+    // while.
     StringRef s = sec->name;
-    return s == ".init" || s == ".fini" || s == ".init_array" || s == ".jcr" ||
-           s.startswith(".ctors") || s.startswith(".dtors");
+    return s == ".init" || s == ".fini" || s.startswith(".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 7896c03b0fc5..2094a54dc2bf 100644
--- a/lld/test/ELF/gc-sections.s
+++ b/lld/test/ELF/gc-sections.s
@@ -157,6 +157,10 @@ h:
 .section .init_array,"aw", at progbits
   .quad 0
 
+# Work around https://github.com/rust-lang/rust/issues/92181
+.section .init_array.00001,"aw", at progbits
+  .quad 0
+
 .section .preinit_array,"aw", at preinit_array
   .quad 0
 


        


More information about the llvm-commits mailing list