With the following foo.cpp sample: #include <algorithm> __attribute__((visibility("default"))) void foo() { int array[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30 }; int elements = sizeof(array) / sizeof(array[0]); std::sort(array, array + elements); }
Building with the following command line: g++-4.3 -shared -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -o foo.so foo.cpp Leads to internals being exposed, which is unexpected: objdump -T -C test2.so | grep std 000000000000136d w DF .text 000000000000003a Base void std::__unguarded_insertion_sort<int*>(int*, int*) 0000000000001b18 w DF .text 0000000000000057 Base void std::sort<int*>(int*, int*) 000000000000147f w DF .text 000000000000000e Base std::__niter_base<int*, false>::__b(int*) 000000000000190b w DF .text 0000000000000021 Base std::__lg(long) 0000000000001324 w DF .text 0000000000000049 Base void std::__unguarded_linear_insert<int*, int>(int*, int) 000000000000141f w DF .text 0000000000000060 Base int* std::__unguarded_partition<int*, int>(int*, int*, int) 0000000000001674 w DF .text 0000000000000088 Base void std::make_heap<int*>(int*, int*) 0000000000001400 w DF .text 000000000000001f Base void std::iter_swap<int*, int*>(int*, int*) 00000000000013b5 w DF .text 000000000000002c Base void std::swap<int>(int&, int&) 00000000000016fc w DF .text 0000000000000054 Base void std::__pop_heap<int*>(int*, int*, int*) 00000000000019bc w DF .text 000000000000004f Base int* std::__copy_move_backward_a2<false, int*, int*>(int*, int*, int*) 0000000000001a4b w DF .text 0000000000000079 Base void std::__insertion_sort<int*>(int*, int*) 0000000000001a0b w DF .text 0000000000000040 Base int* std::copy_backward<int*, int*>(int*, int*, int*) 0000000000001750 w DF .text 000000000000005d Base void std::__heap_select<int*>(int*, int*, int*) 0000000000001284 w DF .text 00000000000000a0 Base int const& std::__median<int>(int const&, int const&, int const&) 00000000000017ad w DF .text 000000000000002b Base void std::pop_heap<int*>(int*, int*) 000000000000152e w DF .text 0000000000000146 Base void std::__adjust_heap<int*, long, int>(int*, long, long, int) 00000000000013a7 w DF .text 000000000000000e Base std::__miter_base<int*, false>::__b(int*) 000000000000180f w DF .text 0000000000000034 Base void std::partial_sort<int*>(int*, int*, int*) 00000000000017d8 w DF .text 0000000000000037 Base void std::sort_heap<int*>(int*, int*) 0000000000001991 w DF .text 000000000000002b Base int* std::__copy_move_backward_a<false, int*, int*>(int*, int*, int*) 0000000000001ac4 w DF .text 0000000000000054 Base void std::__final_insertion_sort<int*>(int*, int*) 0000000000001843 w DF .text 00000000000000c8 Base void std::__introsort_loop<int*, long>(int*, int*, long) 000000000000192c w DF .text 0000000000000065 Base int* std::__copy_move_backward<false, true, std::random_access_iterator_tag>::__copy_move_b<int>(int const*, int const*, int*) 00000000000013e1 w DF .text 000000000000001f Base void std::__iter_swap<true>::iter_swap<int*, int*>(int*, int*) 000000000000148d w DF .text 00000000000000a1 Base void std::__push_heap<int*, long, int>(int*, long, long, int) FYI: g++-4.3 -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure linux gnu Thread model: posix gcc version 4.3.1 20080401 (prerelease) (Debian 4.3.0-3) (it also happens with g++-4.2 from debian (4.2.3)) -- Summary: stl templates exported as weak symbols though visibility hidden is used Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mh+gcc at glandium dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36022