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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DDC481F5AE for ; Wed, 28 Apr 2021 07:56:52 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9884397081F; Wed, 28 Apr 2021 07:56:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9884397081F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619596606; bh=+gLJtp9ipTWMQKer8Br1vubhlLljNHXet3k1yVPv3Fc=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MS/lu0P/BloDRvNKpWgXTneKORywSVNt+Mt7D/Lh6dxUIrr9A3v1d1sOBMoZb+Dh0 F+sZhR4/9M0vFGcFQHWhhZ3VHJVF3V2ZONCIxVPFeo9rdea01vgmxxnmuofbFfFqgS WdH0NCHCmQtSkrzmQDZ9378J6Z7vjdz1hE5Ca3so= 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) To: Bruno Haible 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-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: , From: Florian Weimer via Libc-alpha Reply-To: Florian Weimer Cc: libc-alpha@sourceware.org, bug-gnulib@gnu.org, binutils@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" * 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