[lld] r249367 - [elf2] Add __preinit_array, and __fini_array start and end symbols.
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 18:28:29 PDT 2015
On Mon, Oct 5, 2015 at 6:16 PM, Michael J. Spencer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: mspencer
> Date: Mon Oct 5 20:16:17 2015
> New Revision: 249367
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249367&view=rev
> Log:
> [elf2] Add __preinit_array, and __fini_array start and end symbols.
>
> Added:
> lld/trunk/test/elf2/pre_init_fini_array.s
> - copied, changed from r249365, lld/trunk/test/elf2/init_array.s
> lld/trunk/test/elf2/pre_init_fini_array_missing.s
> Removed:
> lld/trunk/test/elf2/init_array.s
> lld/trunk/test/elf2/init_array_missing.s
> Modified:
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249367&r1=249366&r2=249367&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Mon Oct 5 20:16:17 2015
> @@ -329,13 +329,24 @@ template <class ELFT> void Writer<ELFT>:
> DynamicSec.FiniArraySec =
> Map.lookup({".fini_array", SHT_FINI_ARRAY, SHF_WRITE | SHF_ALLOC});
>
> - if (OutputSection<ELFT> *OS = DynamicSec.InitArraySec) {
> - Symtab.addSyntheticSym<ELFT>("__init_array_start", *OS, 0);
> - Symtab.addSyntheticSym<ELFT>("__init_array_end", *OS, OS->getSize());
> - } else {
> - Symtab.addIgnoredSym<ELFT>("__init_array_start");
> - Symtab.addIgnoredSym<ELFT>("__init_array_end");
> - }
> + auto addStartEnd = [&Symtab](StringRef StartName, StringRef EndName,
> + OutputSection<ELFT> *OS) {
> + if (OS) {
> + Symtab.addSyntheticSym<ELFT>(StartName, *OS, 0);
> + Symtab.addSyntheticSym<ELFT>(EndName, *OS, OS->getSize());
> + }
> + else {
>
format
-- Sean Silva
> + Symtab.addIgnoredSym<ELFT>(StartName);
> + Symtab.addIgnoredSym<ELFT>(EndName);
> + }
> + };
> +
> + addStartEnd("__preinit_array_start", "__preinit_array_end",
> + DynamicSec.PreInitArraySec);
> + addStartEnd("__init_array_start", "__init_array_end",
> + DynamicSec.InitArraySec);
> + addStartEnd("__fini_array_start", "__fini_array_end",
> + DynamicSec.FiniArraySec);
>
> // FIXME: Try to avoid the extra walk over all global symbols.
> std::vector<DefinedCommon<ELFT> *> CommonSymbols;
>
> Removed: lld/trunk/test/elf2/init_array.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array.s?rev=249366&view=auto
>
> ==============================================================================
> --- lld/trunk/test/elf2/init_array.s (original)
> +++ lld/trunk/test/elf2/init_array.s (removed)
> @@ -1,90 +0,0 @@
> -// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> -// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %p/Inputs/shared.s -o %t2
> -// RUN: lld -flavor gnu2 %t2 -o t2.so -shared
> -// RUN: lld -flavor gnu2 %t t2.so -o %t2
> -// RUN: llvm-readobj -symbols -sections -dynamic-table %t2 | FileCheck %s
> -// RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM %s
> -// REQUIRES: x86
> -
> -.globl _start
> -_start:
> - call __init_array_start
> - call __init_array_end
> -
> -
> -.section .init_array,"aw", at init_array
> - .quad 0
> -
> -.section .preinit_array,"aw", at preinit_array
> - .quad 0
> - .byte 0
> -
> -.section .fini_array,"aw", at fini_array
> - .quad 0
> - .short 0
> -
> -// CHECK: Name: .init_array
> -// CHECK-NEXT: Type: SHT_INIT_ARRAY
> -// CHECK-NEXT: Flags [
> -// CHECK-NEXT: SHF_ALLOC
> -// CHECK-NEXT: SHF_WRITE
> -// CHECK-NEXT: ]
> -// CHECK-NEXT: Address: [[INIT_ADDR:.*]]
> -// CHECK-NEXT: Offset:
> -// CHECK-NEXT: Size: [[INIT_SIZE:.*]]
> -
> -
> -// CHECK: Name: .preinit_array
> -// CHECK-NEXT: Type: SHT_PREINIT_ARRAY
> -// CHECK-NEXT: Flags [
> -// CHECK-NEXT: SHF_ALLOC
> -// CHECK-NEXT: SHF_WRITE
> -// CHECK-NEXT: ]
> -// CHECK-NEXT: Address: [[PREINIT_ADDR:.*]]
> -// CHECK-NEXT: Offset:
> -// CHECK-NEXT: Size: [[PREINIT_SIZE:.*]]
> -
> -
> -// CHECK: Name: .fini_array
> -// CHECK-NEXT: Type: SHT_FINI_ARRAY
> -// CHECK-NEXT: Flags [
> -// CHECK-NEXT: SHF_ALLOC
> -// CHECK-NEXT: SHF_WRITE
> -// CHECK-NEXT: ]
> -// CHECK-NEXT: Address: [[FINI_ADDR:.*]]
> -// CHECK-NEXT: Offset:
> -// CHECK-NEXT: Size: [[FINI_SIZE:.*]]
> -
> -// CHECK: Name: __init_array_end
> -// CHECK-NEXT: Value: 0x13008
> -// CHECK-NEXT: Size: 0
> -// CHECK-NEXT: Binding: Local
> -// CHECK-NEXT: Type: None
> -// CHECK-NEXT: Other: 0
> -// CHECK-NEXT: Section: .init_array
> -// CHECK-NEXT: }
> -// CHECK-NEXT: Symbol {
> -// CHECK-NEXT: Name: __init_array_start
> -// CHECK-NEXT: Value: [[INIT_ADDR]]
> -// CHECK-NEXT: Size: 0
> -// CHECK-NEXT: Binding: Local
> -// CHECK-NEXT: Type: None
> -// CHECK-NEXT: Other: 0
> -// CHECK-NEXT: Section: .init_array
> -// CHECK-NEXT: }
> -
> -
> -// CHECK: DynamicSection
> -// CHECK: PREINIT_ARRAY [[PREINIT_ADDR]]
> -// CHECK: PREINIT_ARRAYSZ [[PREINIT_SIZE]] (bytes)
> -// CHECK: INIT_ARRAY [[INIT_ADDR]]
> -// CHECK: INIT_ARRAYSZ [[INIT_SIZE]] (bytes)
> -// CHECK: FINI_ARRAY [[FINI_ADDR]]
> -// CHECK: FINI_ARRAYSZ [[FINI_SIZE]] (bytes)
> -
> -
> -// 0x13000 - (0x12000 + 5) = 4091
> -// 0x13008 - (0x12005 + 5) = 4094
> -// DISASM: _start:
> -// DISASM-NEXT: 12000: e8 fb 0f 00 00 callq 4091
> -// DISASM-NEXT: 12005: e8 fe 0f 00 00 callq 4094
>
> Removed: lld/trunk/test/elf2/init_array_missing.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array_missing.s?rev=249366&view=auto
>
> ==============================================================================
> --- lld/trunk/test/elf2/init_array_missing.s (original)
> +++ lld/trunk/test/elf2/init_array_missing.s (removed)
> @@ -1,18 +0,0 @@
> -// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> -// RUN: lld -flavor gnu2 %t -o %t2
> -// RUN: llvm-objdump -d %t2 | FileCheck %s
> -// REQUIRES: x86
> -
> -.globl _start
> -_start:
> - call __init_array_start
> - call __init_array_end
> -
> -// With no .init_array section the symbols resolve to 0
> -// 0 - (0x11000 + 5) = -69637
> -// 0 - (0x11005 + 5) = -69642
> -
> -// CHECK: Disassembly of section .text:
> -// CHECK-NEXT: _start:
> -// CHECK-NEXT: 11000: e8 fb ef fe ff callq -69637
> -// CHECK-NEXT: 11005: e8 f6 ef fe ff callq -69642
>
> Copied: lld/trunk/test/elf2/pre_init_fini_array.s (from r249365,
> lld/trunk/test/elf2/init_array.s)
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array.s?p2=lld/trunk/test/elf2/pre_init_fini_array.s&p1=lld/trunk/test/elf2/init_array.s&r1=249365&r2=249367&rev=249367&view=diff
>
> ==============================================================================
> --- lld/trunk/test/elf2/init_array.s (original)
> +++ lld/trunk/test/elf2/pre_init_fini_array.s Mon Oct 5 20:16:17 2015
> @@ -8,8 +8,12 @@
>
> .globl _start
> _start:
> + call __preinit_array_start
> + call __preinit_array_end
> call __init_array_start
> call __init_array_end
> + call __fini_array_start
> + call __fini_array_end
>
>
> .section .init_array,"aw", at init_array
> @@ -55,7 +59,25 @@ _start:
> // CHECK-NEXT: Offset:
> // CHECK-NEXT: Size: [[FINI_SIZE:.*]]
>
> -// CHECK: Name: __init_array_end
> +// CHECK: Name: __fini_array_end
> +// CHECK-NEXT: Value: 0x1301B
> +// CHECK-NEXT: Size: 0
> +// CHECK-NEXT: Binding: Local
> +// CHECK-NEXT: Type: None
> +// CHECK-NEXT: Other: 0
> +// CHECK-NEXT: Section: .fini_array
> +// CHECK-NEXT: }
> +// CHECK-NEXT: Symbol {
> +// CHECK-NEXT: Name: __fini_array_start
> +// CHECK-NEXT: Value: [[FINI_ADDR]]
> +// CHECK-NEXT: Size: 0
> +// CHECK-NEXT: Binding: Local
> +// CHECK-NEXT: Type: None
> +// CHECK-NEXT: Other: 0
> +// CHECK-NEXT: Section: .fini_array
> +// CHECK-NEXT: }
> +// CHECK-NEXT: Symbol {
> +// CHECK-NEXT: Name: __init_array_end
> // CHECK-NEXT: Value: 0x13008
> // CHECK-NEXT: Size: 0
> // CHECK-NEXT: Binding: Local
> @@ -72,7 +94,24 @@ _start:
> // CHECK-NEXT: Other: 0
> // CHECK-NEXT: Section: .init_array
> // CHECK-NEXT: }
> -
> +// CHECK-NEXT: Symbol {
> +// CHECK-NEXT: Name: __preinit_array_end
> +// CHECK-NEXT: Value: 0x13011
> +// CHECK-NEXT: Size: 0
> +// CHECK-NEXT: Binding: Local
> +// CHECK-NEXT: Type: None
> +// CHECK-NEXT: Other: 0
> +// CHECK-NEXT: Section: .preinit_array
> +// CHECK-NEXT: }
> +// CHECK-NEXT: Symbol {
> +// CHECK-NEXT: Name: __preinit_array_start
> +// CHECK-NEXT: Value: [[PREINIT_ADDR]]
> +// CHECK-NEXT: Size: 0
> +// CHECK-NEXT: Binding: Local
> +// CHECK-NEXT: Type: None
> +// CHECK-NEXT: Other: 0
> +// CHECK-NEXT: Section: .preinit_array
> +// CHECK-NEXT: }
>
> // CHECK: DynamicSection
> // CHECK: PREINIT_ARRAY [[PREINIT_ADDR]]
> @@ -83,8 +122,16 @@ _start:
> // CHECK: FINI_ARRAYSZ [[FINI_SIZE]] (bytes)
>
>
> -// 0x13000 - (0x12000 + 5) = 4091
> -// 0x13008 - (0x12005 + 5) = 4094
> +// 0x13008 - (0x12000 + 5) = 4099
> +// 0x13011 - (0x12005 + 5) = 4103
> +// 0x13000 - (0x1200a + 5) = 4081
> +// 0x13008 - (0x1200f + 5) = 4084
> +// 0x13011 - (0x12014 + 5) = 4088
> +// 0x1301B - (0x12019 + 5) = 4093
> // DISASM: _start:
> -// DISASM-NEXT: 12000: e8 fb 0f 00 00 callq 4091
> -// DISASM-NEXT: 12005: e8 fe 0f 00 00 callq 4094
> +// DISASM-NEXT: 12000: e8 {{.*}} callq 4099
> +// DISASM-NEXT: 12005: e8 {{.*}} callq 4103
> +// DISASM-NEXT: 1200a: e8 {{.*}} callq 4081
> +// DISASM-NEXT: 1200f: e8 {{.*}} callq 4084
> +// DISASM-NEXT: 12014: e8 {{.*}} callq 4088
> +// DISASM-NEXT: 12019: e8 {{.*}} callq 4093
>
> Added: lld/trunk/test/elf2/pre_init_fini_array_missing.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array_missing.s?rev=249367&view=auto
>
> ==============================================================================
> --- lld/trunk/test/elf2/pre_init_fini_array_missing.s (added)
> +++ lld/trunk/test/elf2/pre_init_fini_array_missing.s Mon Oct 5 20:16:17
> 2015
> @@ -0,0 +1,30 @@
> +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +// RUN: lld -flavor gnu2 %t -o %t2
> +// RUN: llvm-objdump -d %t2 | FileCheck %s
> +// REQUIRES: x86
> +
> +.globl _start
> +_start:
> + call __preinit_array_start
> + call __preinit_array_end
> + call __init_array_start
> + call __init_array_end
> + call __fini_array_start
> + call __fini_array_end
> +
> +// With no .init_array section the symbols resolve to 0
> +// 0 - (0x11000 + 5) = -69637
> +// 0 - (0x11005 + 5) = -69642
> +// 0 - (0x1100a + 5) = -69647
> +// 0 - (0x1100f + 5) = -69652
> +// 0 - (0x11014 + 5) = -69657
> +// 0 - (0x11019 + 5) = -69662
> +
> +// CHECK: Disassembly of section .text:
> +// CHECK-NEXT: _start:
> +// CHECK-NEXT: 11000: e8 fb ef fe ff callq -69637
> +// CHECK-NEXT: 11005: e8 f6 ef fe ff callq -69642
> +// CHECK-NEXT: 1100a: e8 f1 ef fe ff callq -69647
> +// CHECK-NEXT: 1100f: e8 ec ef fe ff callq -69652
> +// CHECK-NEXT: 11014: e8 e7 ef fe ff callq -69657
> +// CHECK-NEXT: 11019: e8 e2 ef fe ff callq -69662
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151005/423f5b1d/attachment.html>
More information about the llvm-commits
mailing list