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.6 required=3.0 tests=AWL,BAYES_00, 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 2B16D1F5AE for ; Wed, 28 Apr 2021 13:29:32 +0000 (UTC) Received: from localhost ([::1]:35418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbkFu-000317-VF for normalperson@yhbt.net; Wed, 28 Apr 2021 09:29:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbk2C-0006IS-Lm for bug-gnulib@gnu.org; Wed, 28 Apr 2021 09:15:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:42752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbk26-0007J1-Ky for bug-gnulib@gnu.org; Wed, 28 Apr 2021 09:15:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F41ACB180; Wed, 28 Apr 2021 13:15:09 +0000 (UTC) Date: Wed, 28 Apr 2021 13:15:09 +0000 (UTC) From: Michael Matz To: Florian Weimer Subject: Re: Undefined use of weak symbols in gnulib In-Reply-To: <87h7jqkdrn.fsf@oldenburg.str.redhat.com> Message-ID: References: <87o8e0p92r.fsf@oldenburg.str.redhat.com> <87fszc8a1z.fsf@igel.home> <87eeewnfzw.fsf@oldenburg.str.redhat.com> <1680226.UWtE2gOZdF@omega> <87h7jqkdrn.fsf@oldenburg.str.redhat.com> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Received-SPF: pass client-ip=195.135.220.15; envelope-from=matz@suse.de; helo=mx2.suse.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=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-Mailman-Approved-At: Wed, 28 Apr 2021 09:29:27 -0400 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: Andreas Schwab , bug-gnulib@gnu.org, "H.J. Lu via Libc-alpha" , Bruno Haible , Binutils Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hello, On Wed, 28 Apr 2021, Florian Weimer via Binutils wrote: > > commit 954b63d4c8645f86e40c7ef6c6d60acd2bf019de > > Author: Alan Modra > > Date: Wed Apr 19 01:26:57 2017 +0930 > > > > Implement -z dynamic-undefined-weak > > > > -z nodynamic-undefined-weak is only implemented for x86. (The sparc > > backend has some support code but doesn't enable the option by > > including ld/emulparams/dynamic_undefined_weak.sh, and since the > > support looks like it may be broken I haven't enabled it.) This patch > > adds the complementary -z dynamic-undefined-weak, extends both options > > to affect building of shared libraries as well as executables, and > > adds support for the option on powerpc. > > I'm not sure if this option is compatible with all compilers on POWER. > > The old binutils behavior allowed the compiler to optimize this common > pattern > > void f1 (void) __attribute__ ((weak)); > > void > f2 (void) > { > if (f1 != 0) > f1 (); > } > > into an unconditional call to f1 because the linker would replace the > call with a NOP if the symbol is undefined, reproducing the effect of > the if condition. However, GCC 10 does not appear to perform this > optimization on powerpc64le. GCC assumes addresses of functions to be non-null, _except when declared weak_. Over the years we fixed problem in that aspect always into that direction (hence the above testcase should always be emitted with an actual test, otherwise it would be considered a bug worth fixing). That would be consistent with making undefined weak symbols dynamic in the ELF case, so that the ultimate test survives until runtime. I don't know what other compilers are doing, of course. Ciao, Michael.