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

Leak sanitizer support for Android on arm64 #379

Open
ramosian-glider opened this issue Sep 1, 2015 · 21 comments
Open

Leak sanitizer support for Android on arm64 #379

ramosian-glider opened this issue Sep 1, 2015 · 21 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 379

This is for porting leak sanitizer for Android with arm64. It seems 32bit arm had issues
documented at https://code.google.com/p/address-sanitizer/issues/detail?id=294&can=1&q=leak%20sanitizer&colspec=ID%20Type%20Status%20Priority%20OpSys%20Owner%20Summary.

  But is there any plan to port for arm64, now that there are 64 bit processors running
Android.

Reported by vairavans on 2015-03-06 23:47:18

@ramosian-glider
Copy link
Member Author

We don't have plans yet, but it's in our radar. We need to make ARM stable runtime first.

Reported by rengolin on 2015-03-07 00:52:22

@ramosian-glider
Copy link
Member Author

Thanks for the update. Do you have any recommendations in the short term? I have tried
using Valgrind for Android but the applications are practically slow that its hard
to execute any use case.

Reported by vairavans on 2015-03-07 02:45:42

@ramosian-glider
Copy link
Member Author

There are several problems here, actually. 
1. Make lsan work on AArch64 Linux. I don't know the status of this, but it should
be easy to accomplish. 
2. Make lsan work on Android, x86_64 and AArch64.

>> Do you have any recommendations in the short term?
Nope. Unless of course you want to help us with the development. :( / :) 

Reported by konstantin.s.serebryany on 2015-03-07 02:52:48

@ramosian-glider
Copy link
Member Author

Sure, i can give it a shot. Btw, android apps don't really have an exit unlike a typical
c program with a main. In c terms, android apps have a kind of an infinite loop which
doesn't quit. Would leak sanitizer still work in such cases?

Reported by vairavans on 2015-03-07 03:45:46

@ramosian-glider
Copy link
Member Author

Right now we can call leak checking only once per process, 
but this does not necessary has to be done at the very end.  

From lsan_interface.h:
  // Calling this function makes LSan enter the leak checking phase immediately.
  // Use this if normal end-of-process leak checking happens too late (e.g. if
  // you have intentional memory leaks in your shutdown code). Calling this
  // function overrides end-of-process leak checking; it must be called at
  // most once per process. This function will terminate the process if there
  // are memory leaks and the exit_code flag is non-zero.
  void __lsan_do_leak_check();

Reported by konstantin.s.serebryany on 2015-03-07 05:36:25

@ramosian-glider
Copy link
Member Author

For the record, I've recently added a new interface function which allows multiple leak
checks:

  // Check for leaks now. Returns zero if no leaks have been found or if leak
  // detection is disabled, non-zero otherwise.
  // This function may be called repeatedly, e.g. to periodically check a
  // long-running process. It prints a leak report if appropriate, but does not
  // terminate the process. It does not affect the behavior of
  // __lsan_do_leak_check() or the end-of-process leak check, and is not
  // affected by them.
  int __lsan_do_recoverable_leak_check();

> 1. Make lsan work on AArch64 Linux. I don't know the status of this, but it should
be easy to accomplish. 

Recently this was done for MIPS. I invite you (vairavans) to take a look at those patches
to get an idea of the scope of work. Basically you will have to:
- port stoptheworld (reimplementing internal_clone() will probably be the bulk of this),
- port the TLS discovery code,
- pick up a few platform-dependent bits and pieces in lsan_common.

Reported by earthdok@google.com on 2015-05-22 15:20:49

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

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

  • Labels added: ProjectAddressSanitizer

@polishcode
Copy link

polishcode commented Mar 30, 2017

@ramosian-glider

I am currently trying to use described functionality in my android library:

#include <sanitizer/lsan_interface.h>
__lsan_do_leak_check();
__lsan_do_recoverable_leak_check();

However, the linking stage fails:
xxxxx.cpp:481: error: undefined reference to '__lsan_do_leak_check'

How can I link from Android.mk to implementation of that function?

[edit]

In fact, I wonder what is the current status of Leak sanitizer support for Android. There is couple of information scattered thorough the wiki/Internet when regarding debugging applications/so libraries, but no concise description. E.g.:

  • it works only on 64-bit architectures
  • it is enabled by default in a standard address sanitizer run
  • address sanitizer works only on following Android architectures: armeabi armeabi-v7a x86
  • leak sanitizer can be triggered to dump info via __lsan_do_leak_check()/ __lsan_do_recoverable_leak_check() - how can i trigger that for android application?

I managed to compile my library with address sanitizer support on armeabi, armeabi-v7a, arm64-v8a, x86; build for x86_64 failed.

[edit2]

Upon running my library for arm64-v8a on an emulator it crashes with:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libclang_rt.asan-aarch64-android.so"
therefore I could not find any working setup that provides working leak sanitizer for Android.

@eugenis
Copy link
Contributor

eugenis commented Mar 30, 2017

LSan does not work on Android at the moment. I'm not sure how much work is left, probably a subset of things listed in this comment:
#379 (comment)

Currently LSan is disabled for Android in the upstream (llvm / cmake) build system, and it is not included in the android prebuilt libraries (the ones you find in the NDK) either.

Regarding your "dlopen failed" error, for this library to appear on device (or emulator) you'd need to run asan_device_setup as per ASan documentation. And, again, there is no LSan there.

@polishcode
Copy link

Thank you for your comment @eugenis.
I am currently stuck with a memory-related issue in my NDK component on Android. I hoped I could resolve that with Leak Sanitizer. Are you aware of any other tools that might be helpful in this case?

@eugenis
Copy link
Contributor

eugenis commented Mar 31, 2017 via email

@chefmax
Copy link

chefmax commented Mar 31, 2017

Just curious, are there any technical blockers for enabling LSan on Android Aarch64? At a first glance I can see TLS supporting caveats, but for beginning we can just disable thread local caches in LSan runtime and exclude static TLS from root set (I just don't know how Android libc implements it).

@eugenis
Copy link
Contributor

eugenis commented Mar 31, 2017 via email

@morehouse
Copy link
Contributor

Ping. Any progress on this since last year?

@eugenis
Copy link
Contributor

eugenis commented Jun 8, 2018

Nope.

@cybertk
Copy link

cybertk commented Sep 4, 2018

==30805==AddressSanitizer: detect_leaks is not supported on this platform.

LSAN still does not work for aarch64-clang on Android 8.0

@zienn
Copy link

zienn commented Aug 27, 2021

Any progress on this over the last three years?

@oontvoo
Copy link
Member

oontvoo commented Aug 27, 2021 via email

@hua-hua-lin
Copy link

hua-hua-lin commented Jul 5, 2022

ASAN+LSAN should work for Android 30+ (aarch64 and x86_64) (no HWASAN+LSAN yet tho)

On Fri, Aug 27, 2021, 4:40 AM Tianqi Xu @.***> wrote: Any progress on this over the last three years? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#379 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANONE6NKFML67VR32D46JLT65FOPANCNFSM4DFZ2PZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

  • Have you tested it? I tested it on NDK23, the Android API 31 version, and it didn't pass.
    $ ${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android31-clang++ -fsanitize=address -O0 -fno-omit-frame-pointer -g -pie -fPIE sample.cpp
    $ adb push a.out /data/local/tmp/lkk/ && adb shell "cd /data/local/tmp/lkk/ && LD_LIBRARY_PATH=/data/local/tmp/lkk/arm64-v8a/:$LD_LIBRARY_PATH ASAN_OPTIONS=detect_leaks=1 /data/local/tmp/lkk/a.out"
    WARNING: linker: Warning: "/data/local/tmp/lkk/arm64-v8a/libclang_rt.asan-aarch64-android.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
    WARNING: linker: Warning: "/data/local/tmp/lkk/arm64-v8a/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
    

@zhangjanet
Copy link

I tried the NDK25C, and the error
AddressSanitizer: detect_leaks is not supported on this platform. Aborted was reported.

@20083017
Copy link

ASAN+LSAN should work for Android 30+ (aarch64 and x86_64) (no HWASAN+LSAN yet tho)

On Fri, Aug 27, 2021, 4:40 AM Tianqi Xu @.***> wrote: Any progress on this over the last three years? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#379 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANONE6NKFML67VR32D46JLT65FOPANCNFSM4DFZ2PZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

seems not working for me~

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