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. 3 4# REQUIRES: system-linux 5 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 17 18 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 33b: je hot_path 34# FDATA: 1 _start #b# 1 _start #hot_path# 0 1 35cold_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 46hot_path: 47 addq $0x20, %rsp 48 pop %r14 49 pop %rbx 50 pop %rbp 51 ret 52 .cfi_endproc 53end: 54 .size _start, .-_start 55 56 .data 57rel: .quad end 58 59# CHECK: BOLT-INFO: Shrink wrapping moved 2 spills inserting load/stores and 0 spills inserting push/pops 60 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 67