Problems with -fvisibility in GCC4.3.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Currently I am trying, using GCC4.3.0, to make my shared libraries
load faster using -fvisibility-ms-compat. The project, about 200.000
LOC, was already using the
dllexport/dllimport mechanism on Windows. Most of the code relies
heavily on templates and I have discovered very peculiar behavior of
the GCC compiler. It is related to the use of explicit instantiation
of templates. For a templated class we usually do the following:

header file:
template < class _T > class A
{
...
};

cpp file:
template class EXPORT A < int >;
template class EXPORT A < double >;
etc.

Here EXPORT is the export macro (dllexport/dllimport for the MS
compiler (VC9) and __attribute__ ((visibility ("default"))) for GCC
4.3.0).

This works fine for most classes, however for some it turned out to be
necessary to export the class definition as well. I.e.:
template < class _T > EXPORT A
{
...
};
This is odd, because you normally only have to export the
instantiation of the template. Unfortunately adding the extra export
macro breaks the build on the MS compiler.

Upon investigation of this issue I discovered that when a certain
class, derived from A, was added to the library symbols of class A
vanished from the library! I confirmed this using the tool 'nm'.

Since the project is fairly large and complex I did not manage to
construct a small example that shows the problem. However I have been
able pinpoint the badly interaction classes. I cannot send you the
code (it is not in the public domain).

The first class is an Image class:
template <class ImageElement, class typeTraits =
TypeTraits<ImageElement> > class Image : virtual public AbstractImage
{
...
};

Then there is a collection of images:
template <typename _Image > class ImageSet : public
AbstractDataObjectSet<_Image *>
{
...
};

Finally there is an image that secretly is a set of images:
template <typename _Image > class ImageSetImage : virtual public
_Image, virtual public ImageSet<_Image>
{
...
};

All these classes have explicit instantiations. When I omit the
ImageSetImage class everything compiles fine. However as soon as I
include the ImageSetImage class into the library, symbols from Image
disappear and I get linker errors. I can fix these by added the EXPORT
macro the the Image class definition:
template <class ImageElement, class typeTraits =
TypeTraits<ImageElement> > class EXPORT Image : virtual public
AbstractImage
However, as said, this should not be done using the MS compiler.

Now, I am really trying to figure out what is happening here. I
realise it is difficult to tell without the code, but perhaps someone
has can provide some clues for me to follow up on.

thanks in advance,
Jeroen Wijnhout

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux