https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105645

Julian Waters <tanksherman27 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tanksherman27 at gmail dot com

--- Comment #3 from Julian Waters <tanksherman27 at gmail dot com> ---
I can confirm this on gcc 11 and higher:

#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)

Is this enough of a reproducer to get this confirmed?

Reply via email to