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.133.124]) by sourceware.org (Postfix) with ESMTP id 032DE3896819 for ; Wed, 28 Apr 2021 07:56:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 032DE3896819 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-424-1PWOvFqJNi6tkgCiOArcKw-1; Wed, 28 Apr 2021 03:56:41 -0400 X-MC-Unique: 1PWOvFqJNi6tkgCiOArcKw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5C9C801106; Wed, 28 Apr 2021 07:56:40 +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 71A025D9F0; Wed, 28 Apr 2021 07:56:39 +0000 (UTC) From: Florian Weimer To: Bruno Haible Cc: bug-gnulib@gnu.org, libc-alpha@sourceware.org, binutils@sourceware.org Subject: Re: Undefined use of weak symbols in gnulib References: <87o8e0p92r.fsf@oldenburg.str.redhat.com> <19516512.8WduG5kV5J@omega> Date: Wed, 28 Apr 2021 09:57:08 +0200 In-Reply-To: <19516512.8WduG5kV5J@omega> (Bruno Haible's message of "Wed, 28 Apr 2021 01:47:10 +0200") Message-ID: <875z06lu3v.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.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Wed, 28 Apr 2021 07:56:45 -0000 * Bruno Haible: > You write: >> Dynamic linking with weak symbols is not very well-defined. ... >> the code will crash if pthread_mutexattr_gettype is ever defined. > > In which situations will it crash? > > (a) when the code is in an executable, that gets linked with '-lpthread' > and that does not use dlopen()? The pthread_mutexattr_gettype is defined, but also pthread_once and the weak symbols, so there is no problem because the link editor doesn't do funny things. > (b) when the code is in an executable, that gets linked WITHOUT > '-lpthread' and that does not use dlopen()? Yes, it will crash or behave incorrectly on most architectures *if* pthread_mutexattr_gettype becomes available for some reason. > (c) when the code is in an executable, that gets linked WITHOUT > '-lpthread' and that does a dlopen("libpthread.so.X")? This will probably work because pthread_mutexattr_gettype is not rebound to the definition. > Under which conditions will it crash? > > ($) when the executable was built before glibc 2.34 and is run > with glibc 2.34 ? Yes. > (%) when the executable is built against glibc 2.34 and is run > with glibc 2.34 ? No. glibc 2.34 will behave as if an implicit -lpthread is present on the linker program line. > And if it crashes, will setting the environment variable LD_DYNAMIC_WEAK [1] > avoid the crash? No, it's unrelated. The crash or other undefined behavior is a consequence of actions of the link editor and cannot be reverted at run time. The best we can do is to hide definitions of symbols like pthread_mutexattr_gettype, therefore masking the existence of those corrupted code paths (like glibc 2.33 and earlier do). Thanks for looking into this. Thanks, Florian