This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Patch to not create GOT and dynamic relocation entries for unresolved symbols with --warn-unresolved-symbols.
- From: Sriraman Tallam <tmsriram at google dot com>
- To: binutils <binutils at sourceware dot org>, Cary Coutant <ccoutant at google dot com>, Paul Pluzhnikov <ppluzhnikov at google dot com>, Rong Xu <xur at google dot com>, Brooks Moses <bmoses at google dot com>, Ollie Wild <aaw at google dot com>, David Li <davidxl at google dot com>, Teresa Johnson <tejohnson at google dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>, Ian Lance Taylor <iant at google dot com>, ccoutant at gmail dot com
- Date: Fri, 10 Apr 2015 17:22:49 -0700
- Subject: Re: Patch to not create GOT and dynamic relocation entries for unresolved symbols with --warn-unresolved-symbols.
- Authentication-results: sourceware.org; auth=none
- References: <CAAs8Hmxe3fNV-7MLyNhk_=DOaR91-s=dFw3E-cFdqCCiGxxreA at mail dot gmail dot com>
+ccoutant@gmail.com
On Fri, Apr 10, 2015 at 5:15 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Hi,
>
> We have a problem where we use --warn-unresolved-symbols to tide
> over an issue where we know the symbol is undefined but we also know
> that the it is never accessed.
>
> Example:
>
> extern int foo();
>
> int (*p)() = NULL;
> int main() {
> if (p == &foo)
> foo();
> return 0;
> }
>
> Now,
>
> $ g++ -O2 foo.cc
> foo.cc:function main: warning: undefined reference to 'foo()'
>
> gives the right warning but builds a.out just fine and runs fine as
> long as p is not equal to foo which is our case.
>
> However, with -fPIE
>
> $ g++ -O2 -fPIE foo.cc -pie
> foo.cc:function main: warning: undefined reference to 'foo()'
>
> but
> $./a.out
> ./a.out: symbol lookup error: ./a.out: undefined symbol: _Z3foov
>
> because with fPIE, a function pointer access is using a GOTPCREL
> relocation which creates a GOT entry and a dynamic relocation for it.
> The dynamic linker does not like the unresolved symbol any more.
>
> I have attached a patch to prevent creation of GOT and dynamic
> relocation entries with --warn-unresolved-symbols in general. Is this
> reasonable?
>
>
> Thanks
> Sri