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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 48504385043C for ; Tue, 24 Nov 2020 15:06:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 48504385043C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-114-Y9PeOXhlPSa0wxuVnU9ygA-1; Tue, 24 Nov 2020 10:06:29 -0500 X-MC-Unique: Y9PeOXhlPSa0wxuVnU9ygA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8118612A2; Tue, 24 Nov 2020 15:06:28 +0000 (UTC) Received: from localhost (unknown [10.33.37.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 813BF4D; Tue, 24 Nov 2020 15:06:28 +0000 (UTC) Date: Tue, 24 Nov 2020 15:06:27 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Ensure __gthread_self doesn't call undefined weak symbol [PR 95989] Message-ID: <20201124150627.GC1312820@redhat.com> References: <20201111172442.GA163354@redhat.com> <20201111180822.GR3788@tucnak> <20201112173449.GE503596@redhat.com> <20201119214243.GI1312820@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201119214243.GI1312820@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="XjbSsFHOHxvQpKib" Content-Disposition: inline X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 24 Nov 2020 15:06:34 -0000 --XjbSsFHOHxvQpKib Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 19/11/20 21:42 +0000, Jonathan Wakely wrote: >On 12/11/20 17:34 +0000, Jonathan Wakely wrote: >>On 11/11/20 19:08 +0100, Jakub Jelinek via Libstdc++ wrote: >>>On Wed, Nov 11, 2020 at 05:24:42PM +0000, Jonathan Wakely wrote: >>>>--- a/libgcc/gthr-posix.h >>>>+++ b/libgcc/gthr-posix.h >>>>@@ -684,7 +684,14 @@ __gthread_equal (__gthread_t __t1, __gthread_t __t2) >>>>static inline __gthread_t >>>>__gthread_self (void) >>>>{ >>>>+#if __GLIBC_PREREQ(2, 27) >>> >>>What if it is a non-glibc system where __GLIBC_PREREQ macro isn't defined? >>>I think you'd get then >>>error: missing binary operator before token "(" >>>So I think you want >>>#if defined __GLIBC__ && defined __GLIBC_PREREQ >>>#if __GLIBC_PREREQ(2, 27) >>>return pthread_self (); >>>#else >>>return __gthrw_(pthread_self) (); >>>#else >>>return __gthrw_(pthread_self) (); >>>#endif >>>or similar. >> >> >>Here's a fixed version of the patch. >> >>I've moved the glibc-specific code in this_thread::get_id() into a new >>macro defined in config/os/gnu-linux/os_defines.h (where we already >>know we are dealing with glibc). That means we don't do the >>__GLIBC_PREREQ check directly in , it's hidden away in a >>target-specific header. >> >>Tested powerpc64le-linux (glibc 2.17 and 2.32), sparc-solaris2.11 and >>powerpc-aix. > >I've committed this version which only fixes this_thread::get_id() in >libstdc++, and doesn't change __gthread_self in gthr-posix.h > >Due to a recent change to replace other uses of __gthread_self with >calls to this_thread::get_id(), fixing it there fixes all uses in >libstdc++. > >Tested x86_64-linux, powerpc-aix, sparc-solaris2.11, committed to >trunk. >diff --git a/libstdc++-v3/testsuite/30_threads/jthread/95989.cc b/libstdc++-v3/testsuite/30_threads/jthread/95989.cc >new file mode 100644 >index 000000000000..46444b5ccabc >--- /dev/null >+++ b/libstdc++-v3/testsuite/30_threads/jthread/95989.cc >@@ -0,0 +1,54 @@ >+// Copyright (C) 2020 Free Software Foundation, Inc. >+// >+// This file is part of the GNU ISO C++ Library. This library is free >+// software; you can redistribute it and/or modify it under the >+// terms of the GNU General Public License as published by the >+// Free Software Foundation; either version 3, or (at your option) >+// any later version. >+ >+// This library is distributed in the hope that it will be useful, >+// but WITHOUT ANY WARRANTY; without even the implied warranty of >+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+// GNU General Public License for more details. >+ >+// You should have received a copy of the GNU General Public License along >+// with this library; see the file COPYING3. If not see >+// . >+ >+// { dg-options "-std=gnu++2a" } >+// { dg-do run { target c++2a } } >+// { dg-require-gthreads {} } >+// { dg-additional-options "-pthread" { target pthread } } >+// { dg-additional-options "-static" { target static } } >+ >+#include >+ >+// PR libstdc++/95989 >+// Segfault compiling with static libraries and using jthread::request_stop >+ >+void >+test01() >+{ >+ std::jthread t{ [] () {} }; >+} >+ >+void >+test02() >+{ >+ std::jthread t{ [] () {} }; >+ t.request_stop(); >+} >+ >+void >+test03() >+{ >+ std::jthread t{ [] {} }; >+ std::stop_callback cb(t.get_stop_token(), [] () {}); >+} >+ >+int >+main() >+{ >+ test01(); >+ test01(); >+} This test runs test01 twice, which isn't what I meant to do. Fixed by this patch (but the test is still failing, see PR 97944). Committed to trunk. --XjbSsFHOHxvQpKib Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 7e0078f8643f9204777152ed0f915b52072a05c8 Author: Jonathan Wakely Date: Tue Nov 24 13:11:13 2020 libstdc++: Run all tests in file libstdc++-v3/ChangeLog: * testsuite/30_threads/jthread/95989.cc: Run all three test functions, not just the first one twice. diff --git a/libstdc++-v3/testsuite/30_threads/jthread/95989.cc b/libstdc++-v3/testsuite/30_threads/jthread/95989.cc index 46444b5ccabc..c7a9430eee90 100644 --- a/libstdc++-v3/testsuite/30_threads/jthread/95989.cc +++ b/libstdc++-v3/testsuite/30_threads/jthread/95989.cc @@ -50,5 +50,6 @@ int main() { test01(); - test01(); + test02(); + test03(); } --XjbSsFHOHxvQpKib--