Strong symbol in shared library overridden by weak symbol in static library?

Jie Jiang robbie.jiang@gmail.com
Wed Apr 10 13:25:00 GMT 2013


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



More information about the Libc-help mailing list