This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to not create GOT and dynamic relocation entries for unresolved symbols with --warn-unresolved-symbols.


+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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]