brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · b59b6db Raw
70 lines · c
1/* Checks that BOLT correctly handles instrumentation shared libraries2 * with further optimization.3 */4#include <dlfcn.h>5#include <stdio.h>6 7#ifdef LIB8int foo(int x) { return x + 1; }9 10int fib(int x) {11  if (x < 2)12    return x;13  return fib(x - 1) + fib(x - 2);14}15 16int bar(int x) { return x - 1; }17#endif18 19#ifndef LIB20int main(int argc, char **argv) {21  int (*fib_func)(int);22  char *libname;23  void *hndl;24  int val;25  if (argc < 2)26    return -1;27  /*28   * Expected library name as input to switch29   * between original and instrumented file30   */31  libname = argv[1];32  hndl = dlopen(libname, RTLD_LAZY);33  if (!hndl) {34    printf("library load failed\n");35    return -1;36  }37  fib_func = dlsym(hndl, "fib");38  if (!fib_func) {39    printf("fib_func load failed\n");40    return -1;41  }42  val = fib_func(argc);43  dlclose(hndl);44  printf("fib(%d) = %d\n", argc, val);45  return 0;46}47#endif48 49/*50REQUIRES: system-linux,bolt-runtime51 52RUN: %clang %cflags %s -o %t.so -Wl,-q -fpie -fPIC -shared -DLIB53RUN: %clang %cflags %s -o %t.exe -Wl,-q -ldl54 55RUN: llvm-bolt %t.so --instrument --instrumentation-file=%t.so.fdata \56RUN:   -o %t.so.instrumented57 58# Program with instrumented shared library needs to finish returning zero59RUN: %t.exe %t.so.instrumented 1 2 | FileCheck %s -check-prefix=CHECK-OUTPUT60RUN: test -f %t.so.fdata61 62# Test that the instrumented data makes sense63RUN: llvm-bolt %t.so -o %t.so.bolted --data %t.so.fdata \64RUN:    --reorder-blocks=ext-tsp --reorder-functions=hfsort+65 66RUN: %t.exe %t.so.bolted 1 2 | FileCheck %s -check-prefix=CHECK-OUTPUT67 68CHECK-OUTPUT: fib(4) = 369*/70