1// Test that the runtime correctly interposes ___cxa_atexit.
2//
3// RUN: %clang -c -o %t %s
4// RUN: %llvm_jitlink %t
5
6 .section __TEXT,__text,regular,pure_instructions
7 .build_version macos, 12, 0 sdk_version 12, 0
8
9# main registers the atexit and sets the test result to one.
10 .globl _main ; -- Begin function main
11 .p2align 2
12_main: ; @main
13; %bb.0:
14 sub sp, sp, #32 ; =32
15 stp x29, x30, [sp, #16] ; 16-byte Folded Spill
16 add x29, sp, #16 ; =16
17 stur wzr, [x29, #-4]
18 adrp x8, __ZGVZ4mainE6onExit@PAGE
19 add x8, x8, __ZGVZ4mainE6onExit@PAGEOFF
20 ldarb w8, [x8]
21 and w8, w8, #0x1
22 and w8, w8, #0xff
23 cbnz w8, LBB0_3
24; %bb.1:
25 adrp x0, __ZGVZ4mainE6onExit@PAGE
26 add x0, x0, __ZGVZ4mainE6onExit@PAGEOFF
27 bl ___cxa_guard_acquire
28 cbz w0, LBB0_3
29; %bb.2:
30 adrp x0, __ZN6OnExitD1Ev@GOTPAGE
31 ldr x0, [x0, __ZN6OnExitD1Ev@GOTPAGEOFF]
32 adrp x1, __ZZ4mainE6onExit@PAGE
33 add x1, x1, __ZZ4mainE6onExit@PAGEOFF
34 adrp x2, ___dso_handle@PAGE
35 add x2, x2, ___dso_handle@PAGEOFF
36 bl ___cxa_atexit
37 adrp x0, __ZGVZ4mainE6onExit@PAGE
38 add x0, x0, __ZGVZ4mainE6onExit@PAGEOFF
39 bl ___cxa_guard_release
40LBB0_3:
41 mov x0, #1
42 bl _llvm_jitlink_setTestResultOverride
43 mov w0, #0
44 ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
45 add sp, sp, #32 ; =32
46 ret
47 ; -- End function
48
49# OnExit destructor resets the test result override to zero.
50 .globl __ZN6OnExitD1Ev ; -- Begin function _ZN6OnExitD1Ev
51 .weak_def_can_be_hidden __ZN6OnExitD1Ev
52 .p2align 2
53__ZN6OnExitD1Ev: ; @_ZN6OnExitD1Ev
54; %bb.0:
55 sub sp, sp, #32 ; =32
56 stp x29, x30, [sp, #16] ; 16-byte Folded Spill
57 add x29, sp, #16 ; =16
58 str x0, [sp, #8]
59 ldr x0, [sp, #8]
60 str x0, [sp] ; 8-byte Folded Spill
61 bl __ZN6OnExitD2Ev
62 ldr x0, [sp] ; 8-byte Folded Reload
63 ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
64 add sp, sp, #32 ; =32
65 ret
66 ; -- End function
67 .globl __ZN6OnExitD2Ev ; -- Begin function _ZN6OnExitD2Ev
68 .weak_def_can_be_hidden __ZN6OnExitD2Ev
69 .p2align 2
70__ZN6OnExitD2Ev: ; @_ZN6OnExitD2Ev
71; %bb.0:
72 sub sp, sp, #32 ; =32
73 stp x29, x30, [sp, #16] ; 16-byte Folded Spill
74 add x29, sp, #16 ; =16
75 str x0, [sp, #8]
76 ldr x8, [sp, #8]
77 str x8, [sp] ; 8-byte Folded Spill
78 mov x0, #0
79 bl _llvm_jitlink_setTestResultOverride
80 ldr x0, [sp] ; 8-byte Folded Reload
81 ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
82 add sp, sp, #32 ; =32
83 ret
84 ; -- End function
85.zerofill __DATA,__bss,__ZZ4mainE6onExit,1,0 ; @_ZZ4mainE6onExit
86.zerofill __DATA,__bss,__ZGVZ4mainE6onExit,8,3 ; @_ZGVZ4mainE6onExit
87.subsections_via_symbols
88

source code of compiler-rt/test/orc/TestCases/Darwin/arm64/trivial-cxa-atexit.S