Skip to content

Commit 578e66a

Browse files
authored
[tsan] Intercept __tls_get_addr_earlier
This can be useful because dlsym() may call malloc on failure which could result in other interposed functions being called that could eventually make use of TLS. While the crash that I experienced originally has been fixed differently (by not using global-dynamic TLS accesses in the mutex deadlock detector, see #83890), moving this interception earlier is still a good since it makes the code a bit more robust against initialization order problems. Reviewed By: MaskRay, vitalybuka Pull Request: #83886
1 parent 6c76506 commit 578e66a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,17 @@ void InitializeInterceptors() {
28632863

28642864
new(interceptor_ctx()) InterceptorContext();
28652865

2866+
// Interpose __tls_get_addr before the common interposers. This is needed
2867+
// because dlsym() may call malloc on failure which could result in other
2868+
// interposed functions being called that could eventually make use of TLS.
2869+
#ifdef NEED_TLS_GET_ADDR
2870+
# if !SANITIZER_S390
2871+
TSAN_INTERCEPT(__tls_get_addr);
2872+
# else
2873+
TSAN_INTERCEPT(__tls_get_addr_internal);
2874+
TSAN_INTERCEPT(__tls_get_offset);
2875+
# endif
2876+
#endif
28662877
InitializeCommonInterceptors();
28672878
InitializeSignalInterceptors();
28682879
InitializeLibdispatchInterceptors();
@@ -3010,15 +3021,6 @@ void InitializeInterceptors() {
30103021
TSAN_INTERCEPT(__cxa_atexit);
30113022
TSAN_INTERCEPT(_exit);
30123023

3013-
#ifdef NEED_TLS_GET_ADDR
3014-
#if !SANITIZER_S390
3015-
TSAN_INTERCEPT(__tls_get_addr);
3016-
#else
3017-
TSAN_INTERCEPT(__tls_get_addr_internal);
3018-
TSAN_INTERCEPT(__tls_get_offset);
3019-
#endif
3020-
#endif
3021-
30223024
TSAN_MAYBE_INTERCEPT__LWP_EXIT;
30233025
TSAN_MAYBE_INTERCEPT_THR_EXIT;
30243026

0 commit comments

Comments
 (0)