This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
behavior of weak definitions in archive libraries
- From: David Mosberger <davidm at napali dot hpl dot hp dot com>
- To: binutils at sources dot redhat dot com
- Cc: eranian at napali dot hpl dot hp dot com, davidm at napali dot hpl dot hp dot com
- Date: Tue, 11 Nov 2003 14:08:47 -0800
- Subject: behavior of weak definitions in archive libraries
- Reply-to: davidm at hpl dot hp dot com
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