1/* Checks that BOLT correctly processes a user-provided function list file,
2 * reorder functions according to this list, update hot_start and hot_end
3 * symbols and insert a function to perform hot text mapping during program
4 * startup.
5 */
6#include <stdio.h>
7
8int foo(int x) { return x + 1; }
9
10int fib(int x) {
11 if (x < 2)
12 return x;
13 return fib(x: x - 1) + fib(x: x - 2);
14}
15
16int bar(int x) { return x - 1; }
17
18int main(int argc, char **argv) {
19 printf(format: "fib(%d) = %d\n", argc, fib(x: argc));
20 return 0;
21}
22
23/*
24REQUIRES: system-linux,bolt-runtime
25
26RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q
27
28RUN: llvm-bolt %t.exe --relocs=1 --lite --reorder-functions=user \
29RUN: --hugify --function-order=%p/Inputs/user_func_order.txt -o %t
30RUN: llvm-bolt %t.exe --relocs=1 --lite --reorder-functions=user \
31RUN: --function-order=%p/Inputs/user_func_order.txt -o %t.nohugify
32RUN: llvm-nm --numeric-sort --print-armap %t | \
33RUN: FileCheck %s -check-prefix=CHECK-NM
34RUN: %t 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT
35RUN: llvm-nm --numeric-sort --print-armap %t.nohugify | \
36RUN: FileCheck %s -check-prefix=CHECK-NM-NOHUGIFY
37RUN: %t.nohugify 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT-NOHUGIFY
38
39
40CHECK-NM: W __hot_start
41CHECK-NM: T main
42CHECK-NM-NEXT: T fib
43CHECK-NM-NEXT: W __hot_end
44CHECK-NM: t __bolt_hugify_start_program
45CHECK-NM-NEXT: W __bolt_runtime_start
46
47CHECK-NM-NOHUGIFY: W __hot_start
48CHECK-NM-NOHUGIFY: T main
49CHECK-NM-NOHUGIFY-NEXT: T fib
50CHECK-NM-NOHUGIFY-NEXT: W __hot_end
51
52CHECK-OUTPUT: fib(4) = 3
53CHECK-OUTPUT-NOHUGIFY: fib(4) = 3
54*/
55

source code of bolt/test/runtime/user-func-reorder.c