unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Michael Matz <matz@suse.de>
To: Florian Weimer <fweimer@redhat.com>
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	bug-gnulib@gnu.org,
	"H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>,
	Bruno Haible <bruno@clisp.org>,
	Binutils <binutils@sourceware.org>
Subject: Re: Undefined use of weak symbols in gnulib
Date: Wed, 28 Apr 2021 13:15:09 +0000 (UTC)	[thread overview]
Message-ID: <alpine.LSU.2.20.2104281310370.4716@wotan.suse.de> (raw)
In-Reply-To: <87h7jqkdrn.fsf@oldenburg.str.redhat.com>

Hello,

On Wed, 28 Apr 2021, Florian Weimer via Binutils wrote:

> > commit 954b63d4c8645f86e40c7ef6c6d60acd2bf019de
> > Author: Alan Modra <amodra@gmail.com>
> > 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.

  reply	other threads:[~2021-04-28 13:15 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27  5:53 Undefined use of weak symbols in gnulib Florian Weimer via Libc-alpha
2021-04-27  6:50 ` Paul Eggert
2021-04-27  6:58   ` Florian Weimer via Libc-alpha
2021-04-27  7:13     ` Paul Eggert
2021-04-27  7:24 ` Andreas Schwab
2021-04-27 11:06   ` Florian Weimer via Libc-alpha
2021-04-28  0:09     ` Bruno Haible
2021-04-28  2:10       ` H.J. Lu via Libc-alpha
2021-04-28  2:13         ` H.J. Lu via Libc-alpha
2021-05-05 20:31           ` Fangrui Song
2021-04-28  8:35         ` Florian Weimer via Libc-alpha
2021-04-28 13:15           ` Michael Matz [this message]
2021-04-28  7:44       ` Florian Weimer via Libc-alpha
2021-04-28 14:48         ` Bruno Haible
2021-04-28 17:44           ` Florian Weimer via Libc-alpha
2021-07-17 14:38         ` Bruno Haible
2021-07-17 14:55           ` Florian Weimer via Libc-alpha
2021-07-17 16:39             ` Bruno Haible
2021-07-27 20:02           ` Joseph Myers
2021-07-27 20:19             ` Florian Weimer via Libc-alpha
2021-07-27 23:38               ` Paul Eggert
2021-04-27 23:22   ` Bruno Haible
2021-04-27 23:47 ` Bruno Haible
2021-04-28  7:57   ` Florian Weimer via Libc-alpha
2021-04-28 14:40     ` Bruno Haible
2021-04-28 17:43       ` Florian Weimer via Libc-alpha
2021-04-29 15:15         ` Bruno Haible
2021-04-30  9:55           ` Florian Weimer via Libc-alpha
2021-04-29  6:33       ` Ben Pfaff via Libc-alpha
2021-05-03  1:44 ` Alan Modra via Libc-alpha
2021-07-12 10:04 ` Michael Hudson-Doyle via Libc-alpha
2021-07-12 15:03   ` Florian Weimer via Libc-alpha
2021-07-12 15:30     ` Matthias Klose
2021-07-12 15:37       ` Florian Weimer via Libc-alpha
2021-07-13  0:22         ` Michael Hudson-Doyle via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.2104281310370.4716@wotan.suse.de \
    --to=matz@suse.de \
    --cc=binutils@sourceware.org \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).