[PATCH] [PATCH] [ELF] Fix .init_array initialization
Adhemerval Zanella
adhemerval.zanella at linaro.org
Wed Jun 24 06:36:32 PDT 2015
Hi ruiu, shankar.easwaran,
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 patch fixes the llvm test-suite regressions for both Single
and MultiSource files.
http://reviews.llvm.org/D10688
Files:
lib/ReaderWriter/ELF/ELFFile.h
test/elf/init_array.test
Index: lib/ReaderWriter/ELF/ELFFile.h
===================================================================
--- lib/ReaderWriter/ELF/ELFFile.h
+++ lib/ReaderWriter/ELF/ELFFile.h
@@ -201,7 +201,11 @@
/// 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.
Index: test/elf/init_array.test
===================================================================
--- test/elf/init_array.test
+++ test/elf/init_array.test
@@ -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 @@
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 @@
- 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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10688.28339.patch
Type: text/x-patch
Size: 2287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150624/fb6d8b2c/attachment.bin>
More information about the llvm-commits
mailing list