This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15428] New: vtables shouldn't always be weak on Darwin
- From: "austern at apple dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 May 2004 21:52:53 -0000
- Subject: [Bug c++/15428] New: vtables shouldn't always be weak on Darwin
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Compiling this on Darwin, and looking at the .o file with 'nm -m', gives the following:
...
00000120 (__DATA,__datacoal_nt) weak external __ZTV1A
...
That is, the vtable is marked as weak. That's all as it should be: the ABI specification says that vtables
should always be weak. Unfortunately, on Darwin that's wrong.
It's wrong because of a limitation in Darwin's linker. Weak ("coalesced") symbols may not appear in the
table of contents of a static archive. So consider the following scenario:
1. The class is defined in a.h. The key method, A::~A(), is defined in a.cc.
2. a.cc gets compiled, and then gets put into a static archive libA.a.
3. Some other file, foo.cc, includes a.h and uses class A in a way that requires the definition of a vtable.
4. We link foo.o against libA.a.
foo.o will have an unresolved reference to _ZTV1A. There will be a perfectly good definition of it in
libA.a(a.o), but the linker won't find it because it won't be there in the table of contents. So even
though the user is doing everything right, the link will fail.
In the long run we should probably remove the Darwin linker's restriction. In the short run, however,
the linker is what it is.
What this means is that on Darwin we have to special-case vtables, just like we special-case members
of explicitly instantiated class templates with TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY. (It's the
same issue.) On Darwin we have to mark vtables weak only if we believe that they will be emitted
everywhere they're needed. That is, we have to mark them weak if the class has no key method or if
the key method is inline, but leave them nonweak otherwise.
This is a bug in my code to enable linkonce support for Darwin, so this bug should be assigned to me
unless someone else desparately wants it.
--
Summary: vtables shouldn't always be weak on Darwin
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: austern at apple dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-apple-darwin7.3.0
GCC host triplet: powerpc-apple-darwin7.3.0
GCC target triplet: powerpc-apple-darwin7.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428