This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: Gcj: add -static-libgcj option for linking.
- From: David Daney <ddaney at avtrex dot com>
- To: tromey at redhat dot com
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 08 Mar 2006 12:24:06 -0800
- Subject: Re: Patch: Gcj: add -static-libgcj option for linking.
- References: <440CBC96.4090706@avtrex.com> <m3d5gw6ccd.fsf@localhost.localdomain>
Tom Tromey wrote:
"David" == David Daney <ddaney@avtrex.com> writes:
David> OK to commit?
Yes, with a couple minor changes.
David> gcc:
David> 2006-03-06 David Daney <ddaney@avtrex.com>
David> * java/gcj.texi: Document -static-libgcj option.
gcc/java has its own ChangeLog. This entry should go there instead.
David> +Important Note: Static linking of libgcj may cause essential (to your
This should use @strong like:
@strong{Caution:} Static linking ...
(The manual recommends not using "Note" in an @strong..)
David> +program) parts of libgcj to be omitted. Caution must be used when
David> +using this option.
It would be nice to say more than this -- this is pretty vague and it
isn't clear what steps ought to be taken. Pointing folks at the wiki
page on gcj static linking would help.
This is what I just committed:
gcc/java/
2006-03-08 David Daney <ddaney@avtrex.com>
* gcj.texi: Document -static-libgcj option.
libjava/
2006-03-08 David Daney <ddaney@avtrex.com>
* configure.ac (LD): Add AC_CHECK_TOOL for ld.
(LD_START_STATIC_SPEC): New AC_SUBST, set with ld check.
(LD_FINISH_STATIC_SPEC): Ditto
* configure: Regenerated.
* libgcj.spec.in: Wrap -lgcj in LD_START_STATIC_SPEC and
LD_FINISH_STATIC_SPEC.
Index: gcc/java/gcj.texi
===================================================================
--- gcc/java/gcj.texi (revision 111845)
+++ gcc/java/gcj.texi (working copy)
@@ -420,6 +420,20 @@
of the @code{gij} command.
This option is an alternative to using @code{--main}; you cannot use both.
+
+@item -static-libgcj
+This option causes linking to be done against a static version of the
+libgcj runtime library. This option is only available if
+corresponding linker support exists.
+
+@strong{Caution:} Static linking of libgcj may cause essential parts
+of libgcj to be omitted. Some parts of libgcj use reflection to load
+classes at runtime. Since the linker does not see these references at
+link time, it can omit the referred to classes. The result is usually
+(but not always) a @code{ClassNotFoundException} being thrown at
+runtime. Caution must be used when using this option. For more
+details see:
+@w{@uref{http://gcc.gnu.org/wiki/Statically%20linking%20libgcj}}
@end table
@node Code Generation
Index: libjava/configure.ac
===================================================================
--- libjava/configure.ac (revision 111728)
+++ libjava/configure.ac (working copy)
@@ -113,6 +113,7 @@
AM_INIT_AUTOMAKE([1.9.0])
AC_CHECK_TOOL(AS, as)
+AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib, :)
@@ -1418,6 +1419,17 @@
# See if we support thread-local storage.
GCC_CHECK_TLS
+# Check if linker supports static linking on a per library basis
+LD_START_STATIC_SPEC=
+LD_FINISH_STATIC_SPEC=
+if $LD --help 2>&1 | grep -q -e -call_shared ; then
+ if $LD --help 2>&1 | grep -q -e -non_shared ; then
+ LD_START_STATIC_SPEC='%{static-libgcj:-non_shared}'
+ LD_FINISH_STATIC_SPEC='%{static-libgcj:-call_shared}'
+ fi
+fi
+AC_SUBST(LD_START_STATIC_SPEC)
+AC_SUBST(LD_FINISH_STATIC_SPEC)
here=`${PWDCMD-pwd}`
AC_SUBST(here)
Index: libjava/libgcj.spec.in
===================================================================
--- libjava/libgcj.spec.in (revision 111728)
+++ libjava/libgcj.spec.in (working copy)
@@ -4,6 +4,6 @@
# to link with libgcj.
#
%rename lib liborig
-*lib: -lgcj -lm @LIBICONV@ @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(libgcc) %(liborig)
+*lib: @LD_START_STATIC_SPEC@ -lgcj @LD_FINISH_STATIC_SPEC@ -lm @LIBICONV@ @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(libgcc) %(liborig)
*jc1: @HASH_SYNC_SPEC@ @DIVIDESPEC@ @CHECKREFSPEC@ @JC1GCSPEC@ @EXCEPTIONSPEC@ @BACKTRACESPEC@ @IEEESPEC@ -fkeep-inline-functions