https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115230
Bug ID: 115230 Summary: -fvisibility=hidden does not hide Template Specializations from being exported Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tanksherman27 at gmail dot com Target Milestone: --- Consider the following code: #include <cstdlib> template<typename T> void method(T* src, T* dst, size_t length); template<> void method<short>(short* src, short* dst, size_t length) { } template<> void method<int>(int* src, int* dst, size_t length) { } Compiled using command line: g++ -O3 -fvisibility=hidden -std=c++14 -pedantic -Wpedantic -Wall -Werror templates.cpp Linked using: g++ -shared -o libtemplates.so templates.o When nm is run over it using nm -gDC libtemplates.so, the following symbols are seen: w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable 0000000000001110 T void method<int>(int*, int*, unsigned long) 0000000000001100 T void method<short>(short*, short*, unsigned long) w __cxa_finalize w __gmon_start__ T void method<int>(int*, int*, unsigned long) and T void method<short>(short*, short*, unsigned long) should not be in the symbol table, but they are even with -fvisibility=hidden. Strangely, marking both methods with [[gnu::visibility("hidden")]] works and results in both not being exported. This was recently observed in the JDK, inside the Java HotSpot VM (see https://github.com/openjdk/jdk/pull/17955/files#r1498933843)