public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH] make libgcj_bc prims symbol sizes correct
@ 2009-08-15  0:08 Nix
  2009-08-15  8:56 ` Andrew Haley
  0 siblings, 1 reply; 9+ messages in thread
From: Nix @ 2009-08-15  0:08 UTC (permalink / raw)
  To: java; +Cc: Tom Tromey

Way back in 2006, in
<http://gcc.gnu.org/ml/java-patches/2006-q3/msg00342.html>, you said, of
the evil trick whereby DECLARE_PRIM_TYPE declares an int in libgcj_bc.so
but a Class * in libgcj itself:

> I'm a little surprised this works -- I would have expected that
> something (ld?  ld.so?), would want the objects to have the proper
> size.  However, this doesn't seem to be the case.

Well, it's stopped working :( on my Linux x86_64/eglibc-2.10 box, GCC
4.4's testsuite says this in every test that pulls in one of the
primitive types (e.g. Array_1 and a whole lot more):

/usr/src/gcc/x86_64-spindle/x86_64-pc-linux-gnu/libjava/testsuite/Array_1.exe: Symbol `_Jv_intClass' has different size in shared object, consider re-linking

Then it dumps core:

Program terminated with signal 6, Aborted.
[New process 20396]
[New process 20398]
#0  0x00007f84e5603d75 in raise () from /lib/libc.so.6
(gdb) bt
#0  0x00007f84e5603d75 in raise () from /lib/libc.so.6
#1  0x00007f84e56069ff in *__GI_abort () at abort.c:88
#2  0x00007f84e3a1181b in _Jv_Throw (value=0x7f84e5cde2f8) at /usr/src/gcc/4.4-090813/libjava/exception.cc:128
#3  0x00007f84e3a058ba in _Jv_catch_segv (_p=<value optimized out>) at /usr/src/gcc/4.4-090813/libjava/prims.cc:184
#4  <signal handler called>
#5  0x0000000000000000 in ?? ()
#6  0x0000000000400b97 in Array_1.main(java.lang.String[])void () at Array_1.java:16
#7  0x00007f84e3a40e1a in gnu::java::lang::MainThread::call_main (this=0x7f84e5bb1dc0) at /usr/src/gcc/4.4-090813/libjava/gnu/java/lang/natMainThread.cc:54
#8  0x00007f84e3aa2c34 in gnu.java.lang.MainThread.run()void (this=0x7f84e5bb1dc0) at /usr/src/gcc/4.4-090813/libjava/gnu/java/lang/MainThread.java:106
#9  0x00007f84e3a516fa in _Jv_ThreadRun (thread=0x7f84e5bb1dc0) at /usr/src/gcc/4.4-090813/libjava/java/lang/natThread.cc:335
#10 0x00007f84e3a05fe5 in _Jv_RunMain (vm_args=<value optimized out>, klass=0x0, name=<value optimized out>, argc=1, argv=0x7f84e17d3fc0, is_jar=<value optimized out>) at /usr/src/gcc/4.4-090813/libjava/prims.cc:1789
#11 0x00007f84e55f0a7d in __libc_start_main () from /lib/libc.so.6
#12 0x0000000000400919 in _start ()

This is with GNU ld 2.19.1.20090202. Obviously the dynamic linker is
complaining, not the linker itself, but whichever it is, this trick will
obviously no longer work. We need to get the sizes of symbols right.

Obviously it is not sane nor portable to hardwire type sizes: so the
right approach is probably to compile libgcj_bc.c with the same compiler
as is used for prims.cc and duplicate the type properly, which means
renaming it to libgcj_bc.cc, including <java/lang/Class.h>, and,
unfortunately, fixing up all the prototypes :/


Fix (against 4.4 branch head) attached, following which all libjava
tests pass (actually these are the cleanest test results I've ever seen
from GCC, people are doing a really good job XFAILing known-broken
stuff). Not posted to -patches because I really really doubt that this
is even vaguely tolerable, even though it works. Please please can
someone think of something less ugly?

(The commented-out things are there as a reminder that these are part of
the libgcj_bc ABI, but happen to be provided by inlines in the header
files now, so cannot be redeclared.)

Downside: everything that <java/lang/Class.h> declares as a non-static
extern inline will now land in libgcj_bc.so as well. I think this is
probably better than a core dump...

2009-08-15  Nix  <nix@esperi.org.uk>

	* libgcj_bc.c: Rename to...
	* libgcj_bc.cc: ... this, adjusting prototypes and inclusions.
	* libgcj_bc.cc (DECLARE_PRIM_TYPE): Use definition from prims.cc.
	* Makefile.am (libgcj_bc_la_SOURCES): Adjust correspondingly.
	* Makefile.in (libgcj_bc_la_SOURCES): Likewise.

Index: gcc/libjava/libgcj_bc.c
===================================================================
--- gcc.orig/libjava/libgcj_bc.c	2009-08-15 01:01:28.000000000 +0100
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,114 +0,0 @@
-/* libgcj_bc.c  */
-
-/* Copyright (C) 2006, 2009 Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-/* This file is used to build libgcj_bc.so, a 'fake' library that is
-   used at link time only. It ensures that binaries built with the
-   BC-ABI link against a constant SONAME. This way, BC-ABI binaries
-   continue to work if the SONAME underlying libgcj.so changes.  */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-static void print_wrong_lib_msg ()
-{
-  fprintf (stderr, "libgcj error: \
-This is libgcj_bc.so, a fake library used only for linking.\n\
-Please create a symlink from libgcj_bc.so.1 to the real libgcj.so.\n");
-  exit (1);
-}
-
-/* Functions called from code generated by gcj.  */
-
-void _Jv_AllocObject () {}
-void _Jv_AllocObjectNoFinalizer () {}
-void _Jv_CheckArrayStore () {}
-void _Jv_CheckCast () {}
-void _Jv_InitClass () {}
-void _Jv_IsInstanceOf () {}
-void _Jv_LookupInterfaceMethod () {}
-void _Jv_LookupInterfaceMethodIdx () {}
-void _Jv_MonitorEnter () {}
-void _Jv_MonitorExit () {}
-void _Jv_NewMultiArray () {}
-void _Jv_NewObjectArray () {}
-void _Jv_NewPrimArray () {}
-void _Jv_RegisterResource () {}
-void _Jv_ResolvePoolEntry () {}
-void _Jv_Throw () {}
-void _Jv_ThrowAbstractMethodError () {}
-void _Jv_ThrowBadArrayIndex () {}
-void _Jv_ThrowNoSuchFieldError () {}
-void _Jv_ThrowNullPointerException () {}
-void __gcj_personality_v0 () {}
-
-void _Jv_RegisterClasses () 
-{
-  print_wrong_lib_msg ();
-}
-
-void _Jv_RegisterNewClasses () 
-{
-  print_wrong_lib_msg ();
-}
-
-/* Symbols used by jvgenmain (-fmain).  */
-
-void JvRunMain () {}
-void JvRunMainName () {}
-const char **_Jv_Compiler_Properties;
-
-/* Functions used by -fjni.  */
-
-void _Jv_GetJNIEnvNewFrame () {}
-void _Jv_LookupJNIMethod () {}
-void _Jv_UnwrapJNIweakReference () {}
-void _Jv_JNI_PopSystemFrame () {}
-
-
-/* Checked divide (-fuse-divide-subroutine).  */
-
-void _Jv_divI () {}
-void _Jv_divJ () {}
-void _Jv_remI () {}
-void _Jv_remJ () {}
-
-
-/* CNI Functions.  */
-
-void _Jv_AllocBytes () {}
-void _Jv_AllocString () {}
-void _Jv_AttachCurrentThread () {}
-void _Jv_AttachCurrentThreadAsDaemon () {}
-void _Jv_CreateJavaVM () {}
-void _Jv_DetachCurrentThread () {}
-void _Jv_Free () {}
-void _Jv_GetStringUTFLength () {}
-void _Jv_GetStringUTFRegion () {}
-void _Jv_Malloc () {}
-void _Jv_NewString () {}
-void _Jv_NewStringLatin1 () {}
-void _Jv_NewStringUTF () {}
-void _Jv_Realloc () {}
-
-
-/* Classes for primitive types.  */
-
-#define DECLARE_PRIM_TYPE(NAME)			\
-  int _Jv_##NAME##Class;
-
-DECLARE_PRIM_TYPE(byte)
-DECLARE_PRIM_TYPE(short)
-DECLARE_PRIM_TYPE(int)
-DECLARE_PRIM_TYPE(long)
-DECLARE_PRIM_TYPE(boolean)
-DECLARE_PRIM_TYPE(char)
-DECLARE_PRIM_TYPE(float)
-DECLARE_PRIM_TYPE(double)
-DECLARE_PRIM_TYPE(void)
Index: gcc/libjava/libgcj_bc.cc
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/libjava/libgcj_bc.cc	2009-08-15 01:04:21.734930987 +0100
@@ -0,0 +1,118 @@
+/* libgcj_bc.cc  */
+
+/* Copyright (C) 2006, 2009 Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+/* This file is used to build libgcj_bc.so, a 'fake' library that is
+   used at link time only. It ensures that binaries built with the
+   BC-ABI link against a constant SONAME. This way, BC-ABI binaries
+   continue to work if the SONAME underlying libgcj.so changes.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <java/lang/Class.h>
+
+static void print_wrong_lib_msg ()
+{
+  fprintf (stderr, "libgcj error: \
+This is libgcj_bc.so, a fake library used only for linking.\n\
+Please create a symlink from libgcj_bc.so.1 to the real libgcj.so.\n");
+  exit (1);
+}
+
+/* Functions called from code generated by gcj.  */
+
+extern "C"
+{
+  jobject _Jv_AllocObject (jclass) { return NULL; }
+  jobject _Jv_AllocObjectNoFinalizer (jclass) { return NULL; }
+  void _Jv_CheckArrayStore (jobject, jobject) {}
+  void *_Jv_CheckCast (jclass, jobject) { return NULL; }
+  //  In the ABI, provided by an extern inline.
+  //  void _Jv_InitClass (jclass) {}
+  jboolean _Jv_IsInstanceOf(jobject, jclass) { return 0; }
+  void *_Jv_LookupInterfaceMethod (jclass, void *, void *) { return NULL; }
+  void *_Jv_LookupInterfaceMethodIdx (jclass, jclass, int) { return NULL; }
+  void _Jv_MonitorEnter (jobject) {}
+  void _Jv_MonitorExit (jobject) {}
+  jobject _Jv_NewMultiArray (jclass, jint, ...) { return NULL; }
+  jobjectArray _Jv_NewObjectArray(jsize, jclass, jobject) { return NULL; }
+  jobject _Jv_NewPrimArray (jclass, jint) { return NULL; }
+  void *_Jv_ResolvePoolEntry (jclass, jint) { return NULL; }
+  void _Jv_Throw (jthrowable) { exit (0); }
+  void _Jv_ThrowAbstractMethodError () { exit (0); }
+  void _Jv_ThrowBadArrayIndex (jint)  { exit (0); }
+  void _Jv_ThrowNoSuchFieldError (int) { exit (0); }
+  void _Jv_ThrowNullPointerException (void) { exit (0); }
+  void __gcj_personality_v0 () {}
+
+  void _Jv_RegisterClasses (const jclass *)
+  {
+    print_wrong_lib_msg ();
+  }
+
+  void _Jv_RegisterNewClasses (char **)
+  {
+    print_wrong_lib_msg ();
+  }
+
+  /* Symbols used by jvgenmain (-fmain).  */
+
+  void JvRunMain (jclass, int, const char **) {}
+  void JvRunMainName (const char *, int, const char **) {}
+  const char **_Jv_Compiler_Properties;
+
+  /* Functions used by -fjni.  */
+
+  void * _Jv_GetJNIEnvNewFrame (jclass) { return NULL; }
+  void *_Jv_LookupJNIMethod (jclass, _Jv_Utf8Const, _Jv_Utf8Const *, int) { return NULL; }
+  jobject _Jv_UnwrapJNIweakReference (jobject) { return NULL; }
+  void _Jv_JNI_PopSystemFrame (void *) {}
+
+
+  /* Checked divide (-fuse-divide-subroutine).  */
+
+  jint _Jv_divI (jint, jint) { return 0; }
+  jlong _Jv_divJ (jlong, jlong) { return 0; }
+  jint _Jv_remI (jint, jint) { return 0; }
+  jlong _Jv_remJ (jlong, jlong) { return 0; }
+
+
+  /* CNI Functions.  */
+
+  //  In the ABI, provided by extern inlines.
+  //  void _Jv_AllocBytes () {}
+  //  void _Jv_AllocString () {}
+  //  void _Jv_AttachCurrentThread () {}
+  //  void _Jv_AttachCurrentThreadAsDaemon () {}
+  //  void _Jv_CreateJavaVM () {}
+  //  void _Jv_DetachCurrentThread () {}
+  void _Jv_Free (void*) {}
+  jsize _Jv_GetStringUTFLength (jstring) { return 0; }
+  jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *) { return 0; }
+  void* _Jv_Malloc (jsize) { return 0; }
+  jstring _Jv_NewString (const jchar*, jsize) { return NULL; }
+  jstring _Jv_NewStringLatin1(const char*, jsize) { return NULL; }
+  jstring _Jv_NewStringUTF (const char *) { return NULL; }
+  void* _Jv_Realloc (void *, jsize) { return NULL; }
+}
+
+/* Classes for primitive types.  */
+
+#define DECLARE_PRIM_TYPE(NAME)			\
+  java::lang::Class _Jv_##NAME##Class __attribute__ ((aligned (8)));
+
+DECLARE_PRIM_TYPE(byte)
+DECLARE_PRIM_TYPE(short)
+DECLARE_PRIM_TYPE(int)
+DECLARE_PRIM_TYPE(long)
+DECLARE_PRIM_TYPE(boolean)
+DECLARE_PRIM_TYPE(char)
+DECLARE_PRIM_TYPE(float)
+DECLARE_PRIM_TYPE(double)
+DECLARE_PRIM_TYPE(void)
Index: gcc/libjava/Makefile.am
===================================================================
--- gcc.orig/libjava/Makefile.am	2009-08-15 01:01:29.000000000 +0100
+++ gcc/libjava/Makefile.am	2009-08-15 01:04:33.128681612 +0100
@@ -358,7 +358,7 @@
 ## Support for libgcj_bc: dummy shared library.
 ##
 ## This lets us have one soname in BC objects and another in C++ ABI objects.
-libgcj_bc_la_SOURCES = libgcj_bc.c
+libgcj_bc_la_SOURCES = libgcj_bc.cc
 libgcj_bc_la_LDFLAGS = -rpath $(toolexeclibdir) -no-static -version-info 1:0:0 \
 	$(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
 libgcj_bc_la_LIBADD = libgcj.la
Index: gcc/libjava/Makefile.in
===================================================================
--- gcc.orig/libjava/Makefile.in	2009-08-15 01:01:29.000000000 +0100
+++ gcc/libjava/Makefile.in	2009-08-15 01:04:33.128681612 +0100
@@ -1069,7 +1069,7 @@
         -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LIBGCJ_LD_SYMBOLIC)
 
 lib_gnu_awt_xlib_la_LINK = $(LIBLINK)
-libgcj_bc_la_SOURCES = libgcj_bc.c
+libgcj_bc_la_SOURCES = libgcj_bc.cc
 libgcj_bc_la_LDFLAGS = -rpath $(toolexeclibdir) -no-static -version-info 1:0:0 \
 	$(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-08-18 22:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-15  0:08 [RFC PATCH] make libgcj_bc prims symbol sizes correct Nix
2009-08-15  8:56 ` Andrew Haley
2009-08-15  9:34   ` Andrew Haley
2009-08-15 19:13     ` Nix
2009-08-17  9:54       ` Andrew Haley
2009-08-17 17:24         ` Andrew Haley
2009-08-17 21:21           ` Nix
2009-08-18  8:42             ` Andrew Haley
2009-08-18 22:25               ` Nix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).