From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 348463858C78 for ; Wed, 10 May 2023 11:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 348463858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683717623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Gx3So6rkZXfmcbSg2aNHm7/NewZyM2YIrsXz6FMRJ1U=; b=dDUFJKCh89uQzs77Lr/uQ540jD47VwSl2HbM7XXjP9WhtW0ULDsdytk1eRZMEU/wo5aauP WcMLPBXT0fI5PwyJLTNKzv1i/HshTkU892eVmf6OR7JUYgzoQNNKr96xsgD6hkR8taYtRT TZm4cCPzKv5UrUnzLPwxSGL56oieDlA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-XJR1Qqw7NlSzmRO2i2HcUA-1; Wed, 10 May 2023 07:20:17 -0400 X-MC-Unique: XJR1Qqw7NlSzmRO2i2HcUA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B156885620; Wed, 10 May 2023 11:20:17 +0000 (UTC) Received: from localhost (unknown [10.42.28.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA04C40C2077; Wed, 10 May 2023 11:20:15 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Mike Crowe Subject: [RFC] libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer Date: Wed, 10 May 2023 12:20:09 +0100 Message-Id: <20230510112009.633444-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This patch would avoid TSan false positives when using timed waiting functions on mutexes and condvars, but as noted below, it changes the semantics. I'm not sure whether we want this workaround in place until tsan gets fixed. On one hand, there's no guarantee that those functions use the right clock anyway (and they won't do unless a recent-ish glibc is used). But on the other hand, if they normally would use the right clock because you have glibc support, it's not ideal for tsan to cause a different clock to be used. -- >8 -- As noted in https://github.com/llvm/llvm-project/issues/62623 there are no tsan interceptors for the new POSIX-1:202x APIs added by https://austingroupbugs.net/view.php?id=1216 so tsan gives false positive warnings. Disable the uses of the new APIs when tsan is active. This changes the semantics of those functions, because it can change which clock is used for the wait. This means those functions might be affected by system clock adjustments when tsan is used, when they would not be affected otherwise. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT): Define _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT to depend on _GLIBCXX_TSAN. (GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK): Likewise for _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK. (GLIBCXX_CHECK_PTHREAD_RWLOCK_CLOCKLOCK): Likewise for _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK. * configure: Regenerate. --- libstdc++-v3/acinclude.m4 | 6 +++--- libstdc++-v3/configure | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 89e7f5f5f45..e2700b05ec3 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -4284,7 +4284,7 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT], [ [glibcxx_cv_PTHREAD_COND_CLOCKWAIT=no]) ]) if test $glibcxx_cv_PTHREAD_COND_CLOCKWAIT = yes; then - AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, 1, [Define if pthread_cond_clockwait is available in .]) + AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, (_GLIBCXX_TSAN==0), [Define if pthread_cond_clockwait is available in .]) fi CXXFLAGS="$ac_save_CXXFLAGS" @@ -4314,7 +4314,7 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK], [ [glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK=no]) ]) if test $glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK = yes; then - AC_DEFINE(_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK, 1, [Define if pthread_mutex_clocklock is available in .]) + AC_DEFINE(_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK, (_GLIBCXX_TSAN==0), [Define if pthread_mutex_clocklock is available in .]) fi CXXFLAGS="$ac_save_CXXFLAGS" @@ -4346,7 +4346,7 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_RWLOCK_CLOCKLOCK], [ [glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK=no]) ]) if test $glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK = yes; then - AC_DEFINE(_GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK, 1, [Define if pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock are available in .]) + AC_DEFINE(_GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK, (_GLIBCXX_TSAN==0), [Define if pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock are available in .]) fi CXXFLAGS="$ac_save_CXXFLAGS"