This is the mail archive of the 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]

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


    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.


extern int foo();

int (*p)() = NULL;
int main() {
  if (p == &foo)
  return 0;


$ g++ -O2 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 -pie main: warning: undefined reference to 'foo()'

./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


Attachment: warn_unresolved.txt
Description: Text document

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