weak symbols

Nicolas Sauzede nicolas.sauzede at st.com
Wed Oct 30 15:13:10 UTC 2013


Hello,

This is my first post to the uClibc mailing-list.
I have a question related to weak API symbols of the uClibc.

I have noticed that, when linking a static binary against the uClibc, 
that certain symbols,
such as 'abort', are not defined as weak symbol.
The end result is that this kind of trivial program my_abort.c :

void abort()
{
     while(1);
}
int main()
{
     abort();
     return 0;
}

can not be compiled with :
gcc -static my_abort -L<uclibc/path> -lc

it fails with :
<uclibc/path>/usr/i386-linux-uclibc/usr/lib/libc.a(abort.os): In 
function `__GI_abort':
<uclibc/sources>/uClibc-0.9.33.2/libc/stdlib/abort.c:61: multiple 
definition of `abort'
my_abort.o:my_abort.c:12: first defined here
collect2: error: ld returned 1 exit status

When I try this using newlib or glibc, it works, because the 'abort' 
symbol is defined as weak.

One workaround/solution would be to modify libc/stdlib/abort.c :
-libc_hidden_def(abort)
+libc_hidden_weak(abort)

What is the rationale behind defining (or not) such symbols as weak, to 
let the user override
implementation (as string alias), while still getting the weak symbols 
as default implementation ?

Thanks by advance,
NS.



More information about the uClibc mailing list