removing symbol from shared lib

Alan Modra
Wed Nov 15 00:13:00 GMT 2006

On Tue, Nov 14, 2006 at 10:15:20PM +0100, Erik Leunissen wrote:
> I've got two object files: a.o and b.o which are going to be linked into 
> a shared lib.
> b.o defines a global symbol XXX which a.o needs. But symbol XXX is not 
> going to be needed outside the shared lib.
> What I want to accomplish is to make symbol XXX in the shared lib 
> invisible from the outside, or even remove it completely, while not 
> affecting the functionality of the shared lib.

Use __attribute__ ((visibility ("hidden"))) in the source or a linker
version script to make the symbol local to the shared lib.  That
should prevent the symbol appearing in the dynamic symbol table.  If
you want to remove the symbol from the static symbol table too, use
objcopy --strip-symbol.

Alan Modra
IBM OzLabs - Linux Technology Centre

More information about the Binutils mailing list