[lld] r240570 - [ELF] Fix .init_array initialization
Adhemerval Zanella
adhemerval.zanella at linaro.org
Wed Jun 24 12:26:00 PDT 2015
Author: azanella
Date: Wed Jun 24 14:26:00 2015
New Revision: 240570
URL: http://llvm.org/viewvc/llvm-project?rev=240570&view=rev
Log:
[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.
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/test/elf/init_array.test
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=240570&r1=240569&r2=240570&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Wed Jun 24 14:26:00 2015
@@ -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.
Modified: lld/trunk/test/elf/init_array.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/init_array.test?rev=240570&r1=240569&r2=240570&view=diff
==============================================================================
--- lld/trunk/test/elf/init_array.test (original)
+++ lld/trunk/test/elf/init_array.test Wed Jun 24 14:26:00 2015
@@ -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
More information about the llvm-commits
mailing list