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=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham 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 1DFC11F5AE for ; Wed, 28 Apr 2021 07:57:04 +0000 (UTC) Received: from localhost ([::1]:50554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbf4A-0007Js-Py for normalperson@yhbt.net; Wed, 28 Apr 2021 03:57:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbf44-0007JI-JE for bug-gnulib@gnu.org; Wed, 28 Apr 2021 03:56:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbf3x-0004o0-F7 for bug-gnulib@gnu.org; Wed, 28 Apr 2021 03:56:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619596605; 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=+gLJtp9ipTWMQKer8Br1vubhlLljNHXet3k1yVPv3Fc=; b=IEvcb/SGltz3I/PQxdu16+H8RAfR80CUmly0k5ESh+rwBn3JT47pm9F+QNlZRa5c/NAq0K rVw9ML00I03BTgtGnZkAphP8t7PubwoWMPPBZrXvnFMW2McoNfXIcYzG7dut6Da+IN1HRG 1muimK0nXnMjV29TsZcSBoU6yKapjvQ= 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 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 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 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.218, 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=unavailable 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, bug-gnulib@gnu.org, binutils@sourceware.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * 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