google / sanitizers

AddressSanitizer, ThreadSanitizer, MemorySanitizer
Other
11.5k stars 1.04k forks source link

Leak sanitizer support for Android on arm64 #379

Open ramosian-glider opened 9 years ago

ramosian-glider commented 9 years ago

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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

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

polishcode commented 7 years ago

@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.:

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 commented 7 years ago

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: https://github.com/google/sanitizers/issues/379#issuecomment-136551038

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 commented 7 years ago

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 commented 7 years ago

Valgrind has some sort of memory profiler (massif). I don't know how well it works on android.

On Thu, Mar 30, 2017 at 10:04 PM, Piotr notifications@github.com wrote:

Thank you for your comment @eugenis https://github.com/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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/sanitizers/issues/379#issuecomment-290616742, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZuSh_xO0lMlu_RT1-j4NjS5dNVWhMVks5rrIlvgaJpZM4MudPz .

chefmax commented 7 years ago

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 commented 7 years ago

No blockers. It should be quite easy, we just never had time to finish the job.

TLS implementation is different from glibc, of course, but it is quite simple. Excluding it from root set would create false positive reports though.

The fact that android apps never finish normally (they catch SIGKILL instead) means the will be no automatic leak report, but the tool would still be usable for standalone executables and through __lsan_do_leak_check() interface.

On Fri, Mar 31, 2017 at 3:50 PM, chefmax notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/sanitizers/issues/379#issuecomment-290850256, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZuSgzREm-JrFPxGj6zK-MQlhKakmOJks5rrYMogaJpZM4MudPz .

morehouse commented 6 years ago

Ping. Any progress on this since last year?

eugenis commented 6 years ago

Nope.

cybertk commented 6 years ago

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

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

zienn commented 3 years ago

Any progress on this over the last three years?

oontvoo commented 3 years ago

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 https://github.com/google/sanitizers/issues/379#issuecomment-907033108, 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.

hunter-kk commented 2 years ago

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.

zhangjanet commented 1 year ago

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

20083017 commented 8 months ago

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~

jimblackler commented 4 months ago

I also get "detect_leaks is not supported on this platform". Any suggestions?