Name clashes in shared libraries
chaz at energoncube.net
Thu May 18 14:42:41 UTC 2006
On Thu, May 18, 2006 at 11:29:45AM +0200, Josu Onandia wrote:
> Hi all,
> I have a problem using shared libraries on an embedded powerpc target.
> I'm porting a legacy project that has a very large library (5MB of stripped
> code, 112MB with full symbol information). I was having some trouble
> because gcc makes
> all the functions of the library *public* by *default*. This is problematic
> when inside
> the library and inside the application there are functions with the same
> name. You
> don't get an error such as 'Duplicated symbol', so everything seems ok
> (this is not
> safe, in my opinion), and the application actually gets loaded and starts
> but when one of those functions is called inside the library, it is the
> that is inside the application the one that is called.
> I've read that there is a way of controlling what symbols are exported from
> inside the library. With the option -Wl,--version-script=library.map
> 'library.map' being a file like *this*:
> global: sample_function;
> local: *;
> This is supposed to make the function 'sample_function' *public* and the
> rest *private*.
I've not used the version-script option to ld before, but I've achieved
the results you're looking for by using gcc's visibility attribute in
my shared library code.
This page explains it (scroll down to the section on "visibility"):
Although this page is heavily C++ oriented, it's got some good
discussion and examples of using visibility attributes in code, that
are largely just as applicable to C:
More information about the uClibc