This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: Symbols in .so even when using fvisibility=hidden


Robert Wohlrab <robert.wohlrab@gmx.de> writes:

> Ian Lance Taylor wrote:
>> Robert Wohlrab <robert.wohlrab@gmx.de> writes:
>> > I have the problem that I have a shared object which is mostly c with a
>> > relative small part C++. It is compiled with -fvisibility=hidden and only
>> > some small parts are exported. I noticed today that non-exported C++
>> > symbols were also exported. This is quite mysterious because they are 5
>> > functions from templates (looks related to std::vector with allocator
>> > stuff to me). The shared object is generated by source files from
>> > mupen64plus-core (can be found on bitbucket) using `make -C
>> > projects/unix/ all`.
>> >
>> > Is there any way to disable that symbols? The vector is not used outside
>> > that shared object and the interface of the shared object should be as
>> > clean as possible. I tried already with -fvisibility-inlines-hidden but
>> > without success.
>> 
>> In general this should not happen.  Can you provide a small standalone
>> test case which shows the problem?
>
> I am not sure what the problem really is - so it is a little bit hard to make 
> a test case. I tried to create one by stripping of some files and functions. 
> It also includes a debian directory because I used dpkg-gensymbols to check 
> for exported symbols. debian/libtest0.symbols says that no function is 
> exported (I wrote it because it is what the source says - it is not 
> autogenerated), but dpkg-gensymbols will then report that 5 other functions 
> were exported by libtest.so.0.
>
> The Makefile says that visibility is hidden and the test.cpp doesn't say that 
> anything should be exported.

Thanks for the test case.  I see what is happening.  Your class and
its functions are hidden.  What is not hidden is the standard library
template functions which your code instantiates.

Template instantations are a tricky case for visibility.  It's
possible to pass template objects from one shared library to another,
so the instantiations all have to be compatible.  And they aren't
symbols that you are defining yourself, so it's not clear whether
-fvisibility=hidden should apply to them.  So I don't know what the
right behaviour is here.

To really get what you want--to hide all the symbols, even the
implicit template instantiations--you will need to pass a version
script to the linker.  You may also want to consider
-fno-implicit-templates and -fno-implicit-inline-templates, although
then you will have to ensure that some other object instantiates the
required templates.

Ian


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