File tree Expand file tree Collapse file tree 6 files changed +439
-0
lines changed Expand file tree Collapse file tree 6 files changed +439
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ library_for_all_configs("libdart_platform") {
1111 sources = platform_sources
1212 include_dirs = [ " .." ]
1313 extra_deps = []
14+ configurable_deps = [ " :libdart_platform_no_tsan" ]
1415
1516 if (is_fuchsia ) {
1617 extra_deps += [
@@ -19,3 +20,22 @@ library_for_all_configs("libdart_platform") {
1920 ]
2021 }
2122}
23+
24+ config (" no_tsan_config" ) {
25+ if (! is_win ) {
26+ cflags = [ " -fno-sanitize=thread" ]
27+ }
28+ }
29+
30+ library_for_all_configs (" libdart_platform_no_tsan" ) {
31+ target_type = " source_set"
32+ public_configs = [
33+ " ../vm:libdart_vm_config" ,
34+ " :no_tsan_config" ,
35+ ]
36+ sources = [
37+ " no_tsan.cc" ,
38+ " no_tsan.h" ,
39+ ]
40+ include_dirs = [ " .." ]
41+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ #include " platform/no_tsan.h"
6+
7+ namespace dart {
8+
9+ #if defined(__clang__)
10+
11+ #if defined(__has_feature)
12+ #if __has_feature(thread_sanitizer)
13+ #error Misconfigured build
14+ #endif
15+ #endif
16+
17+ uintptr_t FetchAndRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr,
18+ uintptr_t value) {
19+ return ptr->fetch_and (value, std::memory_order_relaxed);
20+ }
21+
22+ uintptr_t FetchOrRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr,
23+ uintptr_t value) {
24+ return ptr->fetch_or (value, std::memory_order_relaxed);
25+ }
26+
27+ uintptr_t LoadRelaxedIgnoreRace (const std::atomic<uintptr_t >* ptr) {
28+ return ptr->load (std::memory_order_relaxed);
29+ }
30+
31+ #endif // defined(__clang__)
32+
33+ } // namespace dart
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ #ifndef RUNTIME_PLATFORM_NO_TSAN_H_
6+ #define RUNTIME_PLATFORM_NO_TSAN_H_
7+
8+ #include < stdint.h>
9+
10+ #include < atomic>
11+
12+ namespace dart {
13+
14+ #if defined(__clang__)
15+ // Clang does not honor no_sanitize(thread) for std::atomic, so we place
16+ // the implementation in a separate compilation unit with TSAN disabled.
17+ uintptr_t FetchAndRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr,
18+ uintptr_t value);
19+ uintptr_t FetchOrRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr,
20+ uintptr_t value);
21+ uintptr_t LoadRelaxedIgnoreRace (const std::atomic<uintptr_t >* ptr);
22+ #else
23+ #if defined(__GNUC__)
24+ __attribute__ ((no_sanitize(" thread" )))
25+ #endif
26+ inline uintptr_t
27+ FetchAndRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr, uintptr_t value) {
28+ return ptr->fetch_and (value, std::memory_order_relaxed);
29+ }
30+ #if defined(__GNUC__)
31+ __attribute__ ((no_sanitize(" thread" )))
32+ #endif
33+ inline uintptr_t
34+ FetchOrRelaxedIgnoreRace (std::atomic<uintptr_t >* ptr, uintptr_t value) {
35+ return ptr->fetch_or (value, std::memory_order_relaxed);
36+ }
37+ #if defined(__GNUC__)
38+ __attribute__ ((no_sanitize(" thread" )))
39+ #endif
40+ inline uintptr_t
41+ LoadRelaxedIgnoreRace (const std::atomic<uintptr_t >* ptr) {
42+ return ptr->load (std::memory_order_relaxed);
43+ }
44+ #endif
45+
46+ } // namespace dart
47+
48+ #endif // RUNTIME_PLATFORM_NO_TSAN_H_
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ cc/IsolateReload_PendingStaticCall_DefinedToNSM: Fail # Issue 32981
1111cc/IsolateReload_PendingStaticCall_NSMToDefined: Fail, Crash # Issue 32981. Fails on non-Windows, crashes on Windows (because of test.py special handline)
1212cc/IsolateReload_PendingUnqualifiedCall_InstanceToStatic: Fail # Issue 32981
1313cc/IsolateReload_PendingUnqualifiedCall_StaticToInstance: Fail # Issue 32981
14+ cc/MutatorMarkerRace_Relaxed: Pass, Fail # Comparison to demonstrate race, failure seen on Mac M1.
15+ cc/MutatorMarkerRace_ReleaseHeader: Pass, Fail # Comparison to demonstrate race, failure seen on Windows Snapdragon.
1416cc/TTS_STC_ManyAsserts: Pass, Slow # Generates 10k classes that are put into an STC via assert checks.
1517cc/TypeArguments_Cache_ManyInstantiations: Pass, Slow
1618dart/analyze_snapshot_binary_test: Pass, Slow # Runs various subprocesses for testing AOT.
Original file line number Diff line number Diff line change @@ -85,6 +85,10 @@ void ClassTable::Register(const Class& cls) {
8585 classes_.GetColumn <kClassIndex >());
8686 UpdateCachedAllocationTracingStateTablePointer ();
8787 } else {
88+ // GCC warns that TSAN doesn't understand thread fences.
89+ #if defined(__GNUC__) && !defined(__clang__)
90+ #pragma GCC diagnostic ignored "-Wtsan"
91+ #endif
8892 std::atomic_thread_fence (std::memory_order_release);
8993 }
9094}
You can’t perform that action at this time.
0 commit comments