This isn't a bug, but rather part of a deliberate linkage strategy.
For C++, types that are to be used across shared libraries have to be
visible. See:
http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
And in particular:
Note that '-fvisibility' does affect C++ vague linkage entities. This
means that, for instance, an exception class that will be thrown
between DSOs must be explicitly marked with default visibility so that
the 'type_info' nodes will be unified between the DSOs.
Thus, the rationale for libstdc++ having namespace std have visibility
"default." If you were to hack in support for allowing namespace std
to have hidden visibility, and run the testsuite with
-fvisibility=hidden (see attached patch) you would notice the breakdown in testresults, with mass failures. Thus, it is provided for
information purposes only.
In the libstdc++ source files, anonymous namespaces are used for
specific entities that have both local/hidden linkage. This use of
anonymous namespaces is considered superior to attribute hidden as it
uses ISO C++ and is thus more portable than vendor extensions (pragmas
or attributes).
However, in libstdc++ header files, attribute hidden has been
difficult to use. One might think that perhaps all the implementation
details could be moved to say std::__detail, and then marked with
attribute hidden. Then, many of these helper functions would be marked
as hidden in your example below.
There are some pitfalls with this approach:
- all these implementation base types that are used by default
derived classes would have to be default
- same with implementation
details that use static locals
- same with virtual functions, etc
etc.
- thus you end up with a pretty limited set of hidden things
In addition, this may exacerbate the dlopen + RTLD_LOCAL + weak symbol
issue for C++.