From patchwork Wed May 10 11:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 92032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3541206vqo; Wed, 10 May 2023 04:21:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7l4FktrPNc1z/o0hFhfHaZLcSNHaSWUQ4RX9SE8ZyYnQ0lTMjIW3iTYfqSxcZWA+mCD4t1 X-Received: by 2002:a17:907:72c3:b0:94a:7b2c:205e with SMTP id du3-20020a17090772c300b0094a7b2c205emr14444285ejc.72.1683717680804; Wed, 10 May 2023 04:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683717680; cv=none; d=google.com; s=arc-20160816; b=Ej9Zu3rqAdzBWBKEuGhL99RYpAPbZ7OVkoU0QNUHZTE/5dp0YC2nlfz5itscv/n98r CLHsBelhCdTQqUz5IFS41fLXx8zV9lHCwz4zlyrCT3c/R7b3lipGKP60kYdL7vYxD66F JH6Bv+4hXSq+t7Sg6cxA1Ix1RlqBJZQfA5FP0FWEX6n5yirua4RsSzFupiAiWTvmLr9H Wl7v2CuD87IY/6l9WQ4fDTeOD4G3IhBAF04GX9kv+ncjZ+X6EoHVDv+k16qO0n2D3Tlz Qxd1rwXzh+V8+RT3qJstvgKRbTEMSlV8cMbvy2kF50aku+Af8/YQhRZ+5kv4OMTA2APW jFOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Gx3So6rkZXfmcbSg2aNHm7/NewZyM2YIrsXz6FMRJ1U=; b=bwYYuhR4oaUgyhOXlPash9bDBINrCTKDkxkyPUwljZcYEehMy25mwkdVRIJ+uaDfNu 26mLZ2O0BEcm46Y3vmTmmReOv9WkFjx2vub4vzExDCnTkzpeYUND2VqUkgxNp/PXxo+P lS5t2T5h6PwauagA6kGocXG+R9EJI+MYbj5JS2bGc9J86sHEBBG7LJMm9hp7iOsruNYJ rMhc1LLlSR1FT8Mdu4whF4RETXtN3zNopPW42w300BnOvVe2RIo6uwBWUdkH0bsVALsT XUV6pF3uEIIf4IhSHYiv+Vrqc4QtXy6SDzhpfHQYrtr5gxxwy4IqHAjR8pW/Tv88oJiv WvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U+lSnqD2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l14-20020a170906a40e00b0094f592edc5bsi3912476ejz.1011.2023.05.10.04.21.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 04:21:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U+lSnqD2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C000738560A7 for ; Wed, 10 May 2023 11:21:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C000738560A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683717668; bh=Gx3So6rkZXfmcbSg2aNHm7/NewZyM2YIrsXz6FMRJ1U=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U+lSnqD2Fjh2Rc5AaxVvQi9vqk/05BBcFJaXwYtuMWt5qt/3nrYwkcESDo3vafc+g 6th1GB+zUiAk+/fUP6tR/3kHSNQAdCcJKLeuhKWvyldiybmzKLvjyHKQkS0fi9Y9Sj Sx0Fg83nOFBcBR1tRx/8/IHsgp+prbwgBf+nu6A8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765505950803046452?= X-GMAIL-MSGID: =?utf-8?q?1765505950803046452?= 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"