This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
gcj, shared libraries, and -Bsymbolic
- From: Andrew Haley <aph at redhat dot com>
- To: java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 25 Jan 2005 14:43:55 +0000
- Subject: gcj, shared libraries, and -Bsymbolic
The C semantics of the dynamic linker don't play well with Java: when
a method in a shared library accesses some locally defined object it
wants the local copy, not some other object with the same name that
happens to be in a shared library earlier in the search path.
However, the semantics we require correspond quite nicely with the the
GNU linker option -Bsymbolic.
This patch probes the linker for -Bsymbolic support, and then adds the
spec %{shared:-Bsymbolic} when gcj is used to produce a shared object.
An earlier hack in configure.host that added -Bsymbolic to the libgcj
link options -- but only on Linux -- has been removed. Now,
-Bsymbolic is used on every linker that supports it.
At some point in the future we intend to make gcj classes export no
symbols from shared objects, and then there will be no need to use
-Bsymbolic when linking. However, symbols for classes and methods
must be exported at the present time in order to allow C++ code to
call Java code via CNI.
Andrew.
2005-01-25 Andrew Haley <aph@redhat.com>
* configure.host: Remove setting of libgcj_ld_symbolic.
* libgcj.spec.in (link): Redefine.
* acinclude.m4 (LIBGCJ_CHECK_LINKER_FEATURES): new defun.
* configure.ac: Call LIBGCJ_CHECK_LINKER_FEATURES.
Use the result of LIBGCJ_CHECK_LINKER_FEATURES to control
LIBGCJ_LD_SYMBOLIC.
* configure: Rebuilt.
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.ac,v
retrieving revision 1.16
diff -p -2 -c -r1.16 configure.ac
*** configure.ac 3 Dec 2004 11:15:22 -0000 1.16
--- configure.ac 25 Jan 2005 14:24:02 -0000
*************** AC_ARG_ENABLE(multilib,
*** 86,89 ****
--- 86,91 ----
GCC_NO_EXECUTABLES
+ LIBGCJ_CHECK_LINKER_FEATURES
+
# (1) We use an abnormal CXX (without library references), so we
# must cache it under a different name.
*************** LIBGCJ_CFLAGS="${libgcj_cflags}"
*** 135,139 ****
LIBGCJ_CXXFLAGS="${libgcj_cxxflags}"
LIBGCJ_JAVAFLAGS="${libgcj_javaflags}"
! LIBGCJ_LD_SYMBOLIC="${libgcj_ld_symbolic}"
AC_SUBST(LIBGCJ_CFLAGS)
AC_SUBST(LIBGCJ_CXXFLAGS)
--- 137,145 ----
LIBGCJ_CXXFLAGS="${libgcj_cxxflags}"
LIBGCJ_JAVAFLAGS="${libgcj_javaflags}"
! LIBGCJ_LD_SYMBOLIC==''
! if test "$ac_symbolicLDflag" = "yes"; then
! LIBGCJ_LD_SYMBOLIC=='-Wl,-Bsymbolic'
! fi
!
AC_SUBST(LIBGCJ_CFLAGS)
AC_SUBST(LIBGCJ_CXXFLAGS)
Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/gcc/libjava/acinclude.m4,v
retrieving revision 1.31
diff -p -2 -c -r1.31 acinclude.m4
*** acinclude.m4 23 Sep 2004 01:14:00 -0000 1.31
--- acinclude.m4 25 Jan 2005 14:24:02 -0000
*************** else
*** 36,37 ****
--- 36,72 ----
fi[]dnl
])# CHECK_FOR_BROKEN_MINGW_LD
+
+ dnl Check for linker features. Used here to determine whether the
+ dnl linker supports -Bsymbolic with shared libraries.
+ dnl
+ dnl Defines:
+ dnl SYMBOLIC_LDFLAG='-Bsymbolic' if possible
+
+ AC_DEFUN([LIBGCJ_CHECK_LINKER_FEATURES], [
+ AC_REQUIRE([AC_PROG_LD])
+
+ ac_test_LDLAGS="${LDFLAGS+set}"
+ ac_save_LDFLAGS="$LDFLAGS"
+ LDFLAGS='-shared -Wl,-Bsymbolic'
+
+ # Check for -Wl,-Bsymbolic
+ AC_MSG_CHECKING([for ld that supports -Bsymbolic])
+ AC_LINK_IFELSE(
+ [AC_LANG_SOURCE([[
+ int main(void)
+ {
+ return 0;
+ }
+ ]])],
+ [ac_symbolicLDflag=yes],[ac_symbolicLDflag=no])
+ if test "$ac_test_LDFLAGS" = set; then
+ LDFLAGS="$ac_save_LDFLAGS"
+ else
+ LDFLAGS=''
+ fi
+ if test "$ac_symbolicLDflag" = "yes"; then
+ SYMBOLIC_LDFLAG="-Bsymbolic"
+ fi
+ AC_MSG_RESULT($ac_symbolicLDflag)
+ AC_SUBST(SYMBOLIC_LDFLAG)
+ ])# LIBGCJ_CHECK_LINKER_FEATURES
Index: libgcj.spec.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/libgcj.spec.in,v
retrieving revision 1.25
diff -p -2 -c -r1.25 libgcj.spec.in
*** libgcj.spec.in 13 Feb 2003 02:51:26 -0000 1.25
--- libgcj.spec.in 25 Jan 2005 14:24:02 -0000
***************
*** 8,9 ****
--- 8,13 ----
*jc1: @HASH_SYNC_SPEC@ @DIVIDESPEC@ @CHECKREFSPEC@ @JC1GCSPEC@ @EXCEPTIONSPEC@ @BACKTRACESPEC@ @IEEESPEC@ -fkeep-inline-functions
+
+ %rename link link_orig
+ *link: %{shared:@SYMBOLIC_LDFLAG@} %(link_orig)
+
Index: configure.host
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.host,v
retrieving revision 1.64
diff -p -2 -c -r1.64 configure.host
*** configure.host 25 Nov 2004 03:46:56 -0000 1.64
--- configure.host 25 Jan 2005 14:24:02 -0000
*************** case "${host}" in
*** 174,178 ****
sh-linux* | sh[34]*-linux*)
can_unwind_signal=yes
- libgcj_ld_symbolic='-Wl,-Bsymbolic'
if test x$slow_pthread_self = xyes \
&& test x$cross_compiling != xyes; then
--- 174,177 ----