89 lines · cpp
1// REQUIRES: lld-available2 3// REQUIRES: target={{.*windows-msvc.*}}4// RUN: %clang_profgen -fcoverage-mapping -c %s -o %t0.o5// RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_1 -o %t1.o6// RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_2 -o %t2.o7 8/// An external symbol can override a weak external symbol.9// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:noref %t0.o %t1.o -o %t110// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK111// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE112// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:ref %t0.o %t1.o -o %t113// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK114// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE115 16/// link.exe does not support weak overridding weak.17// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-lld-allow-duplicate-weak,-opt:ref %t0.o %t2.o -o %t218// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK219// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE220 21/// Repeat the above tests with -ffunction-sections (associative comdat).22// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -o %t0.o23// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_1 -o %t1.o24// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_2 -o %t2.o25 26// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:noref %t0.o %t1.o -o %t127// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK128// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE129// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-opt:ref %t0.o %t1.o -o %t130// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK131// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE132 33// RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,-lld-allow-duplicate-weak,-opt:ref %t0.o %t2.o -o %t234// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK235// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE236 37// CHECK1: strong38// CHECK1: strong39 40/// Document the current behavior:41/// __profc_?weak@@YAXXZ in %t1.o is local and has a zero value.42/// Without GC it takes a duplicate entry.43// PROFILE1: ?weak@@YAXXZ:44// PROFILE1-NEXT: Hash:45// PROFILE1-NEXT: Counters: 146// PROFILE1-NEXT: Function count: 047// PROFILE1: ?weak@@YAXXZ:48// PROFILE1-NEXT: Hash:49// PROFILE1-NEXT: Counters: 150// PROFILE1-NEXT: Function count: 251 52// CHECK2: weak53// CHECK2: weak54 55/// __profc__Z4weakv in %t2.o is weak and resolves to the value of %t0.o's copy.56/// Without GC it takes a duplicate entry.57// PROFILE2: ?weak@@YAXXZ:58// PROFILE2-NEXT: Hash:59// PROFILE2-NEXT: Counters: 160// PROFILE2-NEXT: Function count: 261// PROFILE2: ?weak@@YAXXZ:62// PROFILE2-NEXT: Hash:63// PROFILE2-NEXT: Counters: 164// PROFILE2-NEXT: Function count: 265 66#ifdef OBJ_167#include <stdio.h>68 69void weak() { puts("strong"); }70void foo() { weak(); }71 72#elif defined(OBJ_2)73#include <stdio.h>74 75__attribute__((weak)) void weak() { puts("unreachable"); }76void foo() { weak(); }77 78#else79#include <stdio.h>80 81__attribute__((weak)) void weak() { puts("weak"); }82void foo();83 84int main() {85 foo();86 weak();87}88#endif89