[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
This commit is contained in:
Fangrui Song 2021-12-21 10:44:29 -08:00
parent e03ce65190
commit 48161b7490
2 changed files with 13 additions and 1 deletions

View 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");
}
}

View 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