This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Removing unwanted symbols from a .so


[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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]