This is the mail archive of the binutils@sources.redhat.com 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]

behavior of weak definitions in archive libraries


We're seeing a problem which appears to come from an unexpected (to
me) behavior of the linker: it appears that if a program has a weak
reference to a symbol in an archive object and there is no other
reason for the archive object to be linked in, then the weak reference
will end up being resolved to NULL.

For example:

$ cat weak.c
int weakref = 13;
$ gcc -c weak.c
$ ar rv libweak.a weak.o
r - weak.o
$ cat t.c
#include <stdio.h>

extern int weakref __attribute__((weak));

int main (int argc, char **argv) {
  printf ("weakref=%p\n", &weakref);
  return 0;
}
$ gcc t.c libweak.a
$ ./a.out
weakref=(nil)

Is this behavior intentional?  I'm seeing it both on ia64 and x86
(linux).

	--david


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