1/**
2 * Test for asm-dump functionality.
3 *
4 * REQUIRES: x86_64-linux,bolt-runtime
5 *
6 * Compile the source
7 * RUN: %clang -fPIC %s -o %t.exe -Wl,-q
8 *
9 * Profile collection: instrument the binary
10 * RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata -o \
11 * RUN: %t.instr
12 *
13 * Profile collection: run instrumented binary (and capture output)
14 * RUN: %t.instr > %t.result
15 *
16 * Run BOLT with asm-dump
17 * RUN: llvm-bolt %t.exe -p %t.fdata --funcs=main --asm-dump=%t -o %t.null \
18 * RUN: | FileCheck %s --check-prefix=CHECK-BOLT
19 *
20 * Check asm file contents
21 * RUN: cat %t/main.s | FileCheck %s --check-prefix=CHECK-FILE
22 *
23 * Now check if asm-dump file can be consumed by BOLT infra
24 * Strip dot from compiler-local symbols:
25 * RUN: sed -i 's/\.L/L/g' %t/main.s
26 *
27 * Recompile the asm file into objfile
28 * RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
29 *
30 * Reconstruct fdata
31 * RUN: link_fdata %t/main.s %t.o %t.fdata.reconst
32 *
33 * XXX: reenable once dumping data is supported
34 * Check if reoptimized file produces the same results
35 * dontrun: %t.exe.reopt > %t.result.reopt
36 * dontrun: cmp %t.result %t.result.reopt
37 *
38 * Delete our BB symbols so BOLT doesn't mark them as entry points
39 * RUN: llvm-strip --strip-unneeded %t.o
40 *
41 * Recompile the binary
42 * RUN: %clang -fPIC %t.o -o %t.exe.reopt -Wl,-q
43 *
44 * Finally consume reoptimized file with reconstructed fdata
45 * RUN: llvm-bolt %t.exe.reopt -p %t.fdata.reconst -o %t.null \
46 * RUN: | FileCheck %s --check-prefix=CHECK-REOPT
47 *
48 * CHECK-BOLT: BOLT-INFO: Dumping function assembly to {{.*}}/main.s
49 *
50 * CHECK-FILE: .globl main
51 * CHECK-FILE-NEXT: .type main, %function
52 * CHECK-FILE-NEXT: main:
53 * CHECK-FILE-NEXT: # FDATA: 0 [unknown] 0 1 main 0 0 1
54 * CHECK-FILE-NEXT: .cfi_startproc
55 * CHECK-FILE-NEXT: .LBB{{.*}}:
56 * CHECK-FILE: .cfi_def_cfa_offset 16
57 * CHECK-FILE: leaq {{.*}}(%rip)
58 * CHECK-FILE: callq puts@PLT
59 * CHECK-FILE: .cfi_endproc
60 * CHECK-FILE-NEXT: .size main, .-main
61 * CHECK-FILE: .section .rodata
62 *
63 * CHECK-REOPT: BOLT-INFO: 1 out of {{.*}} functions in the binary {{.*}} have
64 * CHECK-REOPT: non-empty execution profile
65 */
66#include <stdio.h>
67#include <string.h>
68
69int main(int argc, char* argv[]) {
70 for (int I = 0; I < 10; I++) {
71 if (I != 9)
72 continue;
73 if (argc > 1 &&
74 strncmp(s1: argv[1], s2: "--help", n: strlen(s: "--help")) == 0) {
75 puts(s: "Help message\n");
76 } else {
77 puts(s: "Hello, World!\n");
78 }
79 }
80 return 0;
81}
82

source code of bolt/test/runtime/X86/asm-dump.c