forked from OSchip/llvm-project
[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
This commit is contained in:
parent
12d8089b8e
commit
be81dd757e
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
Binary file not shown.
|
@ -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
|
Loading…
Reference in New Issue