Patchwork [libjava] : Do some fixes for windows native targets

login
register
mail settings
Submitter Kai Tietz
Date April 6, 2011, 2:39 p.m.
Message ID <BANLkTinxFhAtvOhiER9KKDG8z4b_Aj2BMA@mail.gmail.com>
Download mbox | patch
Permalink /patch/90027/
State New
Headers show

Comments

Kai Tietz - April 6, 2011, 2:39 p.m.
2011/4/6 Kai Tietz <ktietz70@googlemail.com>:
> 2011/4/5 Tom Tromey <tromey@redhat.com>:
>>>>>>> "Kai" == Kai Tietz <ktietz70@googlemail.com> writes:
>>
>> Kai> this patch fixes some issues in libjava for windows targets.  It
>> Kai> addresses for now only 32-bit target, but for JNICALL definition I
>> Kai> introduced already logic for 64-bit windows target too as preparation.
>>
>> Most of this seems ok to me.
>>
>> Kai>    * java/lang/reflect/Field.h (_Jv_JNI_ToReflectedField):
>> Kai>    Likewise.
>> Kai>    * java/lang/reflect/Constructor.h (_Jv_JNI_ToReflectedMethod):
>> Kai>    Likewise.
>>
>> These headers are generated.  You have to edit headers.txt and then
>> rebuild them.
>>
>> Tom
>>
>
> Hi Tom,
>
> I added to headers.txt the changes and regenerate headers.  Btw it is
> a bit tricky to enable for libjava the maintainer-mode and then have a
> successful configure for it ...
>
> ChangeLog
>
> 2011-04-06  Kai Tietz
>
>        * configure.ac (libgcj_ld_export_all): Set for windows
>        native targets to export-all-symbols.
>        (LIBGCJ_LD_EXPORT_ALL): Export libgcj_ld_export_all.
>        * Makefile.am (libgcj_la_LDFLAGS): Add LIBGCJ_LD_EXPORT_ALL.
>        * sysdep/i386/backtrace.h (MAIN_FUNC): Define for windows
>        native targets to DllMain.
>        * gcj/javaprims.h (JNICALL): Define it dependent
>        for different windows targets.
>        * include/jni_md.h: Likewise.
>        * headers.txt (_Jv_JNI_ToReflectedField): Mark
>        JNICALLS for friends.
>        (_Jv_JNI_ToReflectedMethod): Likewise.
>        * java/lang/Class.h: Regenerated.
>        * java/lang/reflect/Field.h: Regenerated.
>        * java/lang/reflect/Constructor.h: Regenerated.
>        * configure: Regenerated.
>        * Makefile.in: Regenerated.
>        * include/Makefile.in: Regenerated.
>        * testsuite/Makefile.in: Regenerated.
>        * gcj/Makefile.in: Regenerated.
>
> Ok for apply?
>
> Regards,
> Kai
>

Sorry, found a typo. Updated patch attached.

Kai
Tom Tromey - April 8, 2011, 1:50 p.m.
>>>>> "Kai" == Kai Tietz <ktietz70@googlemail.com> writes:

Kai> I added to headers.txt the changes and regenerate headers.  Btw it is
Kai> a bit tricky to enable for libjava the maintainer-mode and then have a
Kai> successful configure for it ...

[...]

Kai> Sorry, found a typo. Updated patch attached.

This is ok.  Thanks.

Tom
Kai Tietz - April 8, 2011, 2:17 p.m.
2011/4/8 Tom Tromey <tromey@redhat.com>:
>>>>>> "Kai" == Kai Tietz <ktietz70@googlemail.com> writes:
>
> Kai> I added to headers.txt the changes and regenerate headers.  Btw it is
> Kai> a bit tricky to enable for libjava the maintainer-mode and then have a
> Kai> successful configure for it ...
>
> [...]
>
> Kai> Sorry, found a typo. Updated patch attached.
>
> This is ok.  Thanks.
>
> Tom
>

Applied at revision 172186.

Kai

Patch

Index: gcc-head/libjava/Makefile.am
===================================================================
--- gcc-head.orig/libjava/Makefile.am
+++ gcc-head/libjava/Makefile.am
@@ -492,7 +492,7 @@  xlib_nat_files = $(xlib_nat_source_files
 libgcj_la_LDFLAGS = -rpath $(toolexeclibdir) $(THREADLDFLAGS) $(extra_ldflags) $(THREADLIBS) \
 	$(LIBLTDL) $(SYS_ZLIBS) $(LIBJAVA_LDFLAGS_NOUNDEF) \
 	-version-info `grep -v '^\#' $(srcdir)/libtool-version` \
-	$(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+	$(LIBGCJ_LD_SYMBOLIC_FUNCTIONS) $(LIBGCJ_LD_EXPORT_ALL)
 libgcj_la_LIBADD = \
 	classpath/native/fdlibm/libfdlibm.la \
 	java/lang/Object.lo \
Index: gcc-head/libjava/configure.ac
===================================================================
--- gcc-head.orig/libjava/configure.ac
+++ gcc-head/libjava/configure.ac
@@ -214,6 +214,16 @@  if test -z "$libgcj_ld_symbolic"; then
   libgcj_ld_symbolic=$SYMBOLIC_LDFLAGS
 fi
 
+# for windows native targets enforce export of all symbols for shared libgcj.
+libgcj_ld_export_all=
+case "$host" in
+      *mingw*)
+	libgcj_ld_export_all=-Wl,--export-all-symbols
+	;;
+      *)
+        ;;
+esac
+
 LIBGCJ_CFLAGS="${libgcj_cflags}"
 LIBGCJ_CXXFLAGS="${libgcj_cxxflags}"
 LIBGCJ_JAVAFLAGS="${libgcj_javaflags}"
@@ -221,6 +231,7 @@  LIBGCJ_SUBLIB_LTFLAGS="${libgcj_sublib_l
 LIBGCJ_SUBLIB_CORE_EXTRA_DEPS="${libgcj_sublib_core_extra_deps}"
 LIBGCJ_LD_SYMBOLIC="${libgcj_ld_symbolic}"
 LIBGCJ_LD_SYMBOLIC_FUNCTIONS="${libgcj_ld_symbolic_functions}"
+LIBGCJ_LD_EXPORT_ALL="${libgcj_ld_export_all}"
 AC_SUBST(LIBGCJ_CFLAGS)
 AC_SUBST(LIBGCJ_CXXFLAGS)
 AC_SUBST(LIBGCJ_JAVAFLAGS)
@@ -228,6 +239,7 @@  AC_SUBST(LIBGCJ_SUBLIB_LTFLAGS)
 AC_SUBST(LIBGCJ_SUBLIB_CORE_EXTRA_DEPS)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+AC_SUBST(LIBGCJ_LD_EXPORT_ALL)
 
 # Only use libltdl for non-newlib builds.
 if test "x${with_newlib}" = "x" || test "x${with_newlib}" = "xno"; then
@@ -930,6 +942,9 @@  arm*linux*eabi)
 *-*-cygwin)
     extra_ldflags_libjava=-liconv
     ;;
+*-*-mingw*)
+    extra_ldflags_libjava=-lws2_32
+    ;;
 esac
 
 LIBMATHSPEC=
Index: gcc-head/libjava/gcj/javaprims.h
===================================================================
--- gcc-head.orig/libjava/gcj/javaprims.h
+++ gcc-head/libjava/gcj/javaprims.h
@@ -26,6 +26,15 @@  details.  */
 #undef FALSE
 #define FALSE FALSE
 
+// JNI calling convention also defined in jni.h  */
+#ifndef JNICALL
+ #if (defined (_WIN32) || defined (__WIN32__) || defined (WIN32)) && !defined (_WIN64)
+  #define JNICALL __stdcall
+ #else
+  #define JNICALL
+ #endif
+#endif
+
 // To force selection of correct types that will mangle consistently
 // across platforms.
 extern "Java"
Index: gcc-head/libjava/headers.txt
===================================================================
--- gcc-head.orig/libjava/headers.txt
+++ gcc-head/libjava/headers.txt
@@ -41,26 +41,26 @@  friend jstring (::_Jv_AllocString) (jsiz
 
 class java/lang/reflect/Constructor
 prepend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
-prepend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+prepend jobject JNICALL _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
 friend jmethodID (::_Jv_FromReflectedConstructor) (java::lang::reflect::Constructor *);
-friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+friend jobject JNICALL (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
 friend class java::lang::Class;
 
 class java/lang/reflect/Field
 prepend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
-prepend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
+prepend jobject JNICALL _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
 prepend jobject _Jv_getFieldInternal (java::lang::reflect::Field *f, jclass c, jobject o);
 friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *);
-friend jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
+friend jobject JNICALL (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
 friend class java::lang::Class;
 friend jobject (::_Jv_getFieldInternal) (java::lang::reflect::Field *f, jclass c, jobject o);
 
 class java/lang/reflect/Method
 prepend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
-prepend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+prepend jobject JNICALL _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
 prepend ::java::lang::reflect::Method *_Jv_GetReflectedMethod (jclass, _Jv_Utf8Const*, _Jv_Utf8Const*);
 friend jmethodID (::_Jv_FromReflectedMethod) (java::lang::reflect::Method *);
-friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+friend jobject JNICALL (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
 friend class java::lang::Class;
 friend class java::io::ObjectInputStream;
 friend java::lang::reflect::Method* ::_Jv_GetReflectedMethod (jclass, _Jv_Utf8Const*, _Jv_Utf8Const*);
Index: gcc-head/libjava/include/jni_md.h
===================================================================
--- gcc-head.orig/libjava/include/jni_md.h
+++ gcc-head/libjava/include/jni_md.h
@@ -65,6 +65,15 @@  typedef struct _Jv_JavaVM JavaVM;
      reused between non-nesting JNI calls.  */				\
   struct _Jv_JNI_LocalFrame *bottom_locals;
 
+/*  JNI calling convention.  Also defined in javaprims.h. */
+#ifndef JNICALL
+#if (defined (_WIN32) || defined (__WIN32__) || defined (WIN32)) \
+    && !defined (_WIN64)
+  #define JNICALL __stdcall
+ #else
+  #define JNICALL
+ #endif
+#endif
 
 #else /* __GCJ_JNI_IMPL__ */
 
@@ -117,14 +126,17 @@  typedef uint16_t jchar;
 
 
 /* Linkage and calling conventions. */
-#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
+#if (defined (_WIN32) || defined (__WIN32__) || defined (WIN32)) \
+    && !defined (_WIN64)
 
 #define JNIIMPORT        __declspec(dllimport)
 #define JNIEXPORT        __declspec(dllexport)
 
-#define JNICALL          __stdcall
+#ifndef JNICALL
+#define JNICALL __stdcall
+#endif
 
-#else /* !( _WIN32 || __WIN32__ || WIN32) */
+#else /* !( _WIN32 || __WIN32__ || WIN32) || _WIN64 */
 
 #define JNIIMPORT
 #if defined(__GNUC__) && __GNUC__ > 3
@@ -133,9 +145,11 @@  typedef uint16_t jchar;
 #define JNIEXPORT
 #endif
 
+#ifndef JNICALL
 #define JNICALL
+#endif
 
-#endif /* !( _WIN32 || __WIN32__ || WIN32) */
+#endif /* !( _WIN32 || __WIN32__ || WIN32) || _WIN64 */
 
 /* These defines apply to symbols in libgcj */
 #ifdef __GCJ_DLL__
Index: gcc-head/libjava/java/lang/Class.h
===================================================================
--- gcc-head.orig/libjava/java/lang/Class.h
+++ gcc-head/libjava/java/lang/Class.h
@@ -251,10 +251,10 @@  bool _Jv_getInterfaceMethod(jclass, jcla
 			    const _Jv_Utf8Const*,
 			    const _Jv_Utf8Const*);
 
-jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
-				  jboolean);
-jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
-				   jboolean);
+jobject JNICALL _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
+					  jboolean);
+jobject JNICALL _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
+					   jboolean);
 jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
 
 jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
Index: gcc-head/libjava/java/lang/reflect/Constructor.h
===================================================================
--- gcc-head.orig/libjava/java/lang/reflect/Constructor.h
+++ gcc-head/libjava/java/lang/reflect/Constructor.h
@@ -11,7 +11,7 @@ 
 
 
 jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
-jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+jobject JNICALL _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
 
 class java::lang::reflect::Constructor : public ::java::lang::reflect::AccessibleObject
 {
@@ -58,7 +58,7 @@  public:
   static ::java::lang::Class class$;
 
   friend jmethodID (::_Jv_FromReflectedConstructor) (java::lang::reflect::Constructor *);
-  friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
+  friend jobject JNICALL (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);
   friend class java::lang::Class;
 };
 
Index: gcc-head/libjava/java/lang/reflect/Field.h
===================================================================
--- gcc-head.orig/libjava/java/lang/reflect/Field.h
+++ gcc-head/libjava/java/lang/reflect/Field.h
@@ -11,7 +11,7 @@ 
 
 
 jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
-jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
+jobject JNICALL _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
 jobject _Jv_getFieldInternal (java::lang::reflect::Field *f, jclass c, jobject o);
 
 class java::lang::reflect::Field : public ::java::lang::reflect::AccessibleObject
@@ -90,7 +90,7 @@  public:
   static ::java::lang::Class class$;
 
   friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *);
-  friend jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
+  friend jobject JNICALL (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean);
   friend class java::lang::Class;
   friend jobject (::_Jv_getFieldInternal) (java::lang::reflect::Field *f, jclass c, jobject o);
 };
Index: gcc-head/libjava/sysdep/i386/backtrace.h
===================================================================
--- gcc-head.orig/libjava/sysdep/i386/backtrace.h
+++ gcc-head/libjava/sysdep/i386/backtrace.h
@@ -17,7 +17,10 @@  details.  */
 /* To allow this to link as a DLL.  */
 #define MAIN_FUNC dll_crt0__FP11per_process
 extern "C" int MAIN_FUNC () __declspec(dllimport);
-#else /* !__CYGWIN__ */
+#elif defined (_WIN32)
+#define MAIN_FUNC DllMain
+extern "C" int __stdcall MAIN_FUNC (void *, unsigned long, void *);
+#else /* !__CYGWIN__ && !_WIN32 */
 #define MAIN_FUNC main
 extern int MAIN_FUNC (int, char **);
 #endif /* ?__CYGWIN__ */