1 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -c %s -o %t-callbacks.o
2 // RUN: %clang_dfsan -gmlt -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-reaches-function-callbacks=1 %s %t-callbacks.o -o %t
3 // RUN: %run %t 2>&1 | FileCheck %s
5 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -DORIGIN_TRACKING -c %s -o %t-callbacks.o
6 // RUN: %clang_dfsan -gmlt -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-reaches-function-callbacks=1 -mllvm -dfsan-track-origins=2 %s %t-callbacks.o -o %t
7 // RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-ORIGIN-TRACKING %s
9 // Tests that callbacks are inserted for reached functions when
10 // -dfsan-reaches-function-callbacks is specified.
15 #include <sanitizer/dfsan_interface.h>
18 // Compile this code without DFSan to avoid recursive instrumentation.
20 void my_dfsan_reaches_function_callback(dfsan_label label
, dfsan_origin origin
,
21 const char *file
, unsigned int line
,
22 const char *function
) {
23 #ifdef ORIGIN_TRACKING
24 dfsan_print_origin_id_trace(origin
);
26 printf("%s:%d %s\n", file
, line
, function
);
32 __attribute__((noinline
)) uint64_t add(uint64_t *a
, uint64_t *b
) {
35 // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] add.dfsan
36 // CHECK-ORIGIN-TRACKING: Origin value: 0x10000002, Taint value was stored to memory at
37 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 3]]:{{.*}}
38 // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
39 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in main {{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
42 extern void my_dfsan_reaches_function_callback(dfsan_label label
,
46 const char *function
);
48 int main(int argc
, char *argv
[]) {
50 dfsan_set_reaches_function_callback(my_dfsan_reaches_function_callback
);
55 dfsan_set_label(8, &a
, sizeof(a
));
56 uint64_t c
= add(&a
, &b
);
57 // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] main
58 // CHECK-ORIGIN-TRACKING: Origin value: 0x10000002, Taint value was stored to memory at
59 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan {{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
60 // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
61 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in main {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 6]]:{{.*}}
65 #endif // #ifdef CALLBACKS