diff options
author | Shankar Easwaran <shankare@codeaurora.org> | 2013-08-25 18:05:12 +0000 |
---|---|---|
committer | Shankar Easwaran <shankare@codeaurora.org> | 2013-08-25 18:05:12 +0000 |
commit | be81dd757e272fb09fdfb370cdeafdb225c5c2bc (patch) | |
tree | 85d28032c8f582fe2bcb251fbe4ed32bf1a5917c | |
parent | 12d8089b8e9d4cfafd49eea6305591b52cd22e4e (diff) | |
download | bcm5719-llvm-be81dd757e272fb09fdfb370cdeafdb225c5c2bc.tar.gz bcm5719-llvm-be81dd757e272fb09fdfb370cdeafdb225c5c2bc.zip |
[lld][ELF] process fini_array sections
This change processes fini_array section in addition to processing
init_array sections. This also makes functions registered at compile
time for initialization and finalization to be run during execution
llvm-svn: 189196
-rw-r--r-- | lld/lib/ReaderWriter/ELF/Atoms.h | 2 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/DefaultLayout.h | 1 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/File.h | 4 | ||||
-rw-r--r-- | lld/test/elf/X86_64/Inputs/initfini.c | 14 | ||||
-rw-r--r-- | lld/test/elf/X86_64/Inputs/initfini.o | bin | 0 -> 2256 bytes | |||
-rw-r--r-- | lld/test/elf/X86_64/initfini.test | 23 |
6 files changed, 43 insertions, 1 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Atoms.h b/lld/lib/ReaderWriter/ELF/Atoms.h index d995f97f4d0..735297f638b 100644 --- a/lld/lib/ReaderWriter/ELF/Atoms.h +++ b/lld/lib/ReaderWriter/ELF/Atoms.h @@ -326,6 +326,7 @@ public: ret = typeZeroFill; break; case llvm::ELF::SHT_INIT_ARRAY: + case llvm::ELF::SHT_FINI_ARRAY: ret = typeData; break; } @@ -432,6 +433,7 @@ public: return _permissions = permRW_; case llvm::ELF::SHT_INIT_ARRAY: + case llvm::ELF::SHT_FINI_ARRAY: return _permissions = permRW_; default: diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index c3734061a38..cb18e0ce48b 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -329,6 +329,7 @@ Layout::SectionOrder DefaultLayout<ELFT>::getSectionOrder( case DefinedAtom::typeDataFast: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".init_array", ORDER_INIT_ARRAY) + .StartsWith(".fini_array", ORDER_FINI_ARRAY) .Default(ORDER_DATA); case DefinedAtom::typeZeroFill: diff --git a/lld/lib/ReaderWriter/ELF/File.h b/lld/lib/ReaderWriter/ELF/File.h index 0c2c3b80fe5..33d925067b2 100644 --- a/lld/lib/ReaderWriter/ELF/File.h +++ b/lld/lib/ReaderWriter/ELF/File.h @@ -181,7 +181,9 @@ public: } // Create a sectionSymbols entry for every progbits section. - if (section->sh_type == llvm::ELF::SHT_PROGBITS) + if ((section->sh_type == llvm::ELF::SHT_PROGBITS) || + (section->sh_type == llvm::ELF::SHT_INIT_ARRAY) || + (section->sh_type == llvm::ELF::SHT_FINI_ARRAY)) _sectionSymbols[section]; if (section->sh_type == llvm::ELF::SHT_RELA) { diff --git a/lld/test/elf/X86_64/Inputs/initfini.c b/lld/test/elf/X86_64/Inputs/initfini.c new file mode 100644 index 00000000000..9427a86b6c9 --- /dev/null +++ b/lld/test/elf/X86_64/Inputs/initfini.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +void __attribute__ ((constructor)) constructor() { + printf("%s\n", __FUNCTION__); +} + +void __attribute__ ((destructor)) destructor() { + printf("%s\n", __FUNCTION__); +} + +int main() { + return 0; +} + diff --git a/lld/test/elf/X86_64/Inputs/initfini.o b/lld/test/elf/X86_64/Inputs/initfini.o Binary files differnew file mode 100644 index 00000000000..f0e55a90b8b --- /dev/null +++ b/lld/test/elf/X86_64/Inputs/initfini.o diff --git a/lld/test/elf/X86_64/initfini.test b/lld/test/elf/X86_64/initfini.test new file mode 100644 index 00000000000..08a65a5f453 --- /dev/null +++ b/lld/test/elf/X86_64/initfini.test @@ -0,0 +1,23 @@ +# This tests the functionality that lld is able to read +# init_array/fini_array sections in the input ELF. This +# corresponds to the the .init_array/.fini_array sections +# in the output ELF. + +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o \ +RUN: --noinhibit-exec -emit-yaml -o %t +RUN: FileCheck %s < %t + +CHECK: - type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .init_array +CHECK: references: +CHECK: - kind: R_X86_64_64 +CHECK: offset: 0 +CHECK: target: constructor +CHECK: - type: data +CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] +CHECK: section-name: .fini_array +CHECK: references: +CHECK: - kind: R_X86_64_64 +CHECK: offset: 0 +CHECK: target: destructor |