This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Strong symbol in shared library overridden by weak symbol in static library?
- From: Jie Jiang <robbie dot jiang at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Wed, 10 Apr 2013 15:25:26 +0200
- Subject: Strong symbol in shared library overridden by weak symbol in static library?
Hi all,
In my test, the strong symbol in a shared library seems to be
overridden by a weak symbol in a static library. But in general,
strong symbol should have higher priority!
Here is my testing code:
% cat strong.c
#include <stdio.h>
extern void bar();
void foo ()
{
bar();
printf("%s:%s\n", __FILE__, __func__);
}
% gcc -fPIC -shared -o libstrong.so strong.c
% cat weak.c
#include <stdio.h>
extern void foo() __attribute__((weak));
extern void bar();
void foo ()
{
printf("%s:%s\n", __FILE__, __func__);
}
void bar()
{
printf("%s:%s\n", __FILE__, __func__);
}
% gcc -fPIC -c weak.c
% ar cr libweak.a weak.o
% cat test.c
extern void foo();
int main (int argc, char ** argv)
{
foo();
return 0;
}
% gcc test.c -L. -lstrong -lweak
%./a.out
weak.c: foo
<------- Here we can see the symbol 'foo' in the final a.out is a weak
symbol, not a strong symbol!
% gcc --verison
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Any idea?
Regards,
Jie