[lld] r221588 - [ELF] Fix DT_INIT_ARRAY{SZ} and DT_FINI_ARRAY{SZ}
Shankar Easwaran
shankare at codeaurora.org
Mon Nov 10 06:55:12 PST 2014
Author: shankare
Date: Mon Nov 10 08:55:11 2014
New Revision: 221588
URL: http://llvm.org/viewvc/llvm-project?rev=221588&view=rev
Log:
[ELF] Fix DT_INIT_ARRAY{SZ} and DT_FINI_ARRAY{SZ}
The dynamic table was creating the entry DT_FINI_ARRAY{SZ} even when there was
no .fini_array section. The entries should be creating in the dynamic section
only if there are sections .init_array/.fini_array in the output.
Fixes the tests that checked for errroneous outputs.
Modified:
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/test/elf/Mips/base-address.test
lld/trunk/test/elf/Mips/dynlib-dynamic.test
lld/trunk/test/elf/Mips/exe-dynamic.test
lld/trunk/test/elf/dynamic.test
lld/trunk/test/elf/entry.objtxt
lld/trunk/test/elf/phdr.test
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Mon Nov 10 08:55:11 2014
@@ -1068,10 +1068,6 @@ public:
_dt_strsz = addEntry(dyn);
dyn.d_tag = DT_SYMENT;
_dt_syment = addEntry(dyn);
- dyn.d_tag = DT_FINI_ARRAY;
- _dt_fini_array = addEntry(dyn);
- dyn.d_tag = DT_FINI_ARRAYSZ;
- _dt_fini_arraysz = addEntry(dyn);
if (_layout.hasDynamicRelocationTable()) {
dyn.d_tag = isRela ? DT_RELA : DT_REL;
_dt_rela = addEntry(dyn);
@@ -1099,6 +1095,25 @@ public:
}
}
+ virtual void doPreFlight() {
+ Elf_Dyn dyn;
+ dyn.d_un.d_val = 0;
+ auto initArray = _layout.findOutputSection(".init_array");
+ auto finiArray = _layout.findOutputSection(".fini_array");
+ if (initArray) {
+ dyn.d_tag = DT_INIT_ARRAY;
+ _dt_init_array = addEntry(dyn);
+ dyn.d_tag = DT_INIT_ARRAYSZ;
+ _dt_init_arraysz = addEntry(dyn);
+ }
+ if (finiArray) {
+ dyn.d_tag = DT_FINI_ARRAY;
+ _dt_fini_array = addEntry(dyn);
+ dyn.d_tag = DT_FINI_ARRAYSZ;
+ _dt_fini_arraysz = addEntry(dyn);
+ }
+ }
+
/// \brief Dynamic table tag for .got.plt section referencing.
/// Usually but not always targets use DT_PLTGOT for that.
virtual int64_t getGotPltTag() { return DT_PLTGOT; }
@@ -1132,6 +1147,11 @@ public:
_entries[_dt_symtab].d_un.d_val = _dynamicSymbolTable->virtualAddr();
_entries[_dt_strsz].d_un.d_val = dynamicStringTable->memSize();
_entries[_dt_syment].d_un.d_val = _dynamicSymbolTable->getEntSize();
+ auto initArray = _layout.findOutputSection(".init_array");
+ if (initArray) {
+ _entries[_dt_init_array].d_un.d_val = initArray->virtualAddr();
+ _entries[_dt_init_arraysz].d_un.d_val = initArray->memSize();
+ }
auto finiArray = _layout.findOutputSection(".fini_array");
if (finiArray) {
_entries[_dt_fini_array].d_un.d_val = finiArray->virtualAddr();
@@ -1168,6 +1188,8 @@ private:
std::size_t _dt_pltgot;
std::size_t _dt_pltrel;
std::size_t _dt_jmprel;
+ std::size_t _dt_init_array;
+ std::size_t _dt_init_arraysz;
std::size_t _dt_fini_array;
std::size_t _dt_fini_arraysz;
std::size_t _dt_textrel;
Modified: lld/trunk/test/elf/Mips/base-address.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/base-address.test?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/base-address.test (original)
+++ lld/trunk/test/elf/Mips/base-address.test Mon Nov 10 08:55:11 2014
@@ -5,15 +5,13 @@
# RUN: lld -flavor gnu -target mipsel --noinhibit-exec -o %t.exe %t.o
# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s
-# CHECK: DynamicSection [ (15 entries)
+# CHECK: DynamicSection [ (13 entries)
# CHECK: Tag Type Name/Value
# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x0000000A STRSZ 1 (bytes)
# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
-# CHECK-NEXT: 0x0000001A FINI_ARRAY 0x0
-# CHECK-NEXT: 0x0000001C FINI_ARRAYSZ 0 (bytes)
# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT
# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000
Modified: lld/trunk/test/elf/Mips/dynlib-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/dynlib-dynamic.test?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/dynlib-dynamic.test (original)
+++ lld/trunk/test/elf/Mips/dynlib-dynamic.test Mon Nov 10 08:55:11 2014
@@ -9,15 +9,13 @@
# CHECK: Arch: mipsel
# CHECK: AddressSize: 32bit
# CHECK: LoadName:
-# CHECK: DynamicSection [ (15 entries)
+# CHECK: DynamicSection [ (13 entries)
# CHECK: Tag Type Name/Value
# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}}
# CHECK-NEXT: 0x0000000A STRSZ 17 (bytes)
# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
-# CHECK-NEXT: 0x0000001A FINI_ARRAY 0x0
-# CHECK-NEXT: 0x0000001C FINI_ARRAYSZ 0 (bytes)
# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT
# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x0
@@ -28,14 +26,14 @@
# CHECK-NEXT: 0x00000000 NULL 0x0
# CHECK-NEXT: ]
-FileHeader:
+FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
-Sections:
+Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
@@ -46,7 +44,7 @@ Sections:
Link: .symtab
AddressAlign: 0x04
Info: .text
- Relocations:
+ Relocations:
- Offset: 0x00
Symbol: '$.str1'
Type: R_MIPS_GOT16
@@ -84,8 +82,8 @@ Sections:
AddressAlign: 0x01
Size: 0x05
-Symbols:
- Local:
+Symbols:
+ Local:
- Name: '$.str1'
Section: .rodata.str1
- Name: '$.str2'
@@ -105,7 +103,7 @@ Symbols:
- Name: .rodata.str2
Type: STT_SECTION
Section: .rodata.str2
- Global:
+ Global:
- Name: glob
Section: .text
- Name: ext1
Modified: lld/trunk/test/elf/Mips/exe-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-dynamic.test?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/exe-dynamic.test (original)
+++ lld/trunk/test/elf/Mips/exe-dynamic.test Mon Nov 10 08:55:11 2014
@@ -13,15 +13,13 @@
# CHECK: Arch: mipsel
# CHECK: AddressSize: 32bit
# CHECK: LoadName:
-# CHECK: DynamicSection [ (20 entries)
+# CHECK: DynamicSection [ (18 entries)
# CHECK: Tag Type Name/Value
# CHECK-NEXT: 0x00000004 HASH 0x400110
# CHECK-NEXT: 0x00000005 STRTAB 0x400144
# CHECK-NEXT: 0x00000006 SYMTAB 0x400124
# CHECK-NEXT: 0x0000000A STRSZ 28 (bytes)
# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
-# CHECK-NEXT: 0x0000001A FINI_ARRAY 0x0
-# CHECK-NEXT: 0x0000001C FINI_ARRAYSZ 0 (bytes)
# CHECK-NEXT: 0x00000002 PLTRELSZ 8 (bytes)
# CHECK-NEXT: 0x70000032 MIPS_PLTGOT 0x402000
# CHECK-NEXT: 0x00000014 PLTREL REL
Modified: lld/trunk/test/elf/dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/dynamic.test?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/dynamic.test (original)
+++ lld/trunk/test/elf/dynamic.test Mon Nov 10 08:55:11 2014
@@ -60,15 +60,13 @@ CHECK-NEXT: Binding: Global
CHECK-NEXT: Type: Function
CHECK: }
-CHECK: DynamicSection [ (17 entries)
+CHECK: DynamicSection [ (15 entries)
CHECK: Tag Type Name/Value
CHECK: 0x0000000000000004 HASH
CHECK: 0x0000000000000005 STRTAB
CHECK: 0x0000000000000006 SYMTAB
CHECK: 0x000000000000000A STRSZ
CHECK: 0x000000000000000B SYMENT 24
-CHECK: 0x000000000000001A FINI_ARRAY
-CHECK: 0x000000000000001C FINI_ARRAYSZ
CHECK: 0x0000000000000007 RELA
CHECK: 0x0000000000000008 RELASZ 24
CHECK: 0x0000000000000009 RELAENT 24
Modified: lld/trunk/test/elf/entry.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/entry.objtxt?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/entry.objtxt (original)
+++ lld/trunk/test/elf/entry.objtxt Mon Nov 10 08:55:11 2014
@@ -13,8 +13,8 @@
#
# CHECK: 004001e0 T main
# CHECK: 00401000 D _DYNAMIC
-# CHECK: 00401080 A _end
-# CHECK: 00401080 A end
+# CHECK: 00401060 A _end
+# CHECK: 00401060 A end
# CHECK: U _entrypoint
defined-atoms:
Modified: lld/trunk/test/elf/phdr.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/phdr.test?rev=221588&r1=221587&r2=221588&view=diff
==============================================================================
--- lld/trunk/test/elf/phdr.test (original)
+++ lld/trunk/test/elf/phdr.test Mon Nov 10 08:55:11 2014
@@ -36,8 +36,8 @@ I386-NEXT: Type: PT_LOAD (0x1)
I386-NEXT: Offset: 0x0
I386-NEXT: VirtualAddress: 0x0
I386-NEXT: PhysicalAddress: 0x0
-I386-NEXT: FileSize: 572
-I386-NEXT: MemSize: 572
+I386-NEXT: FileSize: 556
+I386-NEXT: MemSize: 556
I386-NEXT: Flags [ (0x5)
I386-NEXT: PF_R (0x4)
I386-NEXT: PF_X (0x1)
@@ -87,8 +87,8 @@ I386-NEXT: Type: PT_DYNAMIC (0x2)
I386-NEXT: Offset: 0x1FC
I386-NEXT: VirtualAddress: 0x1FC
I386-NEXT: PhysicalAddress: 0x1FC
-I386-NEXT: FileSize: 64
-I386-NEXT: MemSize: 64
+I386-NEXT: FileSize: 48
+I386-NEXT: MemSize: 48
I386-NEXT: Flags [ (0x4)
I386-NEXT: PF_R (0x4)
I386-NEXT: ]
More information about the llvm-commits
mailing list