Skip to content

Commit

Permalink
[DFSan] Support fast16labels mode in dfsan_union.
Browse files Browse the repository at this point in the history
While the instrumentation never calls dfsan_union in fast16labels mode,
the custom wrappers do.  We detect fast16labels mode by checking whether
any labels have been created.  If not, we must be using fast16labels
mode.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D86012
  • Loading branch information
morehouse committed Aug 17, 2020
1 parent 3060894 commit 69721fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler-rt/lib/dfsan/dfsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ dfsan_label __dfsan_union(dfsan_label l1, dfsan_label l2) {
if (l2 == 0)
return l1;

// If no labels have been created, yet l1 and l2 are non-zero, we are using
// fast16labels mode.
if (atomic_load(&__dfsan_last_label, memory_order_relaxed) == 0)
return l1 | l2;

if (l1 > l2)
Swap(l1, l2);

Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/test/dfsan/custom.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
// RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
// RUN: %clang_dfsan -DFAST_16_LABELS -mllvm -dfsan-fast-16-labels %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
// RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
// RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES -mllvm -dfsan-args-abi %s -o %t && %run %t

Expand Down Expand Up @@ -952,10 +953,19 @@ void test_snprintf() {
}

int main(void) {
#ifdef FAST_16_LABELS
i_label = 1;
j_label = 2;
k_label = 4;
#else
i_label = dfsan_create_label("i", 0);
j_label = dfsan_create_label("j", 0);
k_label = dfsan_create_label("k", 0);
#endif
i_j_label = dfsan_union(i_label, j_label);
assert(i_j_label != i_label);
assert(i_j_label != j_label);
assert(i_j_label != k_label);

test_calloc();
test_clock_gettime();
Expand Down

0 comments on commit 69721fc

Please sign in to comment.