From patchwork Thu May 11 20:52:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 92847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4659528vqo; Thu, 11 May 2023 13:53:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Cpbn0HhJ+6pO80266gKHBZfZBylHnJKnuKm+A0dEy6wO8FYwjRtHttt49IQWoUVD02zlr X-Received: by 2002:a05:6402:216:b0:50b:bfee:ea26 with SMTP id t22-20020a056402021600b0050bbfeeea26mr16194919edv.35.1683838403887; Thu, 11 May 2023 13:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683838403; cv=none; d=google.com; s=arc-20160816; b=hK5fN3iowt966EJwrz1tVip1Lf0mDlgJMRVmlIw8slNxDiGVpi3TcjYIqMtuA7M/Js nqYZICzIJGlZ4y6eA/zbKWEyWEIxSwLXIa8IF8yCAVTzNjY5OahGz+ogyQ9h0ln1abQK tjT6zmrOBviqVpDZ33t/25unkPGe2YnjwmGJTgRr3VTt8CMrBq5PJTNUThrfckArh5F+ FIFtR93ZcGBvu+yKAH/8W7o5rTQMSgRzz6M7197iL2epAo4kSdZ0w3QpSp5PWmvIAIhk TJPDn/RVZbVlyoUB02zmwF1FdjJCtX/O0NhDQgE5GhyYZ8Cdb/bIKZqOQHazGjonQVK0 beVQ== 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:cc:to:subject :message-id:date:in-reply-to:references:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=RKYySIpioQyP+GJvofg3IvS/w/CcC6ndB68/CrthHN4=; b=rkoPoXUEHJ2uoMncHVf0QfLKcbAjWDI9jO2/VclrKJel3dwrjgHRNNgOeF6FzXd7I4 Rxd2ySjYP8yu20e+URMc4drOWuMxS2oJpV5gpSAcvPiyKUvS5tTdul6nmXQyLmFW1ZPV 0jORGs5qo3VfMzZHFBRpOlmNClpGN3KDlKAUS52OiGOlrEo5IBs/nXT8A+QNkZOGYmSa Rk/Oie7q1T0B8+YJjJYEg2eS2N6fViTTcO60g42o+25zc2/6BDCjVmyyToVy1WC0MdjY jmXazurJfq7stfL7KJvVk2qgF5wQ69Iq+ccormJM3ixJ7x7bRQtRlJsbsI9WRqdVwuXK aeAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=E49pXsTH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g25-20020aa7c859000000b0050d8a7fb5absi5355876edt.299.2023.05.11.13.53.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 13:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=E49pXsTH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 5275F3857343 for ; Thu, 11 May 2023 20:53:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5275F3857343 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683838401; bh=RKYySIpioQyP+GJvofg3IvS/w/CcC6ndB68/CrthHN4=; h=References:In-Reply-To:Date:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=E49pXsTHDj119g8+8s5ry2d9R+8aQpZjZbUm1MMV4w8S+84f8xgz6lmgeflGeVPop 1i1t7IcL/SWpobAGSyRtt+6LSfgNzMpWdXiwMvYyE03Dn+wzWuZjVR4hqYB1GnyHev rLj1d2p4EozTiCexNAap1niPpmv1xzzFxappNyro= 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 29D843858D1E for ; Thu, 11 May 2023 20:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29D843858D1E Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-546-kjXj2SbrOSqDH3_HB07Rmw-1; Thu, 11 May 2023 16:52:35 -0400 X-MC-Unique: kjXj2SbrOSqDH3_HB07Rmw-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-4edd54a0eaeso5340141e87.0 for ; Thu, 11 May 2023 13:52:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683838353; x=1686430353; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vhYfl4CcC89Y6dNZsBVhHovXEmniD3wfhrgcxRhLtL4=; b=UoBFwWKbg829rq//jESFwwm+YdIwla+x1l6wM/GUbsEnh4Kvr/vra/DAFtsIHdTyOC iBmp6cGk/ld2bcMuWA1xdJLDCMgWmOLjDcfxyDQ5D7OVWOuCAQOHXcb8fYDo/Q1nXhsV rbo/tQVlU/LZctWulu4GyYYjsTRCs20YfzWF0//MMp3Yp+s48EgKZtsBr7TxE737tPIy dWAg7u6owHwRsm/ojwLV+Kgk4T137rM6HJ6N3Q9Uj0P2S1/cPHO3WZfPJPPkZtcw7xiK v68zIOD74Mw6w/VH3WHHyc7RjneYlLOYrWdn46nwgSAWWSQyHXHu8Wkds8+vMgcQ1baY ZJyQ== X-Gm-Message-State: AC+VfDyZHbEgxXKChJo0JaJPFjjdBuX3dkwgwKdk7J9zkQzPUAPogIRB oKARPqZG13QVGHGVGQ8MWe5yGoOIp+gCjgXwHyUqkBNrQyecg+D/VGWNzbh1lIKbRlwRAxD8149 WhwXTjubAUVLFtkI2++gWzIVzLzfdocehPQ== X-Received: by 2002:a2e:9818:0:b0:2a8:c842:d30c with SMTP id a24-20020a2e9818000000b002a8c842d30cmr3952906ljj.44.1683838353620; Thu, 11 May 2023 13:52:33 -0700 (PDT) X-Received: by 2002:a2e:9818:0:b0:2a8:c842:d30c with SMTP id a24-20020a2e9818000000b002a8c842d30cmr3952901ljj.44.1683838353312; Thu, 11 May 2023 13:52:33 -0700 (PDT) MIME-Version: 1.0 References: <20230510112009.633444-1-jwakely@redhat.com> In-Reply-To: Date: Thu, 11 May 2023 21:52:22 +0100 Message-ID: Subject: [PATCH v2] libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer To: Mike Crowe Cc: "libstdc++" , gcc Patches , Thomas Rodgers X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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?1765632538321393698?= On Thu, 11 May 2023 at 13:42, Jonathan Wakely wrote: > > > On Thu, 11 May 2023 at 13:19, Mike Crowe wrote: > >> However, ... >> >> > > 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 >> >> TSan does appear to have an interceptor for pthread_cond_clockwait, even >> if >> it lacks the others. Does this mean that this part is unnecessary? >> > > Ah good point, thanks. I grepped for clocklock but not clockwait. > In fact it seems like we don't need to change _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK either, because I don't get any tsan warnings for that. It doesn't have interceptors for pthread_rwlock_{rd,wr}lock, but it doesn't complain anyway (maybe it's simply not instrumenting the rwlock functions at all?!) So I'm now retesting with this version of the patch, which only touches the USE_PTHREAD_LOCKLOCK macro. Please take another look, thanks. commit 4fc14825c125eece32980df21d09da35e3d5bac6 Author: Jonathan Wakely Date: Tue May 9 09:30:48 2023 libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer As noted in https://github.com/llvm/llvm-project/issues/62623 there are no tsan interceptors for some of the new POSIX-1:202x APIs added by https://austingroupbugs.net/view.php?id=1216 so tsan gives false positive warnings for try_lock_for on timed mutexes. Disable the uses of the new pthread_mutex_clocklock API when tsan is active. This changes the semantics of the try_lock_for 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_MUTEX_CLOCKLOCK): Define _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK in terms of _GLIBCXX_TSAN. * configure: Regenerate. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 89e7f5f5f45..dce3d16aa5c 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -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"