1 | // RUN: %clang_dfsan -mllvm -dfsan-fast-16-labels=true %s -o %t && %run %t |
2 | // |
3 | // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \ |
4 | // RUN: %run %t >%t.out 2>&1 |
5 | // RUN: FileCheck %s < %t.out |
6 | // |
7 | // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && \ |
8 | // RUN: %run %t >%t.out 2>&1 |
9 | // RUN: FileCheck %s < %t.out |
10 | // |
11 | // REQUIRES: x86_64-target-arch |
12 | |
13 | #include <sanitizer/dfsan_interface.h> |
14 | |
15 | #include <assert.h> |
16 | #include <pthread.h> |
17 | #include <string.h> |
18 | |
19 | const int kNumThreads = 24; |
20 | int x = 0; |
21 | int __thread y, z; |
22 | |
23 | static void *ThreadFn(void *a) { |
24 | y = x; |
25 | assert(dfsan_get_label(y) == 8); |
26 | memcpy(&z, &y, sizeof(y)); |
27 | if ((int)a == 7) |
28 | dfsan_print_origin_trace(&z, NULL); |
29 | return 0; |
30 | } |
31 | |
32 | int main(void) { |
33 | dfsan_set_label(8, &x, sizeof(x)); |
34 | |
35 | pthread_t t[kNumThreads]; |
36 | for (size_t i = 0; i < kNumThreads; ++i) |
37 | pthread_create(&t[i], 0, ThreadFn, (void *)i); |
38 | |
39 | for (size_t i = 0; i < kNumThreads; ++i) |
40 | pthread_join(t[i], 0); |
41 | |
42 | return 0; |
43 | } |
44 | |
45 | // CHECK: Taint value 0x8 {{.*}} origin tracking () |
46 | // CHECK: Origin value: {{.*}}, Taint value was stored to memory at |
47 | // CHECK: #0 {{.*}} in dfs$ThreadFn {{.*}}pthread.c:[[@LINE-21]] |
48 | |
49 | // CHECK: Origin value: {{.*}}, Taint value was stored to memory at |
50 | // CHECK: #0 {{.*}} in dfs$ThreadFn {{.*}}pthread.c:[[@LINE-26]] |
51 | |
52 | // CHECK: Origin value: {{.*}}, Taint value was created at |
53 | // CHECK: #0 {{.*}} in main {{.*}}pthread.c:[[@LINE-20]] |
54 | |