[ELF] Fix .init_array initialization
Some compilers may not add the section symbol in '.symtab' for the .init_array and 'ldd' just ignore it. It results in global constructor not being called in final executable. This patch add both '.init_array' and '.fini_array' to be added in Atom graph generation even when the section contains no symbol. An already existing testcase is modified to check for such scenario. The issue fixes the llvm test-suite regressions for both Single and MultiSource files. llvm-svn: 240570
This commit is contained in:
parent
991af666f1
commit
3ebea27d66
|
|
@ -201,7 +201,11 @@ protected:
|
|||
/// symbol references.
|
||||
bool handleSectionWithNoSymbols(const Elf_Shdr *shdr,
|
||||
std::vector<Elf_Sym_Iter> &syms) const {
|
||||
return shdr && (shdr->sh_type == llvm::ELF::SHT_PROGBITS) && syms.empty();
|
||||
return shdr &&
|
||||
(shdr->sh_type == llvm::ELF::SHT_PROGBITS ||
|
||||
shdr->sh_type == llvm::ELF::SHT_INIT_ARRAY ||
|
||||
shdr->sh_type == llvm::ELF::SHT_FINI_ARRAY) &&
|
||||
syms.empty();
|
||||
}
|
||||
|
||||
/// Handle creation of atoms for .gnu.linkonce sections.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@
|
|||
#
|
||||
# int
|
||||
# main() { return (0); }
|
||||
#
|
||||
# Note: both STT_OBJECT and STT_SECTION for .init_array are commented in yaml
|
||||
# declaration to check if lld correct adds the object's .init_array when the
|
||||
# section has no symbol (some compilers may create object with this behavior,
|
||||
# specially for C++ global constructors).
|
||||
|
||||
#RUN: yaml2obj -format=elf %s -o=%t.o
|
||||
#RUN: lld -flavor gnu -target x86_64 %t.o -o %t -e=main
|
||||
|
|
@ -90,10 +95,10 @@ Symbols:
|
|||
Section: .text
|
||||
Value: 0x0000000000000020
|
||||
Size: 0x0000000000000006
|
||||
- Name: init_array
|
||||
Type: STT_OBJECT
|
||||
Section: .init_array
|
||||
Size: 0x0000000000000008
|
||||
# - Name: init_array
|
||||
# Type: STT_OBJECT
|
||||
# Section: .init_array
|
||||
# Size: 0x0000000000000008
|
||||
- Name: .text
|
||||
Type: STT_SECTION
|
||||
Section: .text
|
||||
|
|
@ -103,9 +108,9 @@ Symbols:
|
|||
- Name: .bss
|
||||
Type: STT_SECTION
|
||||
Section: .bss
|
||||
- Name: .init_array
|
||||
Type: STT_SECTION
|
||||
Section: .init_array
|
||||
# - Name: .init_array
|
||||
# Type: STT_SECTION
|
||||
# Section: .init_array
|
||||
- Name: .comment
|
||||
Type: STT_SECTION
|
||||
Section: .comment
|
||||
|
|
|
|||
Loading…
Reference in New Issue