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