From b385c8412e8d4c6e257134e5bb7559ee06cd0c20 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 21 May 1998 05:42:51 +0000 Subject: [PATCH] decl2.c (maybe_make_one_only): New fn. * decl2.c (maybe_make_one_only): New fn. (import_export_vtable): Use it. (import_export_decl): Likewise. * pt.c (mark_decl_instantiated): Likewise. From-SVN: r19921 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl2.c | 34 ++++++++++++++++++++++++++++------ gcc/cp/pt.c | 4 ++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b89b270df3b..b0607c0b592 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +1998-05-21 Jason Merrill + + * decl2.c (maybe_make_one_only): New fn. + (import_export_vtable): Use it. + (import_export_decl): Likewise. + * pt.c (mark_decl_instantiated): Likewise. + 1998-05-21 Mark Mitchell * decl2.c (find_representative_member): Rename to ... diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index a7daa2aafa3..31903411922 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2451,6 +2451,30 @@ comdat_linkage (decl) DECL_COMDAT (decl) = 1; } +/* For win32 we also want to put explicit instantiations in + linkonce sections, so that they will be merged with implicit + instantiations; otherwise we get duplicate symbol errors. */ + +void +maybe_make_one_only (decl) + tree decl; +{ + /* This is not necessary on targets that support weak symbols, because + the implicit instantiations will defer to the explicit one. */ + if (! supports_one_only () || SUPPORTS_WEAK) + return; + + /* We can't set DECL_COMDAT on functions, or finish_file will think + we can get away with not emitting them if they aren't used. + We can't use make_decl_one_only for variables, because their + DECL_INITIAL may not have been set properly yet. */ + + if (TREE_CODE (decl) == FUNCTION_DECL) + make_decl_one_only (decl); + else + comdat_linkage (decl); +} + /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL, based on TYPE and other static flags. @@ -2481,9 +2505,8 @@ import_export_vtable (decl, type, final) /* For WIN32 we also want to put explicit instantiations in linkonce sections. */ - if (CLASSTYPE_EXPLICIT_INSTANTIATION (type) - && supports_one_only () && ! SUPPORTS_WEAK) - make_decl_one_only (decl); + if (CLASSTYPE_EXPLICIT_INSTANTIATION (type)) + maybe_make_one_only (decl); } else { @@ -2769,9 +2792,8 @@ import_export_decl (decl) /* For WIN32 we also want to put explicit instantiations in linkonce sections. */ - if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype) - && supports_one_only () && ! SUPPORTS_WEAK) - make_decl_one_only (decl); + if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype)) + maybe_make_one_only (decl); } else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype)) DECL_NOT_REALLY_EXTERN (decl) = 0; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7550271cbb0..2e50cf98109 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6444,8 +6444,8 @@ mark_decl_instantiated (result, extern_p) /* For WIN32 we also want to put explicit instantiations in linkonce sections. */ - if (supports_one_only () && ! SUPPORTS_WEAK && TREE_PUBLIC (result)) - make_decl_one_only (result); + if (TREE_PUBLIC (result)) + maybe_make_one_only (result); } else if (TREE_CODE (result) == FUNCTION_DECL) mark_inline_for_output (result); -- 2.30.2