Skip to content

Commit 35f76e1

Browse files
committed
[TSan] guard lock_during_write flag on Apple platforms to exclude Go
There are currently build errors when checking the TSan Go runtime due to the implementation of this flag: ``` ../rtl/tsan_rtl.cpp:46:11: error: no member named 'cur_thread_init' in namespace '__tsan' 46 | __tsan::cur_thread_init()->in_internal_write_call = value; | ^~~~~~~~~~~~~~~ ../../sanitizer_common/sanitizer_mac.cpp:109:38: error: redefinition of '__tsan_set_in_internal_write_call' 109 | SANITIZER_WEAK_ATTRIBUTE extern void __tsan_set_in_internal_write_call( | ^ ../rtl/tsan_rtl.cpp:45:13: note: previous definition is here 45 | extern void __tsan_set_in_internal_write_call(bool value) { | ^ ``` This patch guards all changes related to the flag behind `!SANITIZER_GO` to avoid these errors occurring. (cherry picked from commit 79c8397)
1 parent 3f02985 commit 35f76e1

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ extern "C" {
9898
mach_msg_type_number_t *infoCnt);
9999
}
100100

101+
# if !SANITIZER_GO
101102
// Weak symbol no-op when TSan is not linked
102103
SANITIZER_WEAK_ATTRIBUTE extern void __tsan_set_in_internal_write_call(
103104
bool value) {}
105+
# endif
104106

105107
namespace __sanitizer {
106108

@@ -172,11 +174,15 @@ uptr internal_read(fd_t fd, void *buf, uptr count) {
172174
}
173175

174176
uptr internal_write(fd_t fd, const void *buf, uptr count) {
177+
# if SANITIZER_GO
178+
return write(fd, buf, count);
179+
# else
175180
// We need to disable interceptors when writing in TSan
176181
__tsan_set_in_internal_write_call(true);
177182
uptr res = write(fd, buf, count);
178183
__tsan_set_in_internal_write_call(false);
179184
return res;
185+
# endif
180186
}
181187

182188
uptr internal_stat(const char *path, void *buf) {

compiler-rt/lib/tsan/rtl/tsan_flags.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "tsan_rtl.h"
2121
#include "ubsan/ubsan_flags.h"
2222

23-
#if SANITIZER_APPLE
23+
#if SANITIZER_APPLE && !SANITIZER_GO
2424
namespace __sanitizer {
2525

2626
template <>
@@ -55,7 +55,7 @@ inline bool FlagHandler<LockDuringWriteSetting>::Format(char *buffer,
5555
}
5656

5757
} // namespace __sanitizer
58-
#endif
58+
#endif // SANITIZER_APPLE && !SANITIZER_GO
5959

6060
namespace __tsan {
6161

compiler-rt/lib/tsan/rtl/tsan_flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "sanitizer_common/sanitizer_flags.h"
1717
#include "sanitizer_common/sanitizer_deadlock_detector_interface.h"
1818

19-
#if SANITIZER_APPLE
19+
#if SANITIZER_APPLE && !SANITIZER_GO
2020
enum LockDuringWriteSetting {
2121
kLockDuringAllWrites,
2222
kNoLockDuringWritesCurrentProcess,

compiler-rt/lib/tsan/rtl/tsan_flags.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TSAN_FLAG(bool, print_full_thread_history, false,
8181
"If set, prints thread creation stacks for the threads involved in "
8282
"the report and their ancestors up to the main thread.")
8383

84-
#if SANITIZER_APPLE
84+
#if SANITIZER_APPLE && !SANITIZER_GO
8585
TSAN_FLAG(LockDuringWriteSetting, lock_during_write, kLockDuringAllWrites,
8686
"Determines whether to obtain a lock while writing logs or error "
8787
"reports. "

compiler-rt/lib/tsan/rtl/tsan_interceptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef TSAN_INTERCEPTORS_H
22
#define TSAN_INTERCEPTORS_H
33

4-
#if SANITIZER_APPLE
4+
#if SANITIZER_APPLE && !SANITIZER_GO
55
# include "sanitizer_common/sanitizer_mac.h"
66
#endif
77
#include "sanitizer_common/sanitizer_stacktrace.h"
@@ -47,7 +47,7 @@ inline bool in_symbolizer() {
4747

4848
inline bool MustIgnoreInterceptor(ThreadState *thr) {
4949
return !thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib
50-
#if SANITIZER_APPLE
50+
#if SANITIZER_APPLE && !SANITIZER_GO
5151
|| (flags()->lock_during_write != kLockDuringAllWrites &&
5252
thr->in_internal_write_call)
5353
#endif

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "sanitizer_common/sanitizer_tls_get_addr.h"
3232
#include "sanitizer_common/sanitizer_vector.h"
3333
#include "tsan_fd.h"
34-
#if SANITIZER_APPLE
34+
#if SANITIZER_APPLE && !SANITIZER_GO
3535
# include "tsan_flags.h"
3636
#endif
3737
#include "tsan_interceptors.h"
@@ -1668,7 +1668,7 @@ TSAN_INTERCEPTOR(int, pthread_barrier_wait, void *b) {
16681668

16691669
TSAN_INTERCEPTOR(int, pthread_once, void *o, void (*f)()) {
16701670
SCOPED_INTERCEPTOR_RAW(pthread_once, o, f);
1671-
#if SANITIZER_APPLE
1671+
#if SANITIZER_APPLE && !SANITIZER_GO
16721672
if (flags()->lock_during_write != kLockDuringAllWrites &&
16731673
cur_thread_init()->in_internal_write_call) {
16741674
// This is needed to make it through process launch without hanging

compiler-rt/lib/tsan/rtl/tsan_rtl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SANITIZER_WEAK_DEFAULT_IMPL
4040
void __tsan_test_only_on_fork() {}
4141
#endif
4242

43-
#if SANITIZER_APPLE
43+
#if SANITIZER_APPLE && !SANITIZER_GO
4444
// Override weak symbol from sanitizer_common
4545
extern void __tsan_set_in_internal_write_call(bool value) {
4646
__tsan::cur_thread_init()->in_internal_write_call = value;
@@ -901,7 +901,7 @@ void ForkChildAfter(ThreadState* thr, uptr pc, bool start_thread) {
901901
ThreadIgnoreSyncBegin(thr, pc);
902902
}
903903

904-
# if SANITIZER_APPLE
904+
# if SANITIZER_APPLE && !SANITIZER_GO
905905
// This flag can have inheritance disabled - we are the child so act
906906
// accordingly
907907
if (flags()->lock_during_write == kNoLockDuringWritesCurrentProcess)

compiler-rt/lib/tsan/rtl/tsan_rtl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct alignas(SANITIZER_CACHE_LINE_SIZE) ThreadState {
236236

237237
const ReportDesc *current_report;
238238

239-
#if SANITIZER_APPLE
239+
#if SANITIZER_APPLE && !SANITIZER_GO
240240
bool in_internal_write_call;
241241
#endif
242242

0 commit comments

Comments
 (0)