Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ramosian-glider opened this issue Aug 31, 2015 · 11 comments
Closed

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

ramosian-glider opened this issue Aug 31, 2015 · 11 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 271

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.


Reported by wtorpey on 2014-02-27 21:56:37

@ramosian-glider
Copy link
Member Author

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)

Reported by konstantin.s.serebryany on 2014-02-28 07:50:50

@ramosian-glider
Copy link
Member Author

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.


Reported by wtorpey on 2014-02-28 14:20:02

@ramosian-glider
Copy link
Member Author

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!



Reported by wtorpey on 2014-03-07 17:59:34

@ramosian-glider
Copy link
Member Author

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

Reported by wtorpey on 2014-03-07 19:26:56

@ramosian-glider
Copy link
Member Author

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

Reported by tetra2005 on 2014-04-01 16:33:44

@ramosian-glider
Copy link
Member Author

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!

Reported by wtorpey on 2014-04-13 14:10:20

@ramosian-glider
Copy link
Member Author

Perhaps close as not-a-bug?

Reported by tetra2005 on 2015-04-12 11:55:07

@ramosian-glider
Copy link
Member Author

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.

Reported by wtorpey on 2015-04-12 14:56:39

@ramosian-glider
Copy link
Member Author

Reported by ramosian.glider on 2015-07-30 09:05:32

  • Labels added: ProjectAddressSanitizer

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:06:56

@ramosian-glider
Copy link
Member Author

Cool, closing then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant