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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2A4263894419 for ; Tue, 27 Apr 2021 11:06:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A4263894419 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-115-QtWj6GPtNpW6U5dpKlKXfQ-1; Tue, 27 Apr 2021 07:06:18 -0400 X-MC-Unique: QtWj6GPtNpW6U5dpKlKXfQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A485181CAF1; Tue, 27 Apr 2021 11:06:17 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43A2860CFB; Tue, 27 Apr 2021 11:06:15 +0000 (UTC) From: Florian Weimer To: Andreas Schwab Cc: Florian Weimer via Binutils , bug-gnulib@gnu.org, libc-alpha@sourceware.org Subject: Re: Undefined use of weak symbols in gnulib References: <87o8e0p92r.fsf@oldenburg.str.redhat.com> <87fszc8a1z.fsf@igel.home> Date: Tue, 27 Apr 2021 13:06:43 +0200 In-Reply-To: <87fszc8a1z.fsf@igel.home> (Andreas Schwab's message of "Tue, 27 Apr 2021 09:24:08 +0200") Message-ID: <87eeewnfzw.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 11:06:24 -0000 * Andreas Schwab: > On Apr 27 2021, Florian Weimer via Binutils wrote: > >> I think we can provide an libBrokenGnulib.so preload module which >> defines pthread_mutexattr_gettype to zero (as an absolute address), so >> there is a kludge to keep old binaries working, but this is really >> something that must be fixed in gnulib. > > It is likely that the use of weak pthread symbols is not confined to > gnulib. True. Here's a fairly representative test case, I think. #include #include extern __typeof (pthread_key_create) __pthread_key_create __attribute__ ((w= eak)); extern __typeof (pthread_once) pthread_once __attribute__ ((weak)); void f1 (void) { puts ("f1 called"); } pthread_once_t once_var; void __attribute__ ((weak)) f2 (void) { if (__pthread_key_create !=3D NULL) pthread_once (&once_var, f1); } int main (void) { f2 (); } Building it with =E2=80=9Cgcc -O2 -fpie -pie=E2=80=9D and linking with binu= tils 2.30 does not result in a crash with LD_PRELOAD=3Dlibpthread.so.0. That's because the call-to-address-zero via pthread_once has been stubbed out with NOPs, I think. This is still not correct and will undoubtedly cause problems because pthread_once is usually called for its side effect. With binutils 2.35, the call-to-address-zero is not stubbed out anymore, but there is still no dynamic symbol reference for pthread_once, so there is a crash when running with LD_PRELOAD=3Dlibpthread.so.0. This looks like a pre-existing toolchain issue on POWER, related to the thread I quoted at the start. If we proceed with the glibc libpthread changes as planned, things might turn out unacceptably bad. I did a quick experiment and we cannot work around this using a libpthread.so stub library and compatibility-only symbols in libc.so.6. Unversioned weak symbols bind to the baseline symbol version, as they probably should. Even a __pthread_key_create@GLIBC_2.17 compatibility symbol triggers this issue. I have to think of something else to salvage this. Thanks, Florian