https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105645
Bug ID: 105645 Summary: Template specializations are not hidden with fvisibility=hidden Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kndevl at outlook dot com Target Milestone: --- Consider this snippet `encoding.cpp` ``` namespace Test { enum class Encoding { A, B }; template <Encoding enc> int encode(int); template <> int encode<Encoding::A>(int x) { return x + 1; } int f() { return 42; } } ``` I am compiling it through CMake with `/usr/bin/g++ -Dencoding_EXPORTS -g -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -std=gnu++17 -MD -MT CMakeFiles/encoding.dir/encoding.cpp.o -MF CMakeFiles/encoding.dir/encoding.cpp.o.d -o CMakeFiles/encoding.dir/encoding.cpp.o -c /home/nishanth/source/main/encoding.cpp` and linking it with `/usr/bin/g++ -fPIC -g -shared -Wl,-soname,libencoding.so -o libencoding.so CMakeFiles/encoding.dir/encoding.cpp.o CMakeFiles/encoding.dir/encoding-user.cpp.o` I expect `f()` and `Test::encode<Encoding::A>` to have the same symbol binding in `libencoding.so`. This is the output of `nm -C libencoding.so` ``` 0000000000001118 t Test::f() 0000000000001109 T int Test::encode<(Test::Encoding)0>(int) ``` `objdump -t encoding.cpp.o` does not have a `.hidden` tag on the `encode` specialization ``` 0000000000000000 g F .text 000000000000000f _ZN4Test6encodeILNS_8EncodingE0EEEii 000000000000000f g F .text 000000000000000b .hidden _ZN4Test1fEv ``` I can make `Test::encode` specialization local only by using `__attribute__((visibility("hidden")))` explicitly on the definition, in addition to calling the compiler with `-fvisibility=hidden`. On the other hand, clang 13.0.1 marks both `f()` and the `encode` specialization with `.hidden` in `objdump -t` output. Is there a way I can force g++ to hide template specializations?