File: remember_state_leak.pass.sh.s

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (56 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# REQUIRES: target={{x86_64-.+-linux-gnu}}
# RUN: %{build}
# RUN: %{run}

# The following assembly is a translation of this code:
#
#   _Unwind_Reason_Code callback(int, _Unwind_Action, long unsigned int,
#                                _Unwind_Exception*, _Unwind_Context*, void*) {
#     return _Unwind_Reason_Code(0);
#   }
#
#   int main() {
#     asm(".cfi_remember_state\n\t");
#     _Unwind_Exception exc;
#     _Unwind_ForcedUnwind(&exc, callback, 0);
#     asm(".cfi_restore_state\n\t");
#   }
#
# When unwinding, the CFI parser will stop parsing opcodes after the current PC,
# so in this case the DW_CFA_restore_state opcode will never be processed and,
# if the library doesn't clean up properly, the store allocated by
# DW_CFA_remember_state will be leaked.
#
# This test will fail when linked with an asan-enabled libunwind if the
# remembered state is leaked.

    SIZEOF_UNWIND_EXCEPTION = 32

    .text
callback:
    xorl    %eax, %eax
    retq

    .globl    main                    # -- Begin function main
    .p2align    4, 0x90
    .type    main,@function
main:                                   # @main
    .cfi_startproc
    subq    $8, %rsp   # Adjust stack alignment
    subq    $SIZEOF_UNWIND_EXCEPTION, %rsp
    .cfi_def_cfa_offset 48
    .cfi_remember_state
    movq    %rsp, %rdi
    movabsq $callback, %rsi
    xorl    %edx, %edx
    callq    _Unwind_ForcedUnwind
    .cfi_restore_state
    xorl    %eax, %eax
    addq    $SIZEOF_UNWIND_EXCEPTION, %rsp
    addq    $8, %rsp   # Undo stack alignment adjustment
    .cfi_def_cfa_offset 8
    retq
.Lfunc_end1:
    .size    main, .Lfunc_end1-main
    .cfi_endproc
                                        # -- End function