xref: /llvm-project/compiler-rt/test/profile/instrprof-darwin-dead-strip.c (revision 443e2a10f69caeedb9fa621366b16fe0d4358279)
1d5454ce1SVedant Kumar // REQUIRES: osx-ld64-live_support
2d5454ce1SVedant Kumar // REQUIRES: lto
3d5454ce1SVedant Kumar 
4a4c56923SVedant Kumar // RUN: %clang_profgen=%t.profraw -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 -Wl,-dead_strip -o %t %s
5d5454ce1SVedant Kumar // RUN: %run %t
6d5454ce1SVedant Kumar // RUN: llvm-profdata merge -o %t.profdata %t.profraw
7d5454ce1SVedant Kumar // RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s -check-prefix=PROF
8d5454ce1SVedant Kumar // RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s -check-prefix=COV
9d5454ce1SVedant Kumar // RUN: nm %t | FileCheck %s -check-prefix=NM
106c439a38SVedant Kumar // RUN: otool -V -s __DATA __llvm_prf_names %t | FileCheck %s -check-prefix=PRF_NAMES
116c439a38SVedant Kumar // RUN: otool -V -s __DATA __llvm_prf_cnts %t | FileCheck %s -check-prefix=PRF_CNTS
12d5454ce1SVedant Kumar 
13a4c56923SVedant Kumar // RUN: %clang_lto_profgen=%t.lto.profraw -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 -Wl,-dead_strip -flto -o %t.lto %s
14d5454ce1SVedant Kumar // RUN: %run %t.lto
15d5454ce1SVedant Kumar // RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
16d5454ce1SVedant Kumar // RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s -check-prefix=PROF
17d5454ce1SVedant Kumar // RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s -check-prefix=COV
18d5454ce1SVedant Kumar // RUN: nm %t.lto | FileCheck %s -check-prefix=NM
196c439a38SVedant Kumar // RUN: otool -V -s __DATA __llvm_prf_names %t.lto | FileCheck %s -check-prefix=PRF_NAMES
206c439a38SVedant Kumar // RUN: otool -V -s __DATA __llvm_prf_cnts %t.lto | FileCheck %s -check-prefix=PRF_CNTS
21d5454ce1SVedant Kumar 
22d5454ce1SVedant Kumar // Note: We expect foo() and some of the profiling data associated with it to
23d5454ce1SVedant Kumar // be dead-stripped.
24d5454ce1SVedant Kumar 
25a4c56923SVedant Kumar // Note: When there is no code in a program, we expect to see the exact same
26a4c56923SVedant Kumar // set of external functions provided by the profile runtime.
27a4c56923SVedant Kumar 
28a4c56923SVedant Kumar // RUN: %clang_profgen -fcoverage-mapping -Wl,-dead_strip -dynamiclib -o %t.nocode.dylib %s
29a4c56923SVedant Kumar // RUN: nm -jgU %t.nocode.dylib > %t.nocode.syms
30*443e2a10SAlex Brachet // RUN: nm -jgU %t | sed -e '/_\{1,\}main/d' -e '/_\{1,\}mh_execute_header/d' > %t.code.syms
31a4c56923SVedant Kumar // RUN: diff %t.nocode.syms %t.code.syms
32a4c56923SVedant Kumar 
33a4c56923SVedant Kumar #ifdef CODE
34a4c56923SVedant Kumar 
35d5454ce1SVedant Kumar // COV: [[@LINE+1]]{{ *}}|{{ *}}0|void foo()
foo()36d5454ce1SVedant Kumar void foo() {}
37d5454ce1SVedant Kumar 
38d5454ce1SVedant Kumar // COV: [[@LINE+1]]{{ *}}|{{ *}}1|int main
main()39d5454ce1SVedant Kumar int main() { return 0; }
40d5454ce1SVedant Kumar 
41a4c56923SVedant Kumar #endif // CODE
42a4c56923SVedant Kumar 
43d5454ce1SVedant Kumar // NM-NOT: foo
44d5454ce1SVedant Kumar 
45d5454ce1SVedant Kumar // PROF: Counters:
46d5454ce1SVedant Kumar // PROF-NEXT:   main:
47d5454ce1SVedant Kumar // PROF-NEXT:     Hash:
48d5454ce1SVedant Kumar // PROF-NEXT:     Counters: 1
49d5454ce1SVedant Kumar // PROF-NEXT:     Function count: 1
50c1ffcec3SAdam Nemet // PROF-NEXT: Instrumentation level: Front-end
51d5454ce1SVedant Kumar // PROF-NEXT: Functions shown: 1
52d5454ce1SVedant Kumar // PROF-NEXT: Total functions: 1
53d5454ce1SVedant Kumar // PROF-NEXT: Maximum function count: 1
54d5454ce1SVedant Kumar // PROF-NEXT: Maximum internal block count: 0
55d5454ce1SVedant Kumar 
56d5454ce1SVedant Kumar // Note: We don't expect the names of dead-stripped functions to disappear from
57d5454ce1SVedant Kumar // __llvm_prf_names, because collectPGOFuncNameStrings() glues the names
58d5454ce1SVedant Kumar // together.
59d5454ce1SVedant Kumar 
60d5454ce1SVedant Kumar // PRF_NAMES: Contents of (__DATA,__llvm_prf_names) section
616c439a38SVedant Kumar // PRF_NAMES-NEXT: {{.*}} 08 00 66 6f 6f 01 6d 61 69 6e
62d5454ce1SVedant Kumar //                        |  |  f  o  o  #  m  a  i  n
63d5454ce1SVedant Kumar //                        |  |___________|
64d5454ce1SVedant Kumar //                        |              |
65d5454ce1SVedant Kumar //               UncompressedLen = 8     |
66d5454ce1SVedant Kumar //                                       |
67d5454ce1SVedant Kumar //                                CompressedLen = 0
68d5454ce1SVedant Kumar 
69d5454ce1SVedant Kumar // Note: We expect the profile counters for dead-stripped functions to also be
70d5454ce1SVedant Kumar // dead-stripped.
71d5454ce1SVedant Kumar 
72d5454ce1SVedant Kumar // PRF_CNTS: Contents of (__DATA,__llvm_prf_cnts) section
736c439a38SVedant Kumar // PRF_CNTS-NEXT: {{.*}} 00 00 00 00 00 00 00 00
74