From 0524c91d1eee6dc2f1629160ed309a5441fb3bdd Mon Sep 17 00:00:00 2001 From: Matt Austern Date: Thu, 3 Jun 2004 23:15:01 +0000 Subject: [PATCH] re PR c++/15428 (vtables shouldn't always be weak on Darwin) 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. From-SVN: r82610 --- gcc/ChangeLog | 10 ++++++++++ gcc/config/darwin.h | 7 +++---- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl2.c | 30 +++++++++++++++++++++++++++--- gcc/defaults.h | 12 +++++++----- gcc/doc/tm.texi | 22 ++++++++++++++++------ 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dea0b8f79d2..614337b6c94 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2004-06-03 Matt Austern + + 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. + 2004-06-04 Steven Bosscher * rtl.def (VAR_LOCATION): Make RTX_EXTRA. diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 67bb29434bb..37122e6253c 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -358,11 +358,10 @@ do { text_section (); \ #undef USE_COMMON_FOR_ONE_ONLY #define USE_COMMON_FOR_ONE_ONLY 0 -/* The Darwin linker doesn't like explicit template instantiations to be - coalesced, because it doesn't want coalesced symbols to appear in +/* The Darwin linker doesn't want coalesced symbols to appear in a static archive's table of contents. */ -#undef TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY -#define TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY 0 +#undef TARGET_WEAK_NOT_IN_ARCHIVE_TOC +#define TARGET_WEAK_NOT_IN_ARCHIVE_TOC 1 /* We make exception information linkonce. */ #undef TARGET_USES_WEAK_UNWIND_INFO diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4eb93dcbcc6..652dc09a09e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-06-03 Matt Austern + + PR c++/15428 + * 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. + 2004-06-02 Matt Austern * cp-tree.h (instantiate_decl): new boolean parameter, diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index c5c4a55a1c4..038fea00879 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1441,7 +1441,7 @@ maybe_make_one_only (tree decl) to for variables so that cp_finish_decl will update their linkage, because their DECL_INITIAL may not have been set properly yet. */ - if (TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY + if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC || (! DECL_EXPLICIT_INSTANTIATION (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))) { @@ -1582,6 +1582,7 @@ maybe_emit_vtables (tree ctype) tree vtbl; tree primary_vtbl; bool needed = false; + bool weaken_vtables; /* If the vtables for this class have already been emitted there is nothing more to do. */ @@ -1612,6 +1613,29 @@ maybe_emit_vtables (tree ctype) else if (TREE_PUBLIC (vtbl) && !DECL_COMDAT (vtbl)) needed = true; + /* Determine whether to make vtables weak. The ABI requires that we + do so. There are two cases in which we have to violate the ABI + specification: targets where we don't have weak symbols + (obviously), and targets where weak symbols don't appear in + static archives' tables of contents. On such targets, avoiding + undefined symbol link errors requires that we only make a symbol + weak if we know that it will be emitted everywhere it's needed. + So on such targets we don't make vtables weak in the common case + where we're emitting a vtable of a nontemplate class in the + translation unit containing the definition of a noninline key + method. */ + if (flag_weak && !TARGET_WEAK_NOT_IN_ARCHIVE_TOC) + weaken_vtables = true; + else if (flag_weak) + { + if (CLASSTYPE_USE_TEMPLATE (ctype)) + weaken_vtables = CLASSTYPE_IMPLICIT_INSTANTIATION (ctype); + else + weaken_vtables = !CLASSTYPE_KEY_METHOD (ctype) + || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (ctype)); + } + else + weaken_vtables = false; /* The ABI requires that we emit all of the vtables if we emit any of them. */ @@ -1658,8 +1682,8 @@ maybe_emit_vtables (tree ctype) DECL_IGNORED_P (vtbl) = 1; } - /* Always make vtables weak. */ - if (flag_weak) + /* Always make vtables weak. Or at least almost always; see above. */ + if (weaken_vtables) comdat_linkage (vtbl); rest_of_decl_compilation (vtbl, NULL, 1, 1); diff --git a/gcc/defaults.h b/gcc/defaults.h index cf8ad088179..e479affa4ef 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -238,11 +238,13 @@ do { fputs (integer_asm_op (POINTER_SIZE / BITS_PER_UNIT, TRUE), FILE); \ #endif #endif -/* Determines whether explicit template instantiations should - be given link-once semantics. The C++ ABI requires this - macro to be nonzero; see the documentation. */ -#ifndef TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY -# define TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY 1 +/* This determines whether weak symbols must be left out of a static + archive's table of contents. Defining this macro to be nonzero has + the consequence that certain symbols will not be made weak that + otherwise would be. The C++ ABI requires this macro to be zero; + see the documentation. */ +#ifndef TARGET_WEAK_NOT_IN_ARCHIVE_TOC +#define TARGET_WEAK_NOT_IN_ARCHIVE_TOC 0 #endif /* This determines whether or not we need linkonce unwind information */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index aee7ba87b7d..082de59446c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -6753,13 +6753,23 @@ commands that will make the symbol(s) associated with @var{decl} have hidden, protected or internal visibility as specified by @var{visibility}. @end deftypefn -@defmac TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY +@defmac TARGET_WEAK_NOT_IN_ARCHIVE_TOC A C expression that evaluates to true if the target's linker expects -explicit template specializations, as well as implicit, to be given -linkonce semantics. The default is @code{1}. The C++ ABI requires -this macro to be nonzero. Define this macro for targets where full -C++ ABI compliance is impossible and where explicit and implicit -template specialization must be treated differently. +that weak symbols do not appear in a static archive's table of contents. +The default is @code{0}. + +Leaving weak symbols out of an archive's table of contents means that, +if a symbol will only have a definition in one translation unit and +will have undefined references from other translation units, that +symbol should not be weak. Defining this macro to be nonzero will +thus have the effect that certain symbols that would normally be weak +(explicit template instantiations, and vtables for polymorphic classes +with noninline key methods) will instead be nonweak. + +The C++ ABI requires this macro to be zero. Define this macro for +targets where full C++ ABI compliance is impossible and where linker +restrictions require weak symbols to be left out of a static archive's +table of contents. @end defmac @defmac TARGET_SUPPORTS_HIDDEN -- 2.30.2