Seg Fault when loading library with links to Root libs

Hello Rooters,

I was trying to invoke some Root functions from within java using JNI. For that I have created a shared library that I load inside java. All seemed alright besides the fact that I get a random segmentation fault that stops the JVM after the program has been running for a while.

Trying to narrow down the cause I have created a dummy C++ library that doesn’t do much except declaring the functions I want to use. Here comes the strange thing. If I do

g++ -fPIC -I/usr/include/root -L/usr/lib/root -lMathCore -lgcj myCode.cpp -shared -o libMyLib.so
I can reproduce the random segFault

removing -lMathCore the program runs forever.

I’m running root 5.18 on ubuntu 8.10 installed from the repositories.

Thanks in advance for any insight.[/code]

Hi,

What does myCode.cpp do? Did you trying using valgrind to pinpoint the cause of the crash?

Cheers,
Philippe.

[quote=“pcanal”]
What does myCode.cpp do? Did you trying using valgrind to pinpoint the cause of the crash?[/quote]

Hi,

As I said the code I’m using is a dummy code that doesn’t do anything. It is enough that the lib link to a ROOT lib is loaded to cause the segFault.

Valgrind doesn’t seem to give me any useful info since the ROOT libs are not compiled with debug flags. Running java with -Xcheck:jni I get:

 *** Break *** segmentation violation
Warning: SIGINT handler expected:libjvm.so+0x271d00  found:0x00000001
Signal Handlers:
SIGSEGV: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGBUS: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGFPE: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGPIPE: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGXFSZ: [libjvm.so+0x2701c0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGILL: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x26fb70], sa_mask[0]=0x00000000, sa_flags=0x10000004
SIGHUP: [libjvm.so+0x271d00], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGINT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGTERM: [libjvm.so+0x271d00], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGQUIT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
Warning: SIGQUIT handler expected:libjvm.so+0x271d00  found:0x00000001
Signal Handlers:
SIGSEGV: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGBUS: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGFPE: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGPIPE: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGXFSZ: [libjvm.so+0x2701c0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGILL: [libCore.so.5.18+0x1ec5e0], sa_mask[0]=0x00000000, sa_flags=0x10000000
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x26fb70], sa_mask[0]=0x00000000, sa_flags=0x10000004
SIGHUP: [libjvm.so+0x271d00], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGINT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGTERM: [libjvm.so+0x271d00], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGQUIT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
(no debugging symbols found)
Attaching to program: /proc/20302/exe, process 20302
[Thread debugging using libthread_db enabled]

I have run some more tests and it appears that the problem is linked to the fact that the java code is running more that one thread… I mean when I run the code with just one thread it seems ok or at least it takes longer to happen. So it might not linked to ROOT after all.

I’m sorry I’m vague in the clues that I’m giving but I’m new to java and this is my first experiment with JNI. So I haven’t figure out how to debug this in a proper way.

[/list]

I think that it all boils down to:

i.e libCore implements signal handlers that override those of java. Is there a way to not include libCore when linking agains LibMathCore and libHist?

Just to let you know that this problem is easily solved doing:

export LD_PRELOAD=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/libjsig.so ; jni_application.

which does the proper signal chainning.

Cheers.

[quote]i.e libCore implements signal handlers that override those of java. Is there a way to not include libCore when linking agains LibMathCore and libHist?[/quote]libHist requires libCore. libMathCore does not. There is an API to remove the signal handler than ROOT install.

Cheers,
Philippe.

For people finding this forum, the relevant function is:

gSystem->ResetSignals();