public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix 64-bit PR16923 on Solaris 10+/x86
@ 2011-01-05 17:01 Rainer Orth
  2013-01-08 11:41 ` gaurav.rustagi
  0 siblings, 1 reply; 5+ messages in thread
From: Rainer Orth @ 2011-01-05 17:01 UTC (permalink / raw)
  To: java-patches

The 64-bit PR16923 execution test was failing on Solaris 10+/x86.  The
stack looked like this:

#0  0xfffffd7fff28c47a in _lwp_kill () from /lib/64/libc.so.1
#1  0xfffffd7fff280b6d in thr_kill () from /lib/64/libc.so.1
#2  0xfffffd7fff22db71 in raise () from /lib/64/libc.so.1
#3  0xfffffd7fff203801 in abort () from /lib/64/libc.so.1
#4  0xfffffd7fe8306a63 in _Jv_Throw (value=0x46ff00) at /vol/gcc/src/hg/trunk/solaris/libjava/exception.cc:127
#5  0xfffffd7fe8342902 in java::lang::Class::forName (className=0x47ff40, initialize=1 '\001', loader=0x0) at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/natClass.cc:101
#6  0xfffffd7fe835dbda in gnu.gcj.convert.UnicodeToBytes.getDefaultEncoder()gnu.gcj.convert.UnicodeToBytes () at /vol/gcc/src/hg/trunk/solaris/libjava/gnu/gcj/convert/UnicodeToBytes.java:51
#7  0xfffffd7fe86f0f63 in java.io.PrintStream.PrintStream(java.io.OutputStream, boolean) (this=@46ff30, out=<value optimized out>, auto_flush=<value optimized out>) at /vol/gcc/src/hg/trunk/solaris/libjava/java/io/PrintStream.java:121
#8  0xfffffd7fe870ce96 in java.lang.System.<clinit>()void () at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/System.java:103
#9  0xfffffd7fe834252f in java::lang::Class::initializeClass (this=0xfffffd7fe9a1fa00) at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/natClass.cc:783
#10 0xfffffd7fe8713010 in java.lang.System.getProperty(java.lang.String)java.lang.String (key=@444e10) at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/System.java:367
#11 0xfffffd7fe87173d5 in java.lang.VMClassLoader.getSystemClassLoader()java.lang.ClassLoader () at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/VMClassLoader.java:327
#12 0xfffffd7fe871e10d in java.lang.ClassLoader.<clinit>()void () at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/ClassLoader.java:172
#13 0xfffffd7fe834252f in java::lang::Class::initializeClass (this=0xfffffd7fe9a26800) at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/natClass.cc:783
#14 0xfffffd7fe82faa97 in _Jv_InitClass (vm_args=<value optimized out>) at /vol/gcc/src/hg/trunk/solaris/libjava/java/lang/Class.h:742
#15 _Jv_CreateJavaVM (vm_args=<value optimized out>) at /vol/gcc/src/hg/trunk/solaris/libjava/prims.cc:1666
#16 0xfffffd7fe5de0d48 in JNI_CreateJavaVM (vm=0xfffffd7fffdff748, penv=0xfffffd7fffdff750, args=<value optimized out>) at /vol/gcc/src/hg/trunk/solaris/libjava/jni-libjvm.cc:54
#17 0x0000000000400e3f in main ()

i.e. _Jv_Throw abort()s with _URC_END_OF_STACK.

Unfortunately, this proved to be terribly hard to debug since gdb
couldn't print java variables and I had to go back to adding debug code.

The problem turned out to be remarkably simple: the code wasn't linked
with -shared-libgcc, and this caused the unwinder in libc (amd64 only,
thus only a 64-bit failure) to be used which for some reason didn't call
the Java personality function, breaking exception handling.

I got a clue at the problem when trying a bootstrap with gld instead:

/vol/gcc/bin/gld-2.21: warning: libgcc_s.so.1, needed by i386-pc-solaris2.11/amd64/libjava/.libs/libjvm.so, not found (try using -rpath or -rpath-link)
i386-pc-solaris2.11/amd64/libjava/.libs/libgcj.so.12: undefined reference to `_Unwind_GetIPInfo@GCC_4.2.0'
i386-pc-solaris2.11/amd64/libjava/.libs/libgcj.so.12: undefined reference to `_Unwind_GetTextRelBase@GCC_3.0'
i386-pc-solaris2.11/amd64/libjava/.libs/libgcj.so.12: undefined reference to `_Unwind_FindEnclosingFunction@GCC_3.3'
i386-pc-solaris2.11/amd64/libjava/.libs/libgcj.so.12: undefined reference to `_Unwind_GetDataRelBase@GCC_3.0'
i386-pc-solaris2.11/amd64/libjava/.libs/libgcj.so.12: undefined reference to `_Unwind_Backtrace@GCC_3.3'
collect2: ld returned 1 exit status

By e.g. setting LD_LIBRARY_PATH before the link, both the error went
away and the test worked.

The patch below is obvious after this.  At the same time, I noticed that
-lsocket isn't used anymore (ldd -u reports it as unused and the test
works without), so I'm removing it at the same time.

Bootstrapped without regressions (and now clean libjava testsuite
results for both ABIs) on i386-pc-solaris2.11.

Will commit to mainline and the 4.4 and 4.5 branches once {i386-pc,
sparc-sun}-solaris2.{8, 9, 10, 11} testing has completed.

	Rainer


2011-01-01  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* testsuite/libjava.jni/jni.exp (gcj_jni_get_cxxflags_invocation):
	Add -shared-libgcc to cxxflags for *-*-solaris*.
	Remove -lsocket.

diff -r 893bae7716b8 libjava/testsuite/libjava.jni/jni.exp
--- a/libjava/testsuite/libjava.jni/jni.exp	Sat Jan 01 23:04:06 2011 +0100
+++ b/libjava/testsuite/libjava.jni/jni.exp	Mon Jan 03 10:47:48 2011 +0100
@@ -274,8 +274,10 @@
     eval lappend cxxflags "-shared-libgcc -lgcj $libiconv"
   }
 
+  # Make sure libgcc unwinder is used on 64-bit Solaris 10+/x86 rather than
+  # the libc one.
   if { [istarget "*-*-solaris*"] } {
-    lappend cxxflags "-lsocket"
+    lappend cxxflags "-shared-libgcc"
   }
 
   return $cxxflags

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: Fix 64-bit PR16923 on Solaris 10+/x86
  2011-01-05 17:01 Fix 64-bit PR16923 on Solaris 10+/x86 Rainer Orth
@ 2013-01-08 11:41 ` gaurav.rustagi
  2013-01-08 13:37   ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: gaurav.rustagi @ 2013-01-08 11:41 UTC (permalink / raw)
  To: java-patches

Hi,

I am having a similar issue here. Please read the following.

I am getting a crash when a native exception through JNI is propagated to
Java. The source code is really simple and it just throws a native
exception. I think the process crashes when it tries to unwind the stack
after an exception is thrown. You can see the error below. One more thing,
it only happens when the native library is compiled on 64 bit arch, and it
does work successfully on 32 bit arch. I am using gcc compiler and stats are
mentioned below as well. Let me know if you need more information. One more
thing, this code works perfectly well in Linux systems and i could see one
compiler option "--disable-libunwind-exceptions" on Linux. Does this option
really play any role for these kind of exceptions ? Should we put this
option whiling building gcc compiler on Solaris box ? 

uname: SunOS
uname -m: i86pc

compiler info
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/export/home/gcc4/bin/../libexec/gcc/i386-pc-solaris2.10/4.6.3/lto-wrapper
Target: i386-pc-solaris2.10
Configured with: ../gcc-4.6.3/configure --prefix=/usr/local/gcc4
--enable-__cxa_atexit
Thread model: posix
gcc version 4.6.3 (GCC)


From Crash Report:
Stack: [0xfffffd7fffbff000,0xfffffd7fffe00000), sp=0xfffffd7fffdfe4d8, free
space=2045k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native
code)
C 0x00000000000129f5
C [libc.so.1+0xe08b9] _Unwind_RaiseException+0x46
C [libstdc++.so.6.0.16+0xf4a79] __cxa_throw+0x59
C [libtestjni.so+0x1d92] Java_testJava_TEST+0xca
j testJava.TEST()I+0
j testJava.main([Ljava/lang/StringV+14
v ~StubRoutines::call_stub
V [libjvm.so+0x401398]
V [libjvm.so+0x401618]
V [libjvm.so+0x4018dd]
V [libjvm.so+0x4e6414]
V [libjvm.so+0x4ef694]
C [java+0x3169] main+0x649
C [java+0x29cc] _PROCEDURE_LINKAGE_TABLE_+0x3e4

library dependencies :
SERVER:/$HOME/simpleJNITest$ldd libtestjni.so
libstdc++.so.6 => /usr/local/gcc4/lib/amd64/libstdc++.so.6
libm.so.2 => /lib/64/libm.so.2
libgcc_s.so.1 => /usr/local/gcc4/lib/amd64/libgcc_s.so.1
libc.so.1 => /lib/64/libc.so.1



--
View this message in context: http://gcc.1065356.n5.nabble.com/Fix-64-bit-PR16923-on-Solaris-10-x86-tp774103p902934.html
Sent from the gcc - java - patches mailing list archive at Nabble.com.

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

* Re: Fix 64-bit PR16923 on Solaris 10+/x86
  2013-01-08 11:41 ` gaurav.rustagi
@ 2013-01-08 13:37   ` Andrew Haley
  2013-01-10  8:33     ` gaurav.rustagi
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2013-01-08 13:37 UTC (permalink / raw)
  To: gaurav.rustagi; +Cc: java-patches

Hi,

On 01/08/2013 11:41 AM, gaurav.rustagi wrote:
> I am having a similar issue here. Please read the following.
> 
> I am getting a crash when a native exception through JNI is propagated to
> Java. The source code is really simple and it just throws a native
> exception. I think the process crashes when it tries to unwind the stack
> after an exception is thrown. You can see the error below. One more thing,
> it only happens when the native library is compiled on 64 bit arch, and it
> does work successfully on 32 bit arch. I am using gcc compiler and stats are
> mentioned below as well. Let me know if you need more information. One more
> thing, this code works perfectly well in Linux systems and i could see one
> compiler option "--disable-libunwind-exceptions" on Linux. Does this option
> really play any role for these kind of exceptions ? Should we put this
> option whiling building gcc compiler on Solaris box ? 

It's a bug in the unwinder in your libc.  You should try calling backtrace
from a segfault handler written in C.  This will tell you if the problem
is anything to do with libjava.

Andrew.

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

* Re: Fix 64-bit PR16923 on Solaris 10+/x86
  2013-01-08 13:37   ` Andrew Haley
@ 2013-01-10  8:33     ` gaurav.rustagi
  2013-01-10  9:56       ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: gaurav.rustagi @ 2013-01-10  8:33 UTC (permalink / raw)
  To: java-patches

Thanks Andrew.

How can we get rid of this error ? Is there some kind of patch available for
this bug ? If yes, how and where can we get that ?

Thanks again for your help.

Gaurav



--
View this message in context: http://gcc.1065356.n5.nabble.com/Fix-64-bit-PR16923-on-Solaris-10-x86-tp774103p903632.html
Sent from the gcc - java - patches mailing list archive at Nabble.com.

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

* Re: Fix 64-bit PR16923 on Solaris 10+/x86
  2013-01-10  8:33     ` gaurav.rustagi
@ 2013-01-10  9:56       ` Andrew Haley
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2013-01-10  9:56 UTC (permalink / raw)
  To: gaurav.rustagi; +Cc: java-patches

On 01/10/2013 08:32 AM, gaurav.rustagi wrote:
> How can we get rid of this error ? Is there some kind of patch available for
> this bug ? If yes, how and where can we get that ?

Sorry, I have no idea.  There's no solution I know except
to debug it.

Andrew.

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

end of thread, other threads:[~2013-01-10  9:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-05 17:01 Fix 64-bit PR16923 on Solaris 10+/x86 Rainer Orth
2013-01-08 11:41 ` gaurav.rustagi
2013-01-08 13:37   ` Andrew Haley
2013-01-10  8:33     ` gaurav.rustagi
2013-01-10  9:56       ` Andrew Haley

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).