From nobody Mon Feb 07 18:43:52 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A584019B0C08; Mon, 7 Feb 2022 18:43:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jsw5h4JtRz4qhC; Mon, 7 Feb 2022 18:43:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644259432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CBcN47QNC4pfEv/CsBJwr0m/CndyVTHxMT/BjXHZwIA=; b=lPVa5ZXFSnTAhQjEstdfCnSZvWURu6Gn1BuwfIQB/pvcFNi+8eFrE2hShg++mCasvguIkq SpKy/fpdBebq1exBC3XfZvxaRZRK4HJVUntVGHxq5/BPOxEY7Rzkdji0/6AFSHZI3bOP7F TiM3NrBhfuwhS+sGW2dxMmhOsCsXN6tl9XDCDx2kwMp2U7Q10GvXuwOLbvAvr+6MNxmJrA WRH8UTfbsSWaqXfgY9QpzL6xG9K9lb1g7nmnIvZzDuHgEYnCJ0QxyUnwhnrih9bGOT01js 4GMLa14hon6dV03c8m0u+WGyKHEQ8LPoOx6HiS0VBbJ3sH0AA8w9kWG7GaF0rA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 742062E01; Mon, 7 Feb 2022 18:43:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 217IhqjL074885; Mon, 7 Feb 2022 18:43:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 217Ihq4Q074884; Mon, 7 Feb 2022 18:43:52 GMT (envelope-from git) Date: Mon, 7 Feb 2022 18:43:52 GMT Message-Id: <202202071843.217Ihq4Q074884@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dimitry Andric Subject: git: 1c21bfb1b1a3 - main - Apply fix for ThreadSanitizer false positive data race reports List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1c21bfb1b1a368f9833b9fb84ed323eeb58c5d4c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644259432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CBcN47QNC4pfEv/CsBJwr0m/CndyVTHxMT/BjXHZwIA=; b=Jrw5RMA6QSJZSZSamphyHlim9wSw4EawXDGg56LWbRyOJ/WxWVxLgSjqkXYG0QqCam8AvD W4oy64ldLyGHXGElvLJPC1R+i3NqNXyvD0O9FkA6exxkYecMbkZs6mcFlOrI1x1iuUCIu3 zSRzGupzYlDyZet1/n7hfSrKqTvUhx33nTaOupxuaFNzGc3zPx8VTuStRO/5pSMKoB0qe3 Dvf83HY+AjrcFteyUGtCHuRhgHGnZHhIiz5+vXH4I/nyXX/deKdN9pdb3WbeUH/iV2fY5z 0tPd1afvy08sWiHayeVlITAalMGJSG7LQ4OSczUiWve8OiEff3Aqw5fKwlxwTA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644259432; a=rsa-sha256; cv=none; b=LK5J2aM/vR4wncp8rIe2/0JcDMpduaQJ+180MnwD+kRPYUmZ4DS6AJqD+7SN87QIdIzVHA /U2JM5ptFzynrviqJtubSxLf0db+f5TUjHb15h0lwwPp+MTTvLUk0nxEs4mvjGdYX+eWE9 iQtRh+7LJBO7ygdI1DzTf7UpnW4tR2DxEtjKF6DTc++gVs38fjTmIWGRC+TYh1Var34qRF ek4y4fA76ZIbjjytieG/tVnPpynUjVsRJ/epDRPJ/xldawfoAdrzMNqd0ygKP3nJLjbVfw XyOewft5vZF9jY7ry9XFu3kArtEwN86PD3x9Ad+eowNKoX28thH1yE3n67PAbQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=1c21bfb1b1a368f9833b9fb84ed323eeb58c5d4c commit 1c21bfb1b1a368f9833b9fb84ed323eeb58c5d4c Author: Dimitry Andric AuthorDate: 2022-02-07 18:39:02 +0000 Commit: Dimitry Andric CommitDate: 2022-02-07 18:39:02 +0000 Apply fix for ThreadSanitizer false positive data race reports Merge commit 28fb22c90fe7 from llvm git (by Dimitry Andric): [TSan] Handle FreeBSD specific indirection of libpthread functions Similar to 60cc1d3218fc for NetBSD, add aliases and interceptors for the following pthread related functions: - pthread_cond_init(3) - pthread_cond_destroy(3) - pthread_cond_signal(3) - pthread_cond_broadcast(3) - pthread_cond_wait(3) - pthread_mutex_init(3) - pthread_mutex_destroy(3) - pthread_mutex_lock(3) - pthread_mutex_trylock(3) - pthread_mutex_unlock(3) - pthread_rwlock_init(3) - pthread_rwlock_destroy(3) - pthread_rwlock_rdlock(3) - pthread_rwlock_tryrdlock(3) - pthread_rwlock_wrlock(3) - pthread_rwlock_trywrlock(3) - pthread_rwlock_unlock(3) - pthread_once(3) - pthread_sigmask(3) In FreeBSD's libc, a number of internal aliases of the pthread functions are invoked, typically with an additional prefixed underscore, e.g. _pthread_cond_init() and so on. ThreadSanitizer needs to intercept these aliases too, otherwise some false positive reports about data races might be produced. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D119034 MFC after: 3 days --- .../compiler-rt/lib/tsan/rtl/tsan_interceptors.h | 8 +++ .../lib/tsan/rtl/tsan_interceptors_posix.cpp | 69 ++++++++++++++++++---- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.h b/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.h index c5716f53a323..344fa86ba85e 100644 --- a/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.h +++ b/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.h @@ -57,6 +57,14 @@ inline bool in_symbolizer() { #define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__) +#if SANITIZER_FREEBSD +# define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...) \ + TSAN_INTERCEPTOR(ret, _pthread_##func, __VA_ARGS__) \ + ALIAS(WRAPPER_NAME(pthread_##func)); +#else +# define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...) +#endif + #if SANITIZER_NETBSD # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) \ TSAN_INTERCEPTOR(ret, __libc_##func, __VA_ARGS__) \ diff --git a/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index dd2442842795..d6c13696edac 100644 --- a/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -292,20 +292,25 @@ void ScopedInterceptor::DisableIgnores() { } #define TSAN_INTERCEPT(func) INTERCEPT_FUNCTION(func) +#if SANITIZER_FREEBSD || SANITIZER_NETBSD +# define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION(func) +#else +# define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION_VER(func, ver) +#endif #if SANITIZER_FREEBSD -# define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION(func) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(func) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS_THR(func) -#elif SANITIZER_NETBSD -# define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION(func) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(func) \ - INTERCEPT_FUNCTION(__libc_##func) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS_THR(func) \ - INTERCEPT_FUNCTION(__libc_thr_##func) +# define TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(func) \ + INTERCEPT_FUNCTION(_pthread_##func) #else -# define TSAN_INTERCEPT_VER(func, ver) INTERCEPT_FUNCTION_VER(func, ver) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(func) -# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS_THR(func) +# define TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(func) +#endif +#if SANITIZER_NETBSD +# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(func) \ + INTERCEPT_FUNCTION(__libc_##func) +# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS_THR(func) \ + INTERCEPT_FUNCTION(__libc_thr_##func) +#else +# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(func) +# define TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS_THR(func) #endif #define READ_STRING_OF_LEN(thr, pc, s, len, n) \ @@ -2653,6 +2658,26 @@ TSAN_INTERCEPTOR(void, thr_exit, tid_t *state) { #define TSAN_MAYBE_INTERCEPT_THR_EXIT #endif +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, cond_init, void *c, void *a) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, cond_destroy, void *c) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, cond_signal, void *c) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, cond_broadcast, void *c) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, cond_wait, void *c, void *m) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, mutex_init, void *m, void *a) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, mutex_destroy, void *m) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, mutex_lock, void *m) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, mutex_trylock, void *m) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, mutex_unlock, void *m) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_init, void *l, void *a) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_destroy, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_rdlock, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_tryrdlock, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_wrlock, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_trywrlock, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, rwlock_unlock, void *l) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, once, void *o, void (*i)()) +TSAN_INTERCEPTOR_FREEBSD_ALIAS(int, sigmask, int f, void *n, void *o) + TSAN_INTERCEPTOR_NETBSD_ALIAS(int, cond_init, void *c, void *a) TSAN_INTERCEPTOR_NETBSD_ALIAS(int, cond_signal, void *c) TSAN_INTERCEPTOR_NETBSD_ALIAS(int, cond_broadcast, void *c) @@ -2884,6 +2909,26 @@ void InitializeInterceptors() { } #endif + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(cond_init); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(cond_destroy); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(cond_signal); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(cond_broadcast); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(cond_wait); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(mutex_init); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(mutex_destroy); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(mutex_lock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(mutex_trylock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(mutex_unlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_init); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_destroy); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_rdlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_tryrdlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_wrlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_trywrlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(rwlock_unlock); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(once); + TSAN_MAYBE_INTERCEPT_FREEBSD_ALIAS(sigmask); + TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(cond_init); TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(cond_signal); TSAN_MAYBE_INTERCEPT_NETBSD_ALIAS(cond_broadcast);