Skip to content

Commit 348eb30

Browse files
vedantkfredriss
authored andcommitted
[tsan] Try harder to not instrument gcov counters
GCOVProfiler::emitProfileArcs() can create many variables with names starting with "__llvm_gcov_ctr", so llvm appends a numeric suffix to most of them. Teach tsan about this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274801 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit a161bdd)
1 parent 3957141 commit 348eb30

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Transforms/Instrumentation/ThreadSanitizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ bool shouldInstrumentReadWriteFromAddress(Value *Addr) {
259259
return false;
260260
}
261261

262-
// Check if the global is in the GCOV counters array.
263-
if (GV->getName() == "__llvm_gcov_ctr")
262+
// Check if the global is in a GCOV counter array.
263+
if (GV->getName().startswith("__llvm_gcov_ctr"))
264264
return false;
265265
}
266266
return true;

test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target triple = "x86_64-apple-macosx10.9"
1212
@__profc_test_bitcast_foo = private global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8
1313

1414
@__llvm_gcov_ctr = internal global [1 x i64] zeroinitializer
15+
@__llvm_gcov_ctr.1 = internal global [1 x i64] zeroinitializer
1516

1617
define i32 @test_gep() sanitize_thread {
1718
entry:
@@ -23,6 +24,10 @@ entry:
2324
%1 = add i64 %gcovcount, 1
2425
store i64 %1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0)
2526

27+
%gcovcount.1 = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr.1, i64 0, i64 0)
28+
%2 = add i64 %gcovcount.1, 1
29+
store i64 %2, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr.1, i64 0, i64 0)
30+
2631
ret i32 1
2732
}
2833

0 commit comments

Comments
 (0)