This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: Gcj: add -static-libgcj option for linking.
- From: David Daney <ddaney at avtrex dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 06 Mar 2006 14:49:58 -0800
- Subject: Patch: Gcj: add -static-libgcj option for linking.
This patch adds an option '-static-libgcj' that causes libgcj to be
linked statically instead of dynamically. This is similar to the
-static-libgcc option.
The main reason one would do this is to save space. The minimal Hello
World program statically linked is about 8MB. libgcj.so.7.0.0 is around
23MB.
I should note that this option is not for everyone as many parts of
libgcj do not work with static linking. But if you are careful, and
play a few tricks, it can be quite useful.
Tested with make -k check in libjava on i686-pc-linux-gnu with no failures.
OK to commit?
gcc:
2006-03-06 David Daney <ddaney@avtrex.com>
* java/gcj.texi: Document -static-libgcj option.
libjava:
2006-03-06 David Daney <ddaney@avtrex.com>
* configure.ac (LD): Add AC_CHECK_TOOL for ld.
* configure: Regenerated.
(LD_START_STATIC_SPEC): New AC_SUBST, set with ld check.
(LD_FINISH_STATIC_SPEC): Ditto
* libgcj.spec.in: Wrap -lgcj in LD_START_STATIC_SPEC and
LD_FINISH_STATIC_SPEC.
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
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: gcc/java/gcj.texi
===================================================================
--- gcc/java/gcj.texi (revision 111728)
+++ gcc/java/gcj.texi (working copy)
@@ -420,6 +420,15 @@
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.
+
+Important Note: Static linking of libgcj may cause essential (to your
+program) parts of libgcj to be omitted. Caution must be used when
+using this option.
@end table
@node Code Generation