decl2.c (maybe_make_one_only): New fn.
authorJason Merrill <jason@yorick.cygnus.com>
Thu, 21 May 1998 05:42:51 +0000 (05:42 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 May 1998 05:42:51 +0000 (01:42 -0400)
* 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
gcc/cp/decl2.c
gcc/cp/pt.c

index b89b270df3b153868dc66ed983503589456ae8c7..b0607c0b592d500140d8b95e26ab2154d1df0b40 100644 (file)
@@ -1,3 +1,10 @@
+1998-05-21  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * 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  <mmitchell@usa.net>
 
        * decl2.c (find_representative_member): Rename to ...
index a7daa2aafa3db51d06152b02af21260364bd9214..31903411922885749948ed1f74d027886e7e604e 100644 (file)
@@ -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;
index 7550271cbb05fc96ee2afa702bb7370bbd1f581e..2e50cf981097bd0d48a1573eb1bc156310856e95 100644 (file)
@@ -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);