67 lines · plain
1# This reproduces a bug with instrumentation when trying to count calls2# when the target address is computed with a reference to the stack pointer.3# Our instrumentation code uses the stack to save registers to be4# transparent with the instrumented code, but we end up updating the stack5# pointer while doing so, which affects this target address calculation.6# The solution is to temporarily fix RSP. Check that we correctly instrument7# these cases.8 9# REQUIRES: system-linux,bolt-runtime10 11# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \12# RUN: %s -o %t.o13# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q14 15# RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \16# RUN: -o %t.instrumented17 18# Instrumented program needs to finish returning zero19# RUN: %t.instrumented arg1 arg220 21# Test that the instrumented data makes sense22# RUN: llvm-bolt %t.exe -o %t.bolted --data %t.fdata \23# RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+ \24# RUN: --print-only=main --print-finalized | FileCheck %s25 26# RUN: %t.bolted arg1 arg227 28# Check that our indirect call has 1 hit recorded in the fdata file and that29# this was processed correctly by BOLT30# CHECK: callq *0x18(%rsp) # CallProfile: 1 (0 misses) :31# CHECK-NEXT: { targetFunc: 1 (0 misses) }32 33 .text34 .globl main35 .type main, %function36 .p2align 437main:38 pushq %rbp39 movq %rsp, %rbp40 leaq targetFunc, %rax41 pushq %rax # We save the target function address in the stack42 subq $0x18, %rsp # Set up a dummy stack frame43 cmpl $0x2, %edi44 jb .LBBerror # Add control flow so we don't have a trivial case45.LBB2:46 callq *0x18(%rsp) # Indirect call using %rsp47 addq $0x20, %rsp48 movq %rbp, %rsp49 pop %rbp50 retq51 52.LBBerror:53 addq $0x20, %rsp54 movq %rbp, %rsp55 pop %rbp56 movq $1, %rax # Finish with an error if we go this path57 retq58 .size main, .-main59 60 .globl targetFunc61 .type targetFunc, %function62 .p2align 463targetFunc:64 xorq %rax, %rax65 retq66 .size targetFunc, .-targetFunc67