[cfe-dev] Symbol visibility, typedefs and templates

Halfdan Ingvarsson halfdan at sidefx.com
Fri Jul 25 13:53:49 PDT 2014


Hello

I'm running into symbol visibility issues with clang trunk (213949).

I have a template class that gets specialized for symbol export 
(visibility attribute = default), but it is type-dependent on another 
template class, which is fully inlined and so doesn't have the 
visibility attribute. If I compile to a DSO with -fvisibility=hidden, 
the specialized member functions do not get exported, unless I mark the 
dependent class as exported as well.

Is this a bug or the expected behaviour?  This seems to work fine in gcc 
4.8, without specifically exporting the first template. If it's a bug, 
I'll open one up.

So far, I've been unable to find online any document on the 
composability rules of symbol export with regards to nested templates. 
Does such a document exist?

Sample code:

/// ---------------- test.C ------------
#define EXPORT __attribute__((visibility("default")))

// Remove the comment around EXPORT to make this behave
template <typename T> class /* EXPORT */ val_array { };

typedef val_array<float> val_array_f;

template <typename T>
struct handle
{
     handle();
};

template <typename T>
handle<T>::handle()
{
}

template EXPORT handle<val_array_f>::handle();
/// --------------------------------

 > clang++ -fPIC -shared -fvisibility=hidden -o test.so test.C
 > objdump -TC test.so | grep handle || echo NOTFOUND

  - ½



More information about the cfe-dev mailing list