Removing unwanted symbols from a .so
Thomas Lopatic
thomas@lopatic.de
Sat Nov 6 03:36:00 GMT 2004
[unwanted symbols end up in the dynamic symbol table]
> Is there either (a) a way to prevent these symbols from being added to
> the .so in the first place (maybe through partial linking?) or (b) a way
> to strip these extra symbols whilst keeping the library functional and
> keeping the API symbols available?
You might want to try writing a linker version script, for example as
follows:
VERS_1.0 {
global:
func1;
func2;
local: *;
};
This would make functions func1() and func2() visible to the outside
("global") and hide all other symbols ("local", "*" wildcard). Save this
to a file, say script.txt, and add the following command line option to
GCC when linking:
-Wl,--version-script=script.txt
Alternatively you can use visibility attributes in you source code, e.g.
as follows (assuming you use C or C++):
int i __attribute__ ((visibility ("hidden")));
This will define a variable "i" and set it to "hidden" visibility, which
again means that it will not show up in your dynamic symbol table.
So basically "hidden" visibility does to shared objects what "static"
does to object files - limit the scope of a symbol.
-Thomas
More information about the Binutils
mailing list