1 | // Tests trace pc guard coverage collection. |
2 | // |
3 | // REQUIRES: has_sancovcc,stable-runtime,x86_64-linux |
4 | // |
5 | // RUN: DIR=%t_workdir |
6 | // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard" |
7 | // RUN: rm -rf $DIR |
8 | // RUN: mkdir -p $DIR |
9 | // RUN: cd $DIR |
10 | // RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC |
11 | // RUN: %clangxx -DSTATIC1 $CLANG_ARGS %s -c -o %t_2.o |
12 | // RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.o |
13 | // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s |
14 | // RUN: rm -rf $DIR |
15 | |
16 | #include <stdio.h> |
17 | #include <stdint.h> |
18 | #include <stdlib.h> |
19 | |
20 | extern "C" { |
21 | int bar(); |
22 | int baz(); |
23 | } |
24 | |
25 | #ifdef MAIN |
26 | |
27 | extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) { |
28 | fprintf(stderr, "__sanitizer_cov_trace_pc_guard_init\n" ); |
29 | } |
30 | |
31 | extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) { } |
32 | |
33 | |
34 | int foo() { |
35 | fprintf(stderr, "foo\n" ); |
36 | return 1; |
37 | } |
38 | |
39 | int main() { |
40 | fprintf(stderr, "main\n" ); |
41 | foo(); |
42 | bar(); |
43 | baz(); |
44 | } |
45 | |
46 | #endif // MAIN |
47 | |
48 | extern "C" { |
49 | |
50 | #ifdef SHARED1 |
51 | int bar() { |
52 | fprintf(stderr, "bar\n" ); |
53 | return 1; |
54 | } |
55 | #endif |
56 | |
57 | #ifdef STATIC1 |
58 | int baz() { |
59 | fprintf(stderr, "baz\n" ); |
60 | return 1; |
61 | } |
62 | #endif |
63 | |
64 | } // extern "C" |
65 | |
66 | // Init is called once per DSO. |
67 | // CHECK: __sanitizer_cov_trace_pc_guard_init |
68 | // CHECK-NEXT: __sanitizer_cov_trace_pc_guard_init |
69 | // CHECK-NEXT: main |
70 | // CHECK-NEXT: foo |
71 | // CHECK-NEXT: bar |
72 | // CHECK-NEXT: baz |
73 | |