This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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]

Weak symbols not overriden


Hi All,

I found weak symbols wouldn't be overriden by the strong symbols with
same names.
Here is my test code.

$cat s1.c
extern void foo(void)        __attribute__((weak, visibility("default")));
extern void function1(void)  __attribute__((visibility("default")));
void foo(void) {
	printf("Enter %s:%s\n", __FILE__,__FUNCTION__);
}
void function1(void) {
	printf("Enter %s:%s\n", __FILE__,__FUNCTION__);
}

$cat s2.c
extern void foo(void)        __attribute__((visibility("default")));
extern void function2(void)  __attribute__((visibility("default")));
void foo(void) {
	printf("Enter %s:%s\n", __FILE__,__FUNCTION__);
}
void function2(void) {
	printf("Enter %s:%s\n", __FILE__,__FUNCTION__);
}

$cat main.c
extern void foo(void);
extern void function1(void);
extern void function2(void);
int main() {
	foo();
	function1();
	function2();
	return 0;
}

$gcc -fpic -shared -fvisibility=hidden -O2 -o libs1.so s1.c
$gcc -fpic -shared -fvisibility=hidden -O2 -o libs2.so s2.c
$gcc -O2 -o foo -Wl,-rpath=. main.c libs1.so libs2.so
$nm -D libs1.so
00000480 W foo
$nm -D libs2.so
00000480 T foo
$./foo
Enter s1.c:foo
Enter s1.c:function1
Enter s2.c:function2

The result means the `foo' function in libs1.so is called, not that in
libso2.so,
even if `foo' is a weak in libs1.so and is strong in libso2.so.
What's wrong?

PRC
Mar 17,2011


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