xref: /llvm-project/bolt/test/runtime/X86/instrumentation-tail-call.s (revision 70e76e0982a9dc27b8c252353609e3a778c2bec0)
1# This reproduces a bug with instrumentation when trying to instrument
2# a function with only tail calls. Such functions can clobber red zone,
3# see https://github.com/llvm/llvm-project/issues/61114.
4
5# REQUIRES: system-linux,bolt-runtime
6
7# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
8# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q
9
10# RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
11# RUN:   -o %t.instrumented
12# RUN: %t.instrumented arg1 arg2
13# RUN: llvm-objdump %t.instrumented --disassemble-symbols=main | FileCheck %s
14
15# CHECK: leaq 0x80(%rsp), %rsp
16
17# RUN: FileCheck %s --input-file %t.fdata --check-prefix=CHECK-FDATA
18# CHECK-FDATA: 1 main {{.*}} 1 targetFunc 0 0 1
19
20  .text
21  .globl  main
22  .type main, %function
23  .p2align  4
24main:
25  pushq %rbp
26  movq  %rsp, %rbp
27  mov   %rax,-0x10(%rsp)
28  leaq targetFunc, %rax
29  pushq %rax                  # We save the target function address in the stack
30  subq  $0x18, %rsp           # Set up a dummy stack frame
31  cmpl  $0x2, %edi
32  jb    .LBBerror             # Add control flow so we don't have a trivial case
33.LBB2:
34  addq $0x20, %rsp
35  movq %rbp, %rsp
36  pop %rbp
37  mov -0x10(%rsp),%rax
38  test %rsp, %rsp
39  jne targetFunc
40
41.LBBerror:
42  addq $0x20, %rsp
43  movq %rbp, %rsp
44  pop %rbp
45  movq $1, %rax               # Finish with an error if we go this path
46  retq
47  .size main, .-main
48
49  .globl targetFunc
50  .type targetFunc, %function
51  .p2align  4
52targetFunc:
53  xorq %rax, %rax
54  retq
55  .size targetFunc, .-targetFunc
56