[llvm-gsymutil] Disable test macho-gsym-merged-callsites-dsym (#119957)
[llvm-project.git] / bolt / test / X86 / shrinkwrapping-restore-position.s
blob1d26b6e48e6fcac61e1cdf5f5524b1115929e626
1 ## This checks that shrink wrapping uses the red zone defined in the X86 ABI by
2 ## placing restores that access elements already deallocated by the stack.
4 # REQUIRES: system-linux
6 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
7 # RUN: %s -o %t.o
8 # RUN: link_fdata %s %t.o %t.fdata
9 # RUN: llvm-strip --strip-unneeded %t.o
10 # RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
11 # RUN: llvm-bolt -relocs %t.exe -o %t.out -data %t.fdata \
12 # RUN: -frame-opt=all -simplify-conditional-tail-calls=false \
13 # RUN: -experimental-shrink-wrapping \
14 # RUN: -eliminate-unreachable=false | FileCheck %s
15 # RUN: llvm-objdump -d %t.out --print-imm-hex | \
16 # RUN: FileCheck --check-prefix CHECK-OBJDUMP %s
19 ## Here we create a CFG where the restore position matches the previous (deleted)
20 ## restore position. Shrink wrapping then will put a stack access to an element
21 ## that was deallocated at the previously deleted POP, which falls in the red
22 ## zone and should be safe for X86 Linux ABI.
23 .globl _start
24 .type _start, %function
25 _start:
26 .cfi_startproc
27 # FDATA: 0 [unknown] 0 1 _start 0 0 1
28 push %rbp
29 mov %rsp, %rbp
30 push %rbx
31 push %r14
32 subq $0x20, %rsp
33 b: je hot_path
34 # FDATA: 1 _start #b# 1 _start #hot_path# 0 1
35 cold_path:
36 mov %r14, %rdi
37 mov %rbx, %rdi
38 movq rel(%rip), %rdi # Add this to create a relocation and run bolt w/ relocs
39 leaq -0x20(%rbp), %r14
40 movq -0x20(%rbp), %rdi
41 leaq -0x10(%rbp), %rsp
42 pop %r14
43 pop %rbx
44 pop %rbp
45 ret
46 hot_path:
47 addq $0x20, %rsp
48 pop %r14
49 pop %rbx
50 pop %rbp
51 ret
52 .cfi_endproc
53 end:
54 .size _start, .-_start
56 .data
57 rel: .quad end
59 # CHECK: BOLT-INFO: Shrink wrapping moved 2 spills inserting load/stores and 0 spills inserting push/pops
61 # CHECK-OBJDUMP: <_start>:
62 # CHECK-OBJDUMP: leaq (%rbp), %rsp
63 # CHECK-OBJDUMP-NEXT: popq %rbp
64 # CHECK-OBJDUMP-NEXT: movq -0x10(%rsp), %rbx
65 # CHECK-OBJDUMP-NEXT: movq -0x18(%rsp), %r14
66 # CHECK-OBJDUMP-NEXT: retq