| 1 | // REQUIRES: lld-available |
| 2 | |
| 3 | // FIXME: Investigate and fix. |
| 4 | // XFAIL: powerpc64-target-arch |
| 5 | |
| 6 | // RUN: %clang_profgen -fcoverage-mapping -c %s -o %t0.o |
| 7 | // RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_1 -o %t1.o |
| 8 | // RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_2 -o %t2.o |
| 9 | |
| 10 | /// An external symbol can override a weak external symbol. |
| 11 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t1.o -o %t1 |
| 12 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 |
| 13 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC |
| 14 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t1.o -o %t1 |
| 15 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 |
| 16 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC |
| 17 | |
| 18 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t2.o -o %t2 |
| 19 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 |
| 20 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_NOGC |
| 21 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t2.o -o %t2 |
| 22 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 |
| 23 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_GC |
| 24 | |
| 25 | /// Repeat the above tests with -ffunction-sections. |
| 26 | // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -o %t0.o |
| 27 | // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_1 -o %t1.o |
| 28 | // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_2 -o %t2.o |
| 29 | |
| 30 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t1.o -o %t1 |
| 31 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 |
| 32 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC |
| 33 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t1.o -o %t1 |
| 34 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 |
| 35 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_GC |
| 36 | |
| 37 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t2.o -o %t2 |
| 38 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 |
| 39 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_NOGC |
| 40 | // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t2.o -o %t2 |
| 41 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 |
| 42 | // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_GC |
| 43 | |
| 44 | // CHECK1: strong |
| 45 | // CHECK1: strong |
| 46 | |
| 47 | /// __profc__Z4weakv in %t1.o is local and has a zero value. |
| 48 | /// Without GC it takes a duplicate entry. |
| 49 | // PROFILE1_NOGC: _Z4weakv: |
| 50 | // PROFILE1_NOGC-NEXT: Hash: |
| 51 | // PROFILE1_NOGC-NEXT: Counters: 1 |
| 52 | // PROFILE1_NOGC-NEXT: Function count: 0 |
| 53 | // PROFILE1_NOGC: _Z4weakv: |
| 54 | // PROFILE1_NOGC-NEXT: Hash: |
| 55 | // PROFILE1_NOGC-NEXT: Counters: 1 |
| 56 | // PROFILE1_NOGC-NEXT: Function count: 2 |
| 57 | |
| 58 | // PROFILE1_GC: _Z4weakv: |
| 59 | // PROFILE1_GC-NEXT: Hash: |
| 60 | // PROFILE1_GC-NEXT: Counters: 1 |
| 61 | // PROFILE1_GC-NEXT: Function count: 2 |
| 62 | // PROFILE1_GC-NOT: _Z4weakv: |
| 63 | |
| 64 | // CHECK2: weak |
| 65 | // CHECK2: weak |
| 66 | |
| 67 | /// __profc__Z4weakv in %t2.o is weak and resolves to the value of %t0.o's copy. |
| 68 | /// Without GC it takes a duplicate entry. |
| 69 | // PROFILE2_NOGC: _Z4weakv: |
| 70 | // PROFILE2_NOGC-NEXT: Hash: |
| 71 | // PROFILE2_NOGC-NEXT: Counters: 1 |
| 72 | // PROFILE2_NOGC-NEXT: Function count: 2 |
| 73 | // PROFILE2_NOGC: _Z4weakv: |
| 74 | // PROFILE2_NOGC-NEXT: Hash: |
| 75 | // PROFILE2_NOGC-NEXT: Counters: 1 |
| 76 | // PROFILE2_NOGC-NEXT: Function count: 2 |
| 77 | |
| 78 | // PROFILE2_GC: _Z4weakv: |
| 79 | // PROFILE2_GC-NEXT: Hash: |
| 80 | // PROFILE2_GC-NEXT: Counters: 1 |
| 81 | // PROFILE2_GC-NEXT: Function count: 2 |
| 82 | // PROFILE2_GC-NOT: _Z4weakv: |
| 83 | |
| 84 | #ifdef OBJ_1 |
| 85 | #include <stdio.h> |
| 86 | |
| 87 | void weak() { puts("strong" ); } |
| 88 | void foo() { weak(); } |
| 89 | |
| 90 | #elif defined(OBJ_2) |
| 91 | #include <stdio.h> |
| 92 | |
| 93 | __attribute__((weak)) void weak() { puts("unreachable" ); } |
| 94 | void foo() { weak(); } |
| 95 | |
| 96 | #else |
| 97 | #include <stdio.h> |
| 98 | |
| 99 | __attribute__((weak)) void weak() { puts(s: "weak" ); } |
| 100 | void foo(); |
| 101 | |
| 102 | int main() { |
| 103 | foo(); |
| 104 | weak(); |
| 105 | } |
| 106 | #endif |
| 107 | |