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

See https://github.com/rust-lang/rust/issues/92181
This commit is contained in:
Fangrui Song 2021-12-28 16:40:51 -08:00
parent 319181f767
commit de92a13fec
2 changed files with 9 additions and 4 deletions

View File

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

View File

@ -157,6 +157,10 @@ h:
.section .init_array,"aw",@progbits
.quad 0
# Work around https://github.com/rust-lang/rust/issues/92181
.section .init_array.00001,"aw",@progbits
.quad 0
.section .preinit_array,"aw",@preinit_array
.quad 0