| 1 | // Test that the runtime correctly interposes ___cxa_atexit. |
| 2 | // |
| 3 | // RUN: %clang -c -o %t %s |
| 4 | // RUN: %llvm_jitlink %t |
| 5 | |
| 6 | .text |
| 7 | // Destructor resets the test result override to zero. |
| 8 | .globl on_exit |
| 9 | .p2align 2 |
| 10 | .type on_exit,@function |
| 11 | on_exit: |
| 12 | |
| 13 | mov w0, wzr |
| 14 | b llvm_jitlink_setTestResultOverride |
| 15 | .Lfunc_end0: |
| 16 | .size on_exit, .Lfunc_end0-on_exit |
| 17 | |
| 18 | // main registers the atexit and sets the test result to one. |
| 19 | .globl main |
| 20 | .p2align 2 |
| 21 | .type main,@function |
| 22 | main: |
| 23 | |
| 24 | stp x29, x30, [sp, #-16]! |
| 25 | mov x29, sp |
| 26 | adrp x8, :got:__dso_handle |
| 27 | adrp x0, :got:on_exit |
| 28 | mov x1, xzr |
| 29 | ldr x8, [x8, :got_lo12:__dso_handle] |
| 30 | ldr x2, [x8] |
| 31 | ldr x0, [x0, :got_lo12:on_exit] |
| 32 | bl __cxa_atexit |
| 33 | mov w0, #1 |
| 34 | bl llvm_jitlink_setTestResultOverride |
| 35 | mov w0, wzr |
| 36 | ldp x29, x30, [sp], #16 |
| 37 | ret |
| 38 | .Lfunc_end1: |
| 39 | .size main, .Lfunc_end1-main |
| 40 | |