public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15428] New: vtables shouldn't always be weak on Darwin
@ 2004-05-14 15:37 austern at apple dot com
  2004-05-14 15:42 ` [Bug c++/15428] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: austern at apple dot com @ 2004-05-14 15:37 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c++/15428] vtables shouldn't always be weak on Darwin
  2004-05-14 15:37 [Bug c++/15428] New: vtables shouldn't always be weak on Darwin austern at apple dot com
@ 2004-05-14 15:42 ` pinskia at gcc dot gnu dot org
  2004-05-21  3:09 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-14 15:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-13 21:58 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |austern at apple dot com
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|                            |1
           Keywords|                            |ABI, wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-05-13 21:58:07
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428


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

* [Bug c++/15428] vtables shouldn't always be weak on Darwin
  2004-05-14 15:37 [Bug c++/15428] New: vtables shouldn't always be weak on Darwin austern at apple dot com
  2004-05-14 15:42 ` [Bug c++/15428] " pinskia at gcc dot gnu dot org
@ 2004-05-21  3:09 ` pinskia at gcc dot gnu dot org
  2004-06-03 23:15 ` cvs-commit at gcc dot gnu dot org
  2004-06-03 23:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-21  3:09 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-20 01:18 -------
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01240.html>.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
   Target Milestone|---                         |3.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428


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

* [Bug c++/15428] vtables shouldn't always be weak on Darwin
  2004-05-14 15:37 [Bug c++/15428] New: vtables shouldn't always be weak on Darwin austern at apple dot com
  2004-05-14 15:42 ` [Bug c++/15428] " pinskia at gcc dot gnu dot org
  2004-05-21  3:09 ` pinskia at gcc dot gnu dot org
@ 2004-06-03 23:15 ` cvs-commit at gcc dot gnu dot org
  2004-06-03 23:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-06-03 23:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-06-03 23:15 -------
Subject: Bug 15428

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	austern@gcc.gnu.org	2004-06-03 23:15:02

Modified files:
	gcc            : ChangeLog defaults.h 
	gcc/config     : darwin.h 
	gcc/cp         : ChangeLog decl2.c 
	gcc/doc        : tm.texi 

Log message:
	PR c++/15428
	* default.h (TARGET_WEAK_NOT_IN_ARCHIVE_TOC): New name
	for TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY, with reversed sense.
	* config/darwin.h (TARGET_WEAK_NOT_IN_ARCHIVE_TOC): Likewise.
	* doc/tm.texi (TARGET_WEAK_NOT_IN_ARCHIVE_TOC): Rewrite
	documentation to reflect the new macro name and to clarify its
	meaning.
	* cp/decl2.c (maybe_emit_vtables): If TARGET_WEAK_NOT_IN_ARCHIVE_TOC
	is nonzero, and if we see a noninline definition of a key method,
	make the vtables nonweak.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3833&r2=2.3834
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/defaults.h.diff?cvsroot=gcc&r1=1.139&r2=1.140
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/darwin.h.diff?cvsroot=gcc&r1=1.80&r2=1.81
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4079&r2=1.4080
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.712&r2=1.713
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/tm.texi.diff?cvsroot=gcc&r1=1.326&r2=1.327



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428


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

* [Bug c++/15428] vtables shouldn't always be weak on Darwin
  2004-05-14 15:37 [Bug c++/15428] New: vtables shouldn't always be weak on Darwin austern at apple dot com
                   ` (2 preceding siblings ...)
  2004-06-03 23:15 ` cvs-commit at gcc dot gnu dot org
@ 2004-06-03 23:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-03 23:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-03 23:37 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428


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

end of thread, other threads:[~2004-06-03 23:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-14 15:37 [Bug c++/15428] New: vtables shouldn't always be weak on Darwin austern at apple dot com
2004-05-14 15:42 ` [Bug c++/15428] " pinskia at gcc dot gnu dot org
2004-05-21  3:09 ` pinskia at gcc dot gnu dot org
2004-06-03 23:15 ` cvs-commit at gcc dot gnu dot org
2004-06-03 23:37 ` pinskia at gcc dot gnu dot org

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