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