-
Notifications
You must be signed in to change notification settings - Fork 263
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
ubsan support #527
Comments
You can use UBSan. Surprisingly, it can not be used in combination with ASan, because ASan runtime library in the NDK does not include the necessary code. We will fix this in the future. For now, you can use UBSan on its own, by building with -fsanitize=undefined (or subset of it, see [1]) and then manually adding libclang_rt.ubsan_standalone-${arch}-android.so to the link command line and to the apk native library directory. UBSan does not need wrap.sh. Other sanitizers won't work out of the box. [1] https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#id4 |
Thanks for your help. I already added "LOCAL_CFLAGS += -fsanitize=undefined" and "LOCAL_LDFLAGS += -fsanitze=undefined" in Android.mk, but nothing happened during the apk building. Although I add the ubsan lib dependency at build phase and copy the lib into apk native lib directory. I can't find any log about ubsan when the app run. Could you give me more detailed about how to add ubsan in building phase? |
I'm not sure what's wrong. I took hello-jni sample from https://github.com/googlesamples/android-ndk; it's using cmake, so adding something like this works: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") target_link_libraries(hello-jni Then you also need to add the library to the apk, of course. And the snippet above does not work with multiple ABIs. This is bug in Clang that you need to do most of this. The library should be linked automatically with -fsanitize=undefined in linker flags, we'll fix this some day. |
Yes, I added your command into hello-jni sample and ubsan can work. However, I added similar command into Android.mk, the linker always showed undefined reference to '__ubsan_handle_type_mismatch'. I tried add the lib name for LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES, but still failed... |
Sorry, no idea. Must be some quirk of Android.mk. Try checking that the library appears on the link command line. |
I changed the LOCAL_CFLAGS from '-fsanitize=undifined' to '-fsanitize=sign-integer-overflow,integer-divide-by-zero',and the linker didn't hint that '__ubsan_handle_type_mismatch' undefined, instead , showed other simbols undefined, as followed: and I added all the other checks listed in undefinedBehaviorSanitizer#Docs, but still showed them. |
The Clang driver isn't linking the ubsan runtime. I can't see why it isn't from the driver source. |
Because this: It simply never links shared ubsan runtime. I intend to fix it soon-ish. |
|
Retitling this bug to cover just ubsan. If there are other tools people want, please open separate bugs. |
Looks like this is working once we get the next clang update. The compiler team found a miscompile in the one we thought we'd have in time for r17 beta 1 and I don't know the status of the respin. I'll check up on that, but I usually don't like taking compiler updates after beta 1. I should note that "working" means that ubsan works if you pass |
Made it into r17 beta 1 after all. |
Test: None, markdown only Bug: android/ndk#527 Change-Id: I79719566ddc01f18f07a0c03b6e190dabe32a10a (cherry picked from commit dc7f8c448aa89817abfea302bfc1c76502cd06d0)
hi all, I want to integrate sanitizer tools into android apk to check native code. Currently i can run the app that intergrated ASAN on android Oreo phone. But, for other sanitizer tools, such as USAN or TSAN etc, I can not catch any any crached info that trapped by sanitizer. Besides, the info about android sanitizer are varied on web. So could you pls. tell me is there any other sanitizer tools supported on android? and how to integrate them? Thx!
BRs,
newjor
The text was updated successfully, but these errors were encountered: