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.129.124]) by sourceware.org (Postfix) with ESMTPS id 1D3053858CDB for ; Fri, 3 Mar 2023 09:34:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D3053858CDB 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=1677836040; 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: in-reply-to:in-reply-to:references:references; bh=88suCzMCRB96bXSbNWSE6N/JE1Y11ENIBCWvYJXrY3c=; b=dYzGmmh9gJrvd824TN6E+0zGyCAXytv04CE1Bbk/7AZHnHUf09x+WtlxnW0RI5HsmFXfXe DJtam2+xGpBDyYoDy9vbsOgHXyDbqlXtUYyfsxDJaH5UbKix8X0x+PucDSxI+i0mIVIafF x+IkBoRz90N+8QsIoeLU2jSZXQRRudg= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-611-CYvOtw_tM0m96yuPvo4HvA-1; Fri, 03 Mar 2023 04:33:59 -0500 X-MC-Unique: CYvOtw_tM0m96yuPvo4HvA-1 Received: by mail-lj1-f200.google.com with SMTP id y15-20020a05651c220f00b00295c398ba39so442215ljq.11 for ; Fri, 03 Mar 2023 01:33:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=88suCzMCRB96bXSbNWSE6N/JE1Y11ENIBCWvYJXrY3c=; b=SlNDsyx97cil/xTi64dUPYSjMHyEDUGDZ3UcI4+pEyVgIUwu8S2SYCx3xcs/J2vYSy OaBN96i5zDaODq3wY9GxrgH3EXQPzlx61daAQHqqf+Gkltbi24so9w+K4P4r9xVY3I6Q bCAcMFAcM6QmmQ8z7DsozESpZPk+e6R3iZYLZTdKNC3OKWAIUR6zkbdEYcrtQ2HlcivH gieZ5Wd94Y7RbonDIL+7zdBGXkJ/iDxCWLJ4f0GIC7S+YOT64soeE5eOnPJ0myYKnE+L DAj55z0CMz+cOCHwOniRphyGdSXxIIAvi4S9ROlXyDwFQL2p9fD5TzXVyjfsirPs4XCw So6Q== X-Gm-Message-State: AO0yUKWPX+NDdO33wZyAAwXRmnOyaMxyzT86HPDV3yn5En5bUToQx9fB C8Uz2OZQI3Rv/yKiyvtw8VJxT8VKVMgXGUJe35aviAUnyHL+2KgPx7mMvs8PS3lWv+c7eRzh2EC 27UCi6kn73wgc9hPz94Y1pHqPI9eff1g= X-Received: by 2002:a05:651c:b9b:b0:295:9dc0:f204 with SMTP id bg27-20020a05651c0b9b00b002959dc0f204mr332004ljb.9.1677836037640; Fri, 03 Mar 2023 01:33:57 -0800 (PST) X-Google-Smtp-Source: AK7set9gHUfxQVltIJKuwr2THX3f8HB119wQS4RMAco9fxpojAEZBwwV6m8KEDiYO/nawpodGhyJTYylP4KTrbv3Ipk= X-Received: by 2002:a05:651c:b9b:b0:295:9dc0:f204 with SMTP id bg27-20020a05651c0b9b00b002959dc0f204mr331991ljb.9.1677836037280; Fri, 03 Mar 2023 01:33:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 3 Mar 2023 09:33:45 +0000 Message-ID: Subject: Re: [libstdc++] Use __gthread_join in jthread/95989 To: Alexandre Oliva Cc: Jonathan Wakely , gcc-patches , "libstdc++" , Bernd Edlinger X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000fe680b05f5fba4f7" X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000fe680b05f5fba4f7 Content-Type: text/plain; charset="UTF-8" On Fri, 3 Mar 2023 at 08:20, Alexandre Oliva via Libstdc++ < libstdc++@gcc.gnu.org> wrote: > On Feb 17, 2023, Jonathan Wakely wrote: > > > The proper fix is to ensure the program has a non-weak reference to > > pthread_join without extra help (or use a recent glibc where it always > > works). > > Indeed! How about this? Regstrapped on x86_64-linux-gnu, also tested > on arm-vx7r2 (gcc-12); verified that strong references are present in > 95989.o, but not in libstdc++.a or .so. Ok to install? > > (nit: the static local in a ctor of a template class may make for > multiple copies. Maybe a non-template always-inline function called by > all instantiations would be better.) > Yeah, that does seem less than ideal. Jakub previously suggested doing this for PR 61841, which was a similar problem with pthread_create: __asm ("" : : "r" (&pthread_create)); would not be optimized away. That would avoid the multiple copies. Alternatively we could get really creative and cast the addresses of both &pthread_create and &pthread_join to uintptr_t and XOR them, and pass that as the __depend argument (which is never actually dereferenced, it's only there to create a link-time dependency). > > > link pthread_join from std::thread ctor > > Like pthread_create, pthread_join may fail to be statically linked in > absent strong uses, so add to user code strong references to both when > std::thread objects are created. > > > for libstdc++-v3/ChangeLog > > * include/bits/std_thread.h (std::thread ctor): Add strong > reference to pthread_join. > > --- > libstdc++-v3/include/bits/std_thread.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/libstdc++-v3/include/bits/std_thread.h > b/libstdc++-v3/include/bits/std_thread.h > index adbd3928ff783..4bda350fa2c7b 100644 > --- a/libstdc++-v3/include/bits/std_thread.h > +++ b/libstdc++-v3/include/bits/std_thread.h > @@ -145,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > #ifdef GTHR_ACTIVE_PROXY > // Create a reference to pthread_create, not just the gthr weak > symbol. > auto __depend = reinterpret_cast(&pthread_create); > + static auto __attribute__((__used__)) __depend_join = > &pthread_join; > #else > auto __depend = nullptr; > #endif > > > -- > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ > Free Software Activist GNU Toolchain Engineer > Disinformation flourishes because many people care deeply about injustice > but very few check the facts. Ask me about > > --000000000000fe680b05f5fba4f7--