Jeff-Lewis / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

cannot use ASAN w/shared-library code (JVM, JNI) #271

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile so w/-fsanitize=address
2. Run code under JVM 
3.

What is the expected output? What do you see instead?
Expected it to work ;-)  What I got instead is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
/home/btorpey/install/bustalk/0.0.0/abim/lib/libnsbjni.so.0.0.0: 
/home/btorpey/install/Transact/lib/mama/libTrAdapter.so.0: undefined symbol: 
__asan_option_detect_stack_use_after_return
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at NSBInterface.<clinit>(NSBInterface.java:82)
    at Route.main(Route.java:227)
[Loaded java.lang.Shutdown from /home/btorpey/jdk1.6.0_21/jre/lib/rt.jar]
[Loaded java.lang.Shutdown$Lock from /home/btorpey/jdk1.6.0_21/jre/lib/rt.jar]
/home/btorpey/btlogs/abim $ 

What version of the product are you using? On what operating system?
clang 3.4, CentOS 6.5

Please provide any additional information below.
Would like to know how to inject ASAN code at runtime.  Rebuilding the JVM is 
not really feasible.

Original issue reported on code.google.com by wtor...@gmail.com on 27 Feb 2014 at 9:56

GoogleCodeExporter commented 9 years ago
a relevant link: https://code.google.com/p/address-sanitizer/wiki/AsanAsDso
You may try to LD_PRELOAD asan built as a shared library, but in that case 
the warranty is void. You may also try to build the jvm launcher with asan
(AFIACT, the main jvm is a .so linked to a tiny launcher program, but I am not 
an expert there)

Original comment by konstant...@gmail.com on 28 Feb 2014 at 7:50

GoogleCodeExporter commented 9 years ago
Thanks!  I had seen wiki page, and will be following up w/gcc version of ASAN 
as a start, since that at least should be supported.

I'm curious if you expect the current limitation to change, and if so when?  As 
you point out, even the JVM is largely just a bunch of shared objects, and that 
technique of putting functionality into shared objects is pretty common on a 
lot of projects I work on, which is not surprising given that it gives a lot of 
flexibility.

Original comment by wtor...@gmail.com on 28 Feb 2014 at 2:20

GoogleCodeExporter commented 9 years ago
Still having problems, but dont know if they are caused by jvm, our (jni) code 
or some interaction w/jvm.

jvm segv's w/following:

[Loaded java.io.PushbackInputStream from 
/home/btorpey/jdk1.6.0_21/jre/lib/rt.jar]
[Loaded java.util.zip.Checksum from /home/btorpey/jdk1.6.0_21/jre/lib/rt.jar]
[Loaded java.util.zip.CRC32 from /home/btorpey/jdk1.6.0_21/jre/lib/rt.jar]
ASAN:SIGSEGV
=================================================================
==6168== ERROR: AddressSanitizer: SEGV on unknown address 0x7f7293cf3f80 (pc 
0x7f729304320d sp 0x7f72928f2390 bp 0x7f72928f23f0 T1)
AddressSanitizer can not provide additional info.
    #0 0x7f729304320c (/home/btorpey/jdk1.6.0_21/jre/lib/amd64/server/libjvm.so+0x44920c)
    #1 0x7f7292172401 (/home/btorpey/jdk1.6.0_21/jre/lib/amd64/libzip.so+0x3401)
    #2 0x7f728f1d54c5 (+0x664c5)
Thread T1 created by T0 here:
    #0 0x7f7293d04c2b (/usr/local/lib64/libasan.so.0.0.0+0xac2b)
    #1 0x400058ea (/home/btorpey/jdk1.6.0_21/bin/java+0x400058ea)
==6168== ABORTING

Curious if anyone has any suggestions, or knows of successful attempt(s) to use 
ASAN w/JNI code running in JVM.

TIA!

Original comment by wtor...@gmail.com on 7 Mar 2014 at 5:59

GoogleCodeExporter commented 9 years ago
Never mind -- the problem was in some scripts that launch the jvm.  Launching 
from the command line works like a charm!

Original comment by wtor...@gmail.com on 7 Mar 2014 at 7:26

GoogleCodeExporter commented 9 years ago
FYI we've added support for this in trunk Clang/compiler-rt (you'll need to 
cmake with -DCOMPILER_RT_BUILD_SHARED_ASAN=ON - see 
http://code.google.com/p/address-sanitizer/wiki/AsanAsDso for more details).

Original comment by tetra2...@gmail.com on 1 Apr 2014 at 4:33

GoogleCodeExporter commented 9 years ago
Thanks for the heads-up!  I've been successfully using AddressSanitizer with 
gcc for a while now, and it works like a charm (even with the JVM).  In fact, 
it helped find a bug that would have been very difficult to identify -- I wrote 
a little about the process on my blog 
(http://btorpey.github.io/blog/2014/03/27/using-clangs-address-sanitizer/).

I'm also using clang for static analysis, but so far we're still building 
executables w/gcc.

Again, thanks for putting such a terrific tool out there!

Original comment by wtor...@gmail.com on 13 Apr 2014 at 2:10

GoogleCodeExporter commented 9 years ago
Perhaps close as not-a-bug?

Original comment by tetra2...@gmail.com on 12 Apr 2015 at 11:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I don't know if this is a bug or not, but fwiw I've managed to work around this 
issue by creating a C++ executable to invoke JVM using JNI, which allows me to 
compile and link asan statically using clang, as opposed to gcc.

With that configuration asan works like a charm, and I don't see these spurious 
crashes.

Thanks again.

Original comment by wtor...@gmail.com on 12 Apr 2015 at 2:56

GoogleCodeExporter commented 9 years ago

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:05

GoogleCodeExporter commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:06