public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Explicit template instantiation and -fvisibility. Gcc bug?
@ 2008-11-17 13:39 Jeroen Wijnhout
  2008-11-18 15:29 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Jeroen Wijnhout @ 2008-11-17 13:39 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1590 bytes --]

Hi,

I'm currently experimenting with the -fvisibility=hidden visibility
flag. During that I have stumbled upon some very peculiar behavior of
GCC, which I managed to boil down to the following small example:

template < typename _T > class TemplatedClass
{
public:
 TemplatedClass ();
};

template < typename _T > class DependentTemplatedClass
{
public:
 DependentTemplatedClass ();
 _T m_Member;
};

These classes are explicitly instantiated in a library. In one
compilation unit I do:
template class LIBRARY_EXPORT TemplatedClass < int >;

And in another:
template class LIBRARY_EXPORT DependentTemplatedClass < TemplatedClass
< int > >;

The LIBRARY_EXPORT macro sets the visibility of the instantiation to
default (i.e. public).

When I compile the library like this (see the BuildFail.sh script in
the attachment). The TemplatedClass<int>::TemplatedClass symbol
appears twice in the library, the first being hidden the second being
a weak symbol. When linking to this library the linker cannot find
this symbol.

However when I export the class definition (as well as the
instantiation), the linking goes fine (see BuildWorkaround.sh). In
this case the symbol is defined twice in the library, both times as a
weak symbol.

The cause seems to be the instantiation of
DependentTemplatedClass<TemplatedClass<int > >, which induces an
instantiation of TemplatedClass<int> as well. However I would expect
this instantiation to have public visibility as well, because the
DependentTemplatedClass instantiation is public. Is this a GCC bug, or
am I doing something wrong here?

best,
Jeroen

[-- Attachment #2: GccVisibility.tar.bz2 --]
[-- Type: application/x-bzip2, Size: 1587 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Explicit template instantiation and -fvisibility. Gcc bug?
  2008-11-17 13:39 Explicit template instantiation and -fvisibility. Gcc bug? Jeroen Wijnhout
@ 2008-11-18 15:29 ` Ian Lance Taylor
  2008-11-18 15:37   ` Jeroen Wijnhout
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2008-11-18 15:29 UTC (permalink / raw)
  To: jeroen; +Cc: gcc-help

"Jeroen Wijnhout" <jeroen.wijnhout@gmail.com> writes:

> The cause seems to be the instantiation of
> DependentTemplatedClass<TemplatedClass<int > >, which induces an
> instantiation of TemplatedClass<int> as well. However I would expect
> this instantiation to have public visibility as well, because the
> DependentTemplatedClass instantiation is public. Is this a GCC bug, or
> am I doing something wrong here?

The semantics of how visibility should work with C++ classes and
templates are obscure and probably still not fully pinned down.  There
has been work in each recent gcc release to address this in various
ways.  You neglected to mention which version of gcc you are using.  I
would recommend trying your program with mainline (the future gcc
4.4).  If it does not behave as you expect, file a bug report (see
http://gcc.gnu.org/bugs.html ).  Thanks.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Explicit template instantiation and -fvisibility. Gcc bug?
  2008-11-18 15:29 ` Ian Lance Taylor
@ 2008-11-18 15:37   ` Jeroen Wijnhout
  2008-11-21 12:16     ` J.S.Wijnhout
  0 siblings, 1 reply; 4+ messages in thread
From: Jeroen Wijnhout @ 2008-11-18 15:37 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

On Tue, Nov 18, 2008 at 4:23 PM, Ian Lance Taylor <iant@google.com> wrote:
> "Jeroen Wijnhout" <jeroen.wijnhout@gmail.com> writes:
>
>> The cause seems to be the instantiation of
>> DependentTemplatedClass<TemplatedClass<int > >, which induces an
>> instantiation of TemplatedClass<int> as well. However I would expect
>> this instantiation to have public visibility as well, because the
>> DependentTemplatedClass instantiation is public. Is this a GCC bug, or
>> am I doing something wrong here?
>
> The semantics of how visibility should work with C++ classes and
> templates are obscure and probably still not fully pinned down.  There
> has been work in each recent gcc release to address this in various
> ways.  You neglected to mention which version of gcc you are using.  I
> would recommend trying your program with mainline (the future gcc
> 4.4).  If it does not behave as you expect, file a bug report (see
> http://gcc.gnu.org/bugs.html ).  Thanks.

I am using GCC4.3.2 (most recent released version afaik), however I
will try the mainline version.

thanks,
Jeroen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Explicit template instantiation and -fvisibility. Gcc bug?
  2008-11-18 15:37   ` Jeroen Wijnhout
@ 2008-11-21 12:16     ` J.S.Wijnhout
  0 siblings, 0 replies; 4+ messages in thread
From: J.S.Wijnhout @ 2008-11-21 12:16 UTC (permalink / raw)
  To: jeroen, iant; +Cc: gcc-help

>> The semantics of how visibility should work with C++ classes and
>> templates are obscure and probably still not fully pinned down.
There
>> has been work in each recent gcc release to address this in various
>> ways.  You neglected to mention which version of gcc you are using.
I
>> would recommend trying your program with mainline (the future gcc
>> 4.4).  If it does not behave as you expect, file a bug report (see
>> http://gcc.gnu.org/bugs.html ).  Thanks.
>
>I am using GCC4.3.2 (most recent released version afaik), however I
>will try the mainline version.

I've tested with the most recent snapshot (I can't use subversion
through our firewall) and the problem persists. Therefore I have filed a
bugreport:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38175
Hopefully it will be picked up by someone soon.

Best,
Jeroen

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-21 10:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-17 13:39 Explicit template instantiation and -fvisibility. Gcc bug? Jeroen Wijnhout
2008-11-18 15:29 ` Ian Lance Taylor
2008-11-18 15:37   ` Jeroen Wijnhout
2008-11-21 12:16     ` J.S.Wijnhout

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).