This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Use vague linkage for Java methods
- From: Julian Brown <julian at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: julian at codesourcery dot com
- Date: Tue, 08 Mar 2005 02:34:52 +0000
- Subject: [PATCH] Use vague linkage for Java methods
Hi,
This patch causes Java methods to be output with once-only ("vague")
linkage (so long as they are non-abstract, non-private and non-static,
which seem like the right conditions, but I'd be prepared to believe
aren't perfect). This helps when using CNI to interface with C++,
especially on platforms with COMDAT groups.
It allows my previous patch to work again:
http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01624.html
The problem was that gcjh-produced header files sometimes output full
methods in simple cases, which are then put into COMDAT groups by the
C++ front-end. Java methods are currently output with weak linkage due
to the definition of MAKE_DECL_ONE_ONLY, so this works, apparently
somewhat accidentally.
If MAKE_DECL_ONE_ONLY is altered to not use weak linkage, multiple
definitions occur when mixing Java with CNI code.
This patch has been tested independently (with c,c++,java) on
i686-pc-linux-gnu.
ChangeLog:
* gcc/java/decl.c (finish_method): Give methods once-only linkage.
Index: gcc/java/decl.c
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.209
diff -c -p -r1.209 decl.c
*** gcc/java/decl.c 14 Feb 2005 14:58:22 -0000 1.209
--- gcc/java/decl.c 6 Mar 2005 23:55:51 -0000
*************** finish_method (tree fndecl)
*** 2036,2041 ****
--- 2036,2050 ----
build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
}
+ /* Ensure non-abstract non-static non-private members are defined only once
+ when linking. This is an issue when using CNI to interface with C++ object
+ files. */
+ if (! METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
+ && ! METHOD_ABSTRACT (fndecl))
+ {
+ make_decl_one_only (fndecl);
+ }
+
/* Prepend class initialization for static methods reachable from
other classes. */
if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)