[TSan] Initialize libdispatch interceptors if necessary

On Linux (and other non-Darwin platforms) we need to initialize
interceptors. Since tsan_libdispatch.cc is compiled optionally, add a
weak default implementation of `InitializeLibdispatchInterceptors`.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D59113

llvm-svn: 355717
This commit is contained in:
Julian Lettner 2019-03-08 19:52:45 +00:00
parent 782ac933b5
commit 9e18875ba3
2 changed files with 46 additions and 0 deletions

View File

@ -2621,6 +2621,9 @@ static void unreachable() {
}
#endif
// Define default implementation since interception of libdispatch is optional.
SANITIZER_WEAK_ATTRIBUTE void InitializeLibdispatchInterceptors() {}
void InitializeInterceptors() {
#if !SANITIZER_MAC
// We need to setup it early, because functions like dlsym() can call it.
@ -2638,6 +2641,7 @@ void InitializeInterceptors() {
InitializeCommonInterceptors();
InitializeSignalInterceptors();
InitializeLibdispatchInterceptors();
#if !SANITIZER_MAC
// We can not use TSAN_INTERCEPT to get setjmp addr,

View File

@ -723,4 +723,46 @@ TSAN_INTERCEPTOR(void, dispatch_resume, dispatch_object_t o) {
return REAL(dispatch_resume)(o);
}
void InitializeLibdispatchInterceptors() {
INTERCEPT_FUNCTION(dispatch_async);
INTERCEPT_FUNCTION(dispatch_async_f);
INTERCEPT_FUNCTION(dispatch_sync);
INTERCEPT_FUNCTION(dispatch_sync_f);
INTERCEPT_FUNCTION(dispatch_barrier_async);
INTERCEPT_FUNCTION(dispatch_barrier_async_f);
INTERCEPT_FUNCTION(dispatch_barrier_sync);
INTERCEPT_FUNCTION(dispatch_barrier_sync_f);
INTERCEPT_FUNCTION(dispatch_after);
INTERCEPT_FUNCTION(dispatch_after_f);
INTERCEPT_FUNCTION(dispatch_once);
INTERCEPT_FUNCTION(dispatch_once_f);
INTERCEPT_FUNCTION(dispatch_semaphore_signal);
INTERCEPT_FUNCTION(dispatch_semaphore_wait);
INTERCEPT_FUNCTION(dispatch_group_wait);
INTERCEPT_FUNCTION(dispatch_group_leave);
INTERCEPT_FUNCTION(dispatch_group_async);
INTERCEPT_FUNCTION(dispatch_group_async_f);
INTERCEPT_FUNCTION(dispatch_group_notify);
INTERCEPT_FUNCTION(dispatch_group_notify_f);
INTERCEPT_FUNCTION(dispatch_source_set_event_handler);
INTERCEPT_FUNCTION(dispatch_source_set_event_handler_f);
INTERCEPT_FUNCTION(dispatch_source_set_cancel_handler);
INTERCEPT_FUNCTION(dispatch_source_set_cancel_handler_f);
INTERCEPT_FUNCTION(dispatch_source_set_registration_handler);
INTERCEPT_FUNCTION(dispatch_source_set_registration_handler_f);
INTERCEPT_FUNCTION(dispatch_apply);
INTERCEPT_FUNCTION(dispatch_apply_f);
INTERCEPT_FUNCTION(dispatch_data_create);
INTERCEPT_FUNCTION(dispatch_read);
INTERCEPT_FUNCTION(dispatch_write);
INTERCEPT_FUNCTION(dispatch_io_read);
INTERCEPT_FUNCTION(dispatch_io_write);
INTERCEPT_FUNCTION(dispatch_io_barrier);
INTERCEPT_FUNCTION(dispatch_io_create);
INTERCEPT_FUNCTION(dispatch_io_create_with_path);
INTERCEPT_FUNCTION(dispatch_io_create_with_io);
INTERCEPT_FUNCTION(dispatch_io_close);
INTERCEPT_FUNCTION(dispatch_resume);
}
} // namespace __tsan