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