| 1 |
// Test that ELF static initializers with different constructor priorities work |
| 2 |
// and are executed in the proper order. |
| 3 |
// |
| 4 |
// RUN: %clang -c -o %t %s |
| 5 |
// RUN: %llvm_jitlink %t | FileCheck %s |
| 6 |
|
| 7 |
// CHECK: constructor 100 |
| 8 |
// CHECK-NEXT: constructor 200 |
| 9 |
// CHECK-NEXT: constructor 65535 |
| 10 |
// CHECK-NEXT: main |
| 11 |
// CHECK-NEXT: destructor |
| 12 |
|
| 13 |
.text |
| 14 |
|
| 15 |
.globl destructor |
| 16 |
.p2align 4, 0x90 |
| 17 |
.type destructor,@function |
| 18 |
destructor: |
| 19 |
.Ldestructor$local: |
| 20 |
|
| 21 |
leaq .L.str.d(%rip), %rdi |
| 22 |
jmp puts@PLT |
| 23 |
|
| 24 |
.globl main |
| 25 |
.p2align 4, 0x90 |
| 26 |
.type main,@function |
| 27 |
main: |
| 28 |
.Lmain$local: |
| 29 |
|
| 30 |
pushq %rax |
| 31 |
leaq .L.str(%rip), %rdi |
| 32 |
callq puts@PLT |
| 33 |
xorl %eax, %eax |
| 34 |
popq %rcx |
| 35 |
retq |
| 36 |
|
| 37 |
.p2align 4, 0x90 |
| 38 |
.type constructor.65535,@function |
| 39 |
constructor.65535: |
| 40 |
|
| 41 |
pushq %rax |
| 42 |
leaq .L.str.65535(%rip), %rdi |
| 43 |
callq puts@PLT |
| 44 |
leaq .Ldestructor$local(%rip), %rdi |
| 45 |
leaq __dso_handle(%rip), %rdx |
| 46 |
xorl %esi, %esi |
| 47 |
popq %rax |
| 48 |
jmp __cxa_atexit@PLT |
| 49 |
|
| 50 |
.p2align 4, 0x90 |
| 51 |
.type constructor.200,@function |
| 52 |
constructor.200: |
| 53 |
|
| 54 |
leaq .L.str.200(%rip), %rdi |
| 55 |
jmp puts@PLT |
| 56 |
|
| 57 |
.p2align 4, 0x90 |
| 58 |
.type constructor.100,@function |
| 59 |
constructor.100: |
| 60 |
|
| 61 |
leaq .L.str.100(%rip), %rdi |
| 62 |
jmp puts@PLT |
| 63 |
|
| 64 |
.hidden __dso_handle |
| 65 |
.type .L.str,@object |
| 66 |
.section .rodata.str1.1,"aMS",@progbits,1 |
| 67 |
.L.str: |
| 68 |
.asciz "main" |
| 69 |
.size .L.str, 5 |
| 70 |
|
| 71 |
.type .L.str.100,@object |
| 72 |
.L.str.100: |
| 73 |
.asciz "constructor 100" |
| 74 |
.size .L.str.100, 16 |
| 75 |
|
| 76 |
.type .L.str.200,@object |
| 77 |
.L.str.200: |
| 78 |
.asciz "constructor 200" |
| 79 |
.size .L.str.200, 16 |
| 80 |
|
| 81 |
.type .L.str.65535,@object |
| 82 |
.L.str.65535: |
| 83 |
.asciz "constructor 65535" |
| 84 |
.size .L.str.65535, 18 |
| 85 |
|
| 86 |
.type .L.str.d,@object |
| 87 |
.L.str.d: |
| 88 |
.asciz "destructor" |
| 89 |
.size .L.str.d, 11 |
| 90 |
|
| 91 |
.section .init_array.100,"aw",@init_array |
| 92 |
.p2align 3 |
| 93 |
.quad constructor.100 |
| 94 |
.section .init_array.200,"aw",@init_array |
| 95 |
.p2align 3 |
| 96 |
.quad constructor.200 |
| 97 |
.section .init_array,"aw",@init_array |
| 98 |
.p2align 3 |
| 99 |
.quad constructor.65535 |