Skip to content

Commit

Permalink
[tsan] Intercept __tls_get_addr_earlier
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arichardson committed Mar 9, 2024
1 parent 6c76506 commit 578e66a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,17 @@ void InitializeInterceptors() {

new(interceptor_ctx()) InterceptorContext();

// Interpose __tls_get_addr before the common interposers. This is needed
// because dlsym() may call malloc on failure which could result in other
// interposed functions being called that could eventually make use of TLS.
#ifdef NEED_TLS_GET_ADDR
# if !SANITIZER_S390
TSAN_INTERCEPT(__tls_get_addr);
# else
TSAN_INTERCEPT(__tls_get_addr_internal);
TSAN_INTERCEPT(__tls_get_offset);
# endif
#endif
InitializeCommonInterceptors();
InitializeSignalInterceptors();
InitializeLibdispatchInterceptors();
Expand Down Expand Up @@ -3010,15 +3021,6 @@ void InitializeInterceptors() {
TSAN_INTERCEPT(__cxa_atexit);
TSAN_INTERCEPT(_exit);

#ifdef NEED_TLS_GET_ADDR
#if !SANITIZER_S390
TSAN_INTERCEPT(__tls_get_addr);
#else
TSAN_INTERCEPT(__tls_get_addr_internal);
TSAN_INTERCEPT(__tls_get_offset);
#endif
#endif

TSAN_MAYBE_INTERCEPT__LWP_EXIT;
TSAN_MAYBE_INTERCEPT_THR_EXIT;

Expand Down

0 comments on commit 578e66a

Please sign in to comment.