From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 727071F5AE for ; Tue, 27 Apr 2021 05:53:09 +0000 (UTC) Received: from localhost ([::1]:47232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbGeh-0006gA-Q1 for normalperson@yhbt.net; Tue, 27 Apr 2021 01:53:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbGeX-0006fo-Gq for bug-gnulib@gnu.org; Tue, 27 Apr 2021 01:52:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbGeV-0002YC-PA for bug-gnulib@gnu.org; Tue, 27 Apr 2021 01:52:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619502774; 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: content-transfer-encoding:content-transfer-encoding; bh=YEcFHdos/RbqzAy58LhMvPjplehsjFYYq5KA3G2dJKA=; b=cyXRtTuVGj+5TvRx0wcYPNWJ+YPUUAO2nnaG+WAXaIoavJuluvEXSV0s6yGKSoWccLNxJb HdvQfuhlceClCqFnAvBrp8EGILFe5U8ACUYW3vdjyLNgGosZV49hAcDKyOtLGsHvo8Axvm DC6AslL8b9ELyMQA7xZig/rV8isRsL4= 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-286-w6_SWtqYP2206xm9jIGC6g-1; Tue, 27 Apr 2021 01:52:51 -0400 X-MC-Unique: w6_SWtqYP2206xm9jIGC6g-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 B433B8189C3; Tue, 27 Apr 2021 05:52:50 +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 8E11760636; Tue, 27 Apr 2021 05:52:49 +0000 (UTC) From: Florian Weimer To: bug-gnulib@gnu.org Subject: Undefined use of weak symbols in gnulib Date: Tue, 27 Apr 2021 07:53:16 +0200 Message-ID: <87o8e0p92r.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.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=fweimer@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=170.10.133.124; envelope-from=fweimer@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libc-alpha@sourceware.org, binutils@sourceware.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" lib/glthread/lock.h has this: | /* The way to test at runtime whether libpthread is present is to test | whether a function pointer's value, such as &pthread_mutex_init, is | non-NULL. However, some versions of GCC have a bug through which, in | PIC mode, &foo !=3D NULL always evaluates to true if there is a direct | call to foo(...) in the same function. To avoid this, we test the | address of a function in libpthread that we don't use. */ |=20 | # pragma weak pthread_mutex_init | # pragma weak pthread_mutex_lock | # pragma weak pthread_mutex_unlock | # pragma weak pthread_mutex_destroy | # pragma weak pthread_rwlock_init | # pragma weak pthread_rwlock_rdlock | # pragma weak pthread_rwlock_wrlock | # pragma weak pthread_rwlock_unlock | # pragma weak pthread_rwlock_destroy | # pragma weak pthread_once | [=E2=80=A6] And: | # if !PTHREAD_IN_USE_DETECTION_HARD | # pragma weak pthread_mutexattr_gettype | # define pthread_in_use() \ | (pthread_mutexattr_gettype !=3D NULL || c11_threads_in_use ()) | # endif As far as I can tell gnulib uses this macro definition to implement gl_once on glibc targets: | # define glthread_once(ONCE_CONTROL, INITFUNCTION) \ | (pthread_in_use () = \ | ? pthread_once (ONCE_CONTROL, INITFUNCTION) = \ | : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), = 0) : 0)) So the net effect is this: if (pthread_mutexattr_gettype !=3D NULL) pthread_once (control, callback); Dynamic linking with weak symbols is not very well-defined. On x86-64, the link editor produces the expected dynamic symbol relocation for the pthread_once call. On other targets (notably POWER), no dynamic relocation is produced, and the code will crash if pthread_mutexattr_gettype is ever defined. There is an old thread here covering related issues: Specify how undefined weak symbol should be resolved in executable On glibc targets, there is another problem: weak references do not carry symbol versions, so they can bind to base versions unexpectedly. This will become an urgent issue with glibc 2.34, which defines pthread_mutexattr_gettype unconditionally. Certain gnulib modules will stop working until the binaries are relinked. I expect the issue is already visible with earlier glibc versions if libpthread is unexpectedly present at run time. 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. Thanks, Florian