1 /* Checks that BOLT correctly handles instrumentation shared libraries
2 * with further optimization.
8 int foo(int x
) { return x
+ 1; }
13 return fib(x
- 1) + fib(x
- 2);
16 int bar(int x
) { return x
- 1; }
20 int main(int argc
, char **argv
) {
28 * Expected library name as input to switch
29 * between original and instrumented file
32 hndl
= dlopen(libname
, RTLD_LAZY
);
34 printf("library load failed\n");
37 fib_func
= dlsym(hndl
, "fib");
39 printf("fib_func load failed\n");
44 printf("fib(%d) = %d\n", argc
, val
);
50 REQUIRES: system-linux,bolt-runtime
52 RUN: %clang %cflags %s -o %t.so -Wl,-q -fpie -fPIC -shared -DLIB
53 RUN: %clang %cflags %s -o %t.exe -Wl,-q -ldl
55 RUN: llvm-bolt %t.so --instrument --instrumentation-file=%t.so.fdata \
56 RUN: -o %t.so.instrumented
58 # Program with instrumented shared library needs to finish returning zero
59 RUN: %t.exe %t.so.instrumented 1 2 | FileCheck %s -check-prefix=CHECK-OUTPUT
60 RUN: test -f %t.so.fdata
62 # Test that the instrumented data makes sense
63 RUN: llvm-bolt %t.so -o %t.so.bolted --data %t.so.fdata \
64 RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+
66 RUN: %t.exe %t.so.bolted 1 2 | FileCheck %s -check-prefix=CHECK-OUTPUT
68 CHECK-OUTPUT: fib(4) = 3