This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Build libgcj, libgcj-tools, and libffi as shared libraries on Windows


Aaron W. LaFramboise wrote:
> This patch builds libgcj, libgcj-tools, and libffi as DLLs on Windows.

  This patch revises and updates Aaron's old patch from last August.  It adds
some essential support for Cygwin that the previous patch didn't have, and
does things slightly differently in places.

  There's only one substantial addition: I added a mechanism in libffi's build
system to allow the override of $toolexeclibdir.  We use this on Cygwin to
install the newly built libffi into the GCC private directory alongside cc1 et
al., as we may have a different upstream version of libffi-devel installed in
/usr/lib and /usr/include.

  I'm just putting this through a bootstrap at the moment.  There's not going
to be much to test because none of this used to be built on Cygwin at all
before, so it can hardly regress.  If it bootstraps and builds nice working
DLLs, OK for HEAD?

ChangeLog:

	* configure.ac (Cygwin noconfigdirs):  Remove libgcj.
	* configure:  Regenerate.

boehm-gc/ChangeLog:

	* win32_threads.c (get_thread_stack_base):  Add missing function
	definition for Cygwin.

gcc/ChangeLog

	* config/i386/t-cygming (jc1):  Add -Wl,-stack to LDFLAGS.

libffi/ChangeLog

	* configure.ac (toolexeclibdir):  Allow host-specific override
	if defined in host__toolexeclibdir.
	* configure.host (Cygwin host__toolexeclibdir):  Define.
	* Makefile.am (gcc_version):  New makefile variable.
	(toollibffidir):  Likewise.
	(LTLDFLAGS):  Add "-no-undefined".
	* configure:  Regenerate.
	* Makefile.in:  Regenerate.

	* src/x86/win32.S (ffi_prep_args):  Rename from this ...
	(_ffi_prep_args):  ... to this.
	(_ffi_call_SYSV, _ffi_call_STDCALL, _ffi_closure_SYSV,
	_ffi_closure_raw_SYSV):  Add missing symbol function type attributes.

libjava/ChangeLog

	* configure.ac (Cygwin|MinGW extra_ldflags_libjava):  Add ws2_32 lib.
	* Makefile.am (LIBLINK):  Add "-no-undefined".
	(libgij_la_LDFLAGS, libjvm_la_LDFLAGS):  Likewise.
	(libgcj_tools_la_LIBADD):  Link against new libgcj.la.
	* Makefile.in:  Regenerate.

	* sysdep/i386/backtrace.h (MAIN_FUNC):  New define.
	(fallback_backtrace):  Use it.

libjava/libltdl/ChangeLog

	* ldtl.c (DLL_EXPORT):  Rename from this ...
	(LIBLTDL_DLL_EXPORT):  ... to this.
	* ldtl.c (DLL_EXPORT, LIBLTDL_DLL_EXPORT):  Change use.


    cheers,
      DaveK
ChangeLog:

	* configure.ac (Cygwin noconfigdirs):  Remove libgcj.
	* configure:  Regenerate.

boehm-gc/ChangeLog:

	* win32_threads.c (get_thread_stack_base):  Add missing function 
	definition for Cygwin.

gcc/ChangeLog

	* config/i386/t-cygming (jc1):  Add -Wl,-stack to LDFLAGS.

libffi/ChangeLog

	* configure.ac (toolexeclibdir):  Allow host-specific override
	if defined in host__toolexeclibdir.
	* configure.host (Cygwin host__toolexeclibdir):  Define.
	* Makefile.am (gcc_version):  New makefile variable.
	(toollibffidir):  Likewise.
	(LTLDFLAGS):  Add "-no-undefined".
	* configure:  Regenerate.
	* Makefile.in:  Regenerate.

	* src/x86/win32.S (ffi_prep_args):  Rename from this ...
	(_ffi_prep_args):  ... to this.
	(_ffi_call_SYSV, _ffi_call_STDCALL, _ffi_closure_SYSV,
	_ffi_closure_raw_SYSV):  Add missing symbol function type attributes.

libjava/ChangeLog

	* configure.ac (Cygwin|MinGW extra_ldflags_libjava):  Add ws2_32 lib.
	* Makefile.am (LIBLINK):  Add "-no-undefined".
	(libgij_la_LDFLAGS, libjvm_la_LDFLAGS):  Likewise.
	(libgcj_tools_la_LIBADD):  Link against new libgcj.la.
	* Makefile.in:  Regenerate.

	* sysdep/i386/backtrace.h (MAIN_FUNC):  New define.
	(fallback_backtrace):  Use it.

libjava/libltdl/ChangeLog

	* ldtl.c (DLL_EXPORT):  Rename from this ...
	(LIBLTDL_DLL_EXPORT):  ... to this.
	* ldtl.c (DLL_EXPORT, LIBLTDL_DLL_EXPORT):  Change use.

==============================================================================

Index: gcc/config/i386/t-cygming
===================================================================
--- gcc/config/i386/t-cygming	(revision 145828)
+++ gcc/config/i386/t-cygming	(working copy)
@@ -37,6 +37,13 @@ msformat-c.o: $(srcdir)/config/i386/msformat-c.c $
 
 STMP_FIXINC=stmp-fixinc
 
+# Building and linking gcj, gcj-tools stretches a 32-bit Windows
+# system to its limits, and the default per-thread stack allocation
+# is way too low.  Add a target-specific make variable definition
+# to extend LDFLAGS so that the compiler is built with header fields
+# set to make the runtime loader give it a big stack allocation.
+jc1$(exeext): LDFLAGS+=-Wl,-stack,0x8000000
+
 # Build a shared libgcc library for PECOFF with a DEF file
 # with the GNU linker.
 #
Index: configure.ac
===================================================================
--- configure.ac	(revision 145828)
+++ configure.ac	(working copy)
@@ -727,7 +727,7 @@ case "${target}" in
     ;;    
   *-*-cygwin*)
     target_configdirs="$target_configdirs target-libtermcap target-winsup"
-    noconfigdirs="$noconfigdirs target-gperf target-libgloss ${libgcj}"
+    noconfigdirs="$noconfigdirs target-gperf target-libgloss"
     # always build newlib if winsup directory is present.
     if test -d "$srcdir/winsup/cygwin"; then
       skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'`
Index: boehm-gc/win32_threads.c
===================================================================
--- boehm-gc/win32_threads.c	(revision 145828)
+++ boehm-gc/win32_threads.c	(working copy)
@@ -753,6 +753,12 @@ int GC_pthread_detach(pthread_t thread)
     return result;
 }
 
+GC_PTR GC_get_thread_stack_base()
+{
+  extern GC_PTR _tlsbase __asm__ ("%fs:4");
+  return _tlsbase;
+}
+
 #else /* !CYGWIN32 */
 
 /*
Index: libffi/src/x86/win32.S
===================================================================
--- libffi/src/x86/win32.S	(revision 145828)
+++ libffi/src/x86/win32.S	(working copy)
@@ -32,11 +32,12 @@
  
 .text
  
-.globl ffi_prep_args
+.globl _ffi_prep_args
  
         # This assumes we are using gas.
         .balign 16
 .globl _ffi_call_SYSV
+	.def	_ffi_call_SYSV;	.scl	2;	.type	32;	.endef
  
 _ffi_call_SYSV:
         pushl %ebp
@@ -152,6 +153,7 @@ epilogue:
 .globl _ffi_call_STDCALL
 
 _ffi_call_STDCALL:
+	.def	_ffi_call_STDCALL;	.scl	2;	.type	32;	.endef
         pushl %ebp
         movl  %esp,%ebp
 
@@ -259,6 +261,7 @@ sc_epilogue:
 .ffi_call_STDCALL_end:
 
 	.globl _ffi_closure_SYSV
+	.def	_ffi_closure_SYSV;	.scl	2;	.type	32;	.endef
 _ffi_closure_SYSV:
 	pushl	%ebp
 	movl	%esp, %ebp
@@ -322,6 +325,7 @@ _ffi_closure_SYSV:
 
 	.balign	16
 	.globl _ffi_closure_raw_SYSV
+	.def	_ffi_closure_raw_SYSV;	.scl	2;	.type	32;	.endef
 _ffi_closure_raw_SYSV:
 	pushl	%ebp
 	movl	%esp, %ebp
Index: libffi/configure.host
===================================================================
--- libffi/configure.host	(revision 145828)
+++ libffi/configure.host	(working copy)
@@ -8,4 +8,8 @@ case "${host}" in
   frv*-elf)
     LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
     ;;
+  i?86-*-cygwin*)
+    # Redirect installation to gcc private dir.
+    host__toolexeclibdir='$(toollibffidir)'
+    ;;
 esac
Index: libffi/configure.ac
===================================================================
--- libffi/configure.ac	(revision 145828)
+++ libffi/configure.ac	(working copy)
@@ -344,6 +344,7 @@ if test -n "$with_cross_host" &&
    test x"$with_cross_host" != x"no"; then
   toolexecdir='$(exec_prefix)/$(target_alias)'
   toolexeclibdir='$(toolexecdir)/lib'
+  test "${host__toolexeclibdir+set}" = set && toolexeclibdir=${host__toolexeclibdir}
 else
   toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
   toolexeclibdir='$(libdir)'
Index: libffi/Makefile.am
===================================================================
--- libffi/Makefile.am	(revision 145828)
+++ libffi/Makefile.am	(working copy)
@@ -31,6 +31,10 @@ EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj
 	src/pa/ffitarget.h src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S \
 	src/frv/ffi.c src/frv/eabi.S src/frv/ffitarget.h
 
+# Where generated headers like ffitarget.h get installed.
+gcc_version   = $(shell cat $(top_srcdir)/../gcc/BASE-VER)
+toollibffidir = $(libdir)/gcc/$(target_alias)/$(gcc_version)
+
 ## ################################################################
 
 ##
@@ -156,7 +160,8 @@ nodist_libffi_convenience_la_SOURCES = $(nodist_li
 
 AM_CFLAGS = -Wall -g -fexceptions
 
-LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \
+        -no-undefined
 
 libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LTLDFLAGS)
 
Index: libjava/libltdl/ltdl.c
===================================================================
--- libjava/libltdl/ltdl.c	(revision 145828)
+++ libjava/libltdl/ltdl.c	(working copy)
@@ -142,7 +142,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor,
 /* --- WINDOWS SUPPORT --- */
 
 
-#ifdef DLL_EXPORT
+#ifdef LIBLTDL_DLL_EXPORT
 #  define LT_GLOBAL_DATA	__declspec(dllexport)
 #else
 #  define LT_GLOBAL_DATA
Index: libjava/libltdl/ltdl.h
===================================================================
--- libjava/libltdl/ltdl.h	(revision 145828)
+++ libjava/libltdl/ltdl.h	(working copy)
@@ -128,7 +128,7 @@ LT_BEGIN_C_DECLS
    ridiculous implementation of data symbol exporting. */
 #ifndef LT_SCOPE
 #  ifdef __WINDOWS__
-#    ifdef DLL_EXPORT		/* defined by libtool (if required) */
+#    ifdef LIBLTDL_DLL_EXPORT	/* don't define or ld disables auto-export. */
 #      define LT_SCOPE	__declspec(dllexport)
 #    endif
 #    ifdef LIBLTDL_DLL_IMPORT	/* define if linking with this dll */
Index: libjava/configure.ac
===================================================================
--- libjava/configure.ac	(revision 145828)
+++ libjava/configure.ac	(working copy)
@@ -885,6 +885,9 @@ arm*linux*eabi)
     LIBSTDCXXSPEC=-lstdc++
     LIBGCJTESTSPEC="-L`${PWDCMD-pwd}`/.libs -L`${PWDCMD-pwd}`/../libstdc++-v3/src/.libs -rpath `${PWDCMD-pwd}`/.libs:`${PWDCMD-pwd}`/../libstdc++-v3/src/.libs -lstdc++"
     ;;
+*-*-mingw*|*-*-cygwin)
+    extra_ldflags_libjava=-lws2_32
+    ;;
 esac
 AC_SUBST(extra_ldflags_libjava)
 AC_SUBST(extra_gij_ldflags)
Index: libjava/sysdep/i386/backtrace.h
===================================================================
--- libjava/sysdep/i386/backtrace.h	(revision 145828)
+++ libjava/sysdep/i386/backtrace.h	(working copy)
@@ -13,7 +13,14 @@ details.  */
 
 #include <java-stack.h>
 
-extern int main (int, char **);
+#ifdef __CYGWIN__
+/* To allow this to link as a DLL.  */
+#define MAIN_FUNC dll_crt0__FP11per_process
+extern "C" int MAIN_FUNC () __declspec(dllimport);
+#else /* !__CYGWIN__ */
+#define MAIN_FUNC main
+extern int MAIN_FUNC (int, char **);
+#endif /* ?__CYGWIN__ */
 
 /* The context used to keep track of our position while unwinding through
    the call stack.  */
@@ -104,7 +111,7 @@ fallback_backtrace (_Unwind_Trace_Fn trace_fn, _Jv
                             const char **, bool))_Jv_RunMain;
       if (ctx.meth_addr == (_Jv_uintptr_t)jv_runmain
           || ctx.meth_addr == (_Jv_uintptr_t)_Jv_ThreadStart
-          || (ctx.meth_addr - (_Jv_uintptr_t)main) < 16)
+          || (ctx.meth_addr - (_Jv_uintptr_t)MAIN_FUNC) < 16)
         break;
     }
 
Index: libjava/Makefile.am
===================================================================
--- libjava/Makefile.am	(revision 145828)
+++ libjava/Makefile.am	(working copy)
@@ -134,7 +134,8 @@ GCJLINK = $(LIBTOOL) --tag=GCJ --mode=link $(GCJ)
 GCJ_FOR_ECJX = @GCJ_FOR_ECJX@
 GCJ_FOR_ECJX_LINK = $(GCJ_FOR_ECJX) -o $@
 LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) \
-          $(LTLDFLAGS) $(extra_ldflags_libjava) $(extra_ldflags) -o $@
+          $(LTLDFLAGS) $(extra_ldflags_libjava) $(extra_ldflags) -no-undefined \
+          -o $@
 CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
 	$(CXXFLAGS) $(AM_LDFLAGS) $(LTLDFLAGS) -o $@
 
@@ -221,7 +222,7 @@ libgij_la_DEPENDENCIES = libgcj.la libgcj.spec
 ## See jv_convert_LDADD.
 libgij_la_LIBADD = -L$(here)/.libs libgcj.la
 ## The mysterious backslash in the grep pattern is consumed by make.
-libgij_la_LDFLAGS = -rpath $(toolexeclibdir) \
+libgij_la_LDFLAGS = -rpath $(toolexeclibdir) -no-undefined \
         -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LIBGCJ_LD_SYMBOLIC)
 
 if INTERPRETER
@@ -311,6 +312,7 @@ libgcj_tools_la_LDFLAGS = -rpath $(toolexeclibdir)
  -version-info `grep -v '^\#' $(srcdir)/libtool-version` \
  $(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
 libgcj_tools_la_DEPENDENCIES = libgcj.la libgcj.spec
+libgcj_tools_la_LIBADD = -L$(here)/.libs libgcj.la
 libgcj_tools_la_LINK = $(LIBLINK)
 
 ## libjvm.so
@@ -318,7 +320,7 @@ libjvm_la_SOURCES = jni-libjvm.cc
 libjvm_la_DEPENDENCIES = libgcj.la libgcj.spec
 ## See jv_convert_LDADD.
 libjvm_la_LIBADD = -L$(here)/.libs libgcj.la
-libjvm_la_LDFLAGS = -avoid-version $(LIBGCJ_LD_SYMBOLIC)
+libjvm_la_LDFLAGS = -avoid-version $(LIBGCJ_LD_SYMBOLIC) -no-undefined
 
 ## The .db file.  This rule is only used for native builds, so it is
 ## safe to invoke gcj-dbtool.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]