[PATCH 0/2] s390: Avoid relocation overflows on undefined weak symbols

Alan Modra amodra@gmail.com
Wed Jul 3 00:43:28 GMT 2024


On Mon, Jul 01, 2024 at 04:33:20PM +0200, Jens Remus wrote:
> I had a quick look at bfd.ld AArch64 and PPC64. As you listed they both
> replace branches with NOPs. Yet it is unclear to me how/where they deal with
> (function) pointers resolving to zero.

ppc64 does nothing special.  As with most other targets, you need to
write
  if (foo)
    foo ();
when dealing with a weak function foo that may or may not be defined
at runtime.  However, if you know the function will be resolved at
link time (static linking, or -z nodynamic-undefined-weak) then you
can just write
  foo ();
and get the same behaviour as
  if (foo)
    foo ();

So replacing a branch and link with a nop is only useful in special
cases, and of course doesn't apply if you're calling via a function
pointer.

-- 
Alan Modra


More information about the Binutils mailing list