1/* Checks that BOLT correctly handles instrumentation of executables built
2 * with PIE with further optimization.
3 */
4#include <stdio.h>
5
6int foo(int x) { return x + 1; }
7
8int fib(int x) {
9 if (x < 2)
10 return x;
11 return fib(x: x - 1) + fib(x: x - 2);
12}
13
14int bar(int x) { return x - 1; }
15
16int main(int argc, char **argv) {
17 printf(format: "fib(%d) = %d\n", argc, fib(x: argc));
18 return 0;
19}
20
21/*
22REQUIRES: system-linux,bolt-runtime
23
24RUN: %clang %cflags %s -o %t.exe -Wl,-q -pie -fpie
25
26RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
27RUN: -o %t.instrumented
28
29# Instrumented program needs to finish returning zero
30RUN: %t.instrumented 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT
31
32# Test that the instrumented data makes sense
33RUN: llvm-bolt %t.exe -o %t.bolted --data %t.fdata \
34RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+
35
36RUN: %t.bolted 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT
37
38CHECK-OUTPUT: fib(4) = 3
39*/
40

source code of bolt/test/runtime/X86/instrumentation-pie.c