bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/22269] Undefined weak symbols isn't resolved to 0 in static PIE


From: hjl.tools at gmail dot com
Subject: [Bug ld/22269] Undefined weak symbols isn't resolved to 0 in static PIE
Date: Tue, 10 Oct 2017 23:36:19 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=22269

--- Comment #10 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Alan Modra from comment #9)
> > Since call is PC relative, this doesn't branch to address 0.
> 
> I don't see why this matters.  A symbol that resolves to zero without
> dynamic relocs in a PIE or shared lib results in an address of zero.  If
> that zero is in a PC-relative instruction then you get zero relative to the
> shared library or PIE base.  Typical code for dealing with weakly defined
> functions like
>   if (foo)
>     foo ();
> will give you a load of zero (absolute) on the condition, but a relative
> zero for the call.

If there is a program bug:

  foo ();

without if (foo) check, PC relative branch to base may not crash and may
lead to undesired behavior.

> > This doesn't work with
> > 
> > -pie --no-dynamic-linker -z dynamic-undefined-weak
> 
> Define "doesn't work".  I would have said that combination of options ought
> to result in a dynamic reloc for "func" on the original testcase.  Which is
> what powerpc will do.  It may not work in the runtime environment for static
> PIE, but that's a different issue.  By passing -z dynamic-undefined-weak you
> asked for dynamic relocs!

-z dynamic-undefined-weak applies to there is a DT_NEEDED entry which
may provide definition for undefined weak reference at run-time.  For static
PIE, weak undefined should always be resolved to 0.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]