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 -Wl,-opt:noref %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 11 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:ref %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 14 15 /// link.exe does not support weak overridding weak. 16 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-lldmingw,-opt:ref %t0.o %t2.o -o %t2 17 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 18 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2 19 20 /// Repeat the above tests with -ffunction-sections (associative comdat). 21 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -o %t0.o 22 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_1 -o %t1.o 23 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_2 -o %t2.o 24 25 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:noref %t0.o %t1.o -o %t1 26 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 27 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1 28 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:ref %t0.o %t1.o -o %t1 29 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1 30 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1 31 32 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-lldmingw,-opt:ref %t0.o %t2.o -o %t2 33 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2 34 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2 35 36 // CHECK1: strong 37 // CHECK1: strong 38 39 /// Document the current behavior: 40 /// __profc_?weak@@YAXXZ in %t1.o is local and has a zero value. 41 /// Without GC it takes a duplicate entry. 42 // PROFILE1: ?weak@@YAXXZ: 43 // PROFILE1-NEXT: Hash: 44 // PROFILE1-NEXT: Counters: 1 45 // PROFILE1-NEXT: Function count: 0 46 // PROFILE1: ?weak@@YAXXZ: 47 // PROFILE1-NEXT: Hash: 48 // PROFILE1-NEXT: Counters: 1 49 // PROFILE1-NEXT: Function count: 2 50 51 // CHECK2: weak 52 // CHECK2: weak 53 54 /// __profc__Z4weakv in %t2.o is weak and resolves to the value of %t0.o's copy. 55 /// Without GC it takes a duplicate entry. 56 // PROFILE2: ?weak@@YAXXZ: 57 // PROFILE2-NEXT: Hash: 58 // PROFILE2-NEXT: Counters: 1 59 // PROFILE2-NEXT: Function count: 2 60 // PROFILE2: ?weak@@YAXXZ: 61 // PROFILE2-NEXT: Hash: 62 // PROFILE2-NEXT: Counters: 1 63 // PROFILE2-NEXT: Function count: 2 64 65 #ifdef OBJ_1 66 #include <stdio.h> 67 68 void weak() { puts("strong"); } 69 void foo() { weak(); } 70 71 #elif defined(OBJ_2) 72 #include <stdio.h> 73 74 __attribute__((weak)) void weak() { puts("unreachable"); } 75 void foo() { weak(); } 76 77 #else 78 #include <stdio.h> 79 80 __attribute__((weak)) void weak() { puts("weak"); } 81 void foo(); 82 83 int main() { 84 foo(); 85 weak(); 86 } 87 #endif 88