Linker version script turning weak symbols into strong symbols

Kevin P. Fleming kpfleming@digium.com
Tue May 26 16:25:00 GMT 2009


I'm debugging a build issue in Asterisk, and have tracked down the
problem to this small example:

==== test2.c =====

> #include <stdio.h>
> 
> static void __foo_internal(void)
> {
> 	printf("Test2\n");
> }
> 
> void __attribute__((weak, alias("__foo_internal"))) foo(void);
> 
> void test2(void)
> {
> 	printf("2\n");
> 	foo();
> }

Compiling this with "gcc -shared -o test2.so test2.c" results in the
'foo' symbol appearing in the symbol table as weak (nm reports 'W') as
expected.

However, if I use this linker version script:

> {
> 	local:
> 		*;
> };

in this way: "gcc -shared -o test2.so test2.c
-Wl,--version-script,default.exports"

then the 'foo' symbol is turned into a text-section ('t') symbol and is
no longer weak. Is this expected behavior? If so, is there some
reasonable method to avoid it? We use this version-script method to
ensure that modules that are built for Asterisk do not accidentally
expose any symbols to the global namespace unless explicitly allowed,
but it appears to be interfering with our use of weak symbols.

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kpfleming@digium.com
Check us out at www.digium.com & www.asterisk.org



More information about the Binutils mailing list