This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Yet another tweak for systems without weak symbols
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Apr 2003 00:21:58 -0700
- Subject: C++ PATCH: Yet another tweak for systems without weak symbols
- Reply-to: mark at codesourcery dot com
This patch makes yet another change aimed at getting systems without
weak symbols to behave in a sensible fashion. It turns out that this
stuff was all messed up, but often worked by luck.
This patch is going to cause some new warnings on targets without weak
symbols. The warnings are legitimate; they are warning the user that
initialized static variables in a template/inline functions are
handled incorrectly on these targets. There is no non-trivial fix.
Tested on i686-pc-linux-gnu, and with a cross compiler; installed on
the mainline and on the branch.
--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery dot com
2003-04-29 Mark Mitchell <mark at codesourcery dot com>
* decl.c (maybe_commonize_var): Further tweak support for systems
without weak symbols.
2003-04-29 Mark Mitchell <mark at codesourcery dot com>
* g++.old-deja/g++.pt/deduct5.C: Remove unnecessary initializer.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.965.2.40
diff -c -5 -p -r1.965.2.40 decl.c
*** cp/decl.c 28 Apr 2003 06:12:52 -0000 1.965.2.40
--- cp/decl.c 29 Apr 2003 06:54:19 -0000
*************** maybe_commonize_var (decl)
*** 7801,7838 ****
&& (DECL_COMDAT (DECL_CONTEXT (decl))
|| ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
|| DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
&& TREE_PUBLIC (DECL_CONTEXT (decl)))))
{
! /* If flag_weak, we don't need to mess with this, as we can just
! make the function weak, and let it refer to its unique local
! copy. This works because we don't allow the function to be
! inlined. */
! if (! flag_weak)
{
! if (DECL_INTERFACE_KNOWN (current_function_decl))
! {
! TREE_PUBLIC (decl) = 1;
! DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl);
! }
! else if (DECL_INITIAL (decl) == NULL_TREE
! || DECL_INITIAL (decl) == error_mark_node)
{
TREE_PUBLIC (decl) = 1;
DECL_COMMON (decl) = 1;
}
! /* else we lose. We can only do this if we can use common,
! which we can't if it has been initialized. */
!
! if (!TREE_PUBLIC (decl))
{
cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
cp_warning_at (" you can work around this by removing the initializer", decl);
}
}
- else
- comdat_linkage (decl);
}
else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
/* Set it up again; we might have set DECL_INITIAL since the last
time. */
comdat_linkage (decl);
--- 7801,7838 ----
&& (DECL_COMDAT (DECL_CONTEXT (decl))
|| ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
|| DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
&& TREE_PUBLIC (DECL_CONTEXT (decl)))))
{
! if (flag_weak)
{
! /* With weak symbols, we simply make the variable COMDAT;
! that will cause copies in multiple translations units to
! be merged. */
! comdat_linkage (decl);
! }
! else
! {
! if (DECL_INITIAL (decl) == NULL_TREE
! || DECL_INITIAL (decl) == error_mark_node)
{
+ /* Without weak symbols, we can use COMMON to merge
+ uninitialized variables. */
TREE_PUBLIC (decl) = 1;
DECL_COMMON (decl) = 1;
}
! else
{
+ /* While for initialized variables, we must use internal
+ linkage -- which means that multiple copies will not
+ be merged. */
+ TREE_PUBLIC (decl) = 0;
+ DECL_COMMON (decl) = 0;
cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
cp_warning_at (" you can work around this by removing the initializer", decl);
}
}
}
else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
/* Set it up again; we might have set DECL_INITIAL since the last
time. */
comdat_linkage (decl);
Index: testsuite/g++.old-deja/g++.pt/deduct5.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.pt/deduct5.C,v
retrieving revision 1.1
diff -c -5 -p -r1.1 deduct5.C
*** testsuite/g++.old-deja/g++.pt/deduct5.C 14 Feb 2001 09:45:29 -0000 1.1
--- testsuite/g++.old-deja/g++.pt/deduct5.C 29 Apr 2003 06:54:21 -0000
***************
*** 5,15 ****
#include <stdio.h>
template <typename T> int Foo (T const *ptr)
{
! static int count = 0;
printf ("%s\n", __PRETTY_FUNCTION__);
count++;
return count;
--- 5,15 ----
#include <stdio.h>
template <typename T> int Foo (T const *ptr)
{
! static int count;
printf ("%s\n", __PRETTY_FUNCTION__);
count++;
return count;