Make use of the newly added thread-properties API (available since 31)
Side-effect change: set -fno-emulated-tls for lsan/asan libraries and skip their tests on pre-S Android.
Differential D85927
Enable LSAN for Android oontvoo on Aug 13 2020, 12:53 PM. Authored by
Details
Make use of the newly added thread-properties API (available since 31) Side-effect change: set -fno-emulated-tls for lsan/asan libraries and skip their tests on pre-S Android.
Diff Detail
Event TimelineComment Actions FYI https://reviews.llvm.org/D85930 moves standalone LSan on Android/aarch64 to the 64-bit allocator, I don't know if you care about this.
Comment Actions I think there needs to be something to disable automatic leak detection on exit on older platform, otherwise existing users of ASan will start getting false leak reports.
Comment Actions I'm not familiar with this. How would it change the way static and dynamic TLS are allocated on android? Specifically, would it still eventually go to the bionic allocator?
Comment Actions This change does not enable standalone LSan. It probably should, as a test vehicle if nothing else. See COMPILER_RT_HAS_LSAN. It would be great to have some testing, too. Unfortunately with the pandemic our testing rig is locked in the office and most of the devices fell off over time... There used to be aarch64 and arm testing steps here: It's pretty hard to setup, but could you check that check-asan check-lsan check-sanitizer pass both with old and new aosp images? I'm concerned about __lsan_disable which involves a thread-local variable built with -fno-emulated-tls and it's probably going to crash before Android Q. You can peek at the buildbot setup: https://github.com/llvm/llvm-zorg/blob/master/zorg/buildbot/builders/sanitizers/buildbot_android_functions.sh The interesting parts are configure_android and test_arch_on_device. Any plans to add hwasan+lsan support? Android is generally moving in that direction, and both standalone lsan and asan+lsan are unlikely to see a lot of use.
Comment Actions Done
Maybe moving the check for existence of the new API before the call to __lsan_disable would prevent the crash? (because it wouldn't to that) ?
I've grabbed a pixel3 test phone from the office. Is there a one-step setup script that I could run and point it at the device? Or would I have to set it up manually ?
Yes, not sure where to start. :-) Any pointers? (I was under the impression it'd "just work" ... what's still missing? )
Comment Actions
Try this one, it's the same script that runs on the buildbot. Be careful, it can mess up anything in the current directory (it expect source/build trees there for a possible incremental run).
There are a few small things, search for "lsan" in compiler-rt/lib/asan. The main one is an allocator interface for scanning, and a few hooks for initializing lsan and passing the runtime flags. Comment Actions Avoid accessing TLS variables for android when the thread-properties API is not present. Comment Actions Updated a few tests to work on Android. @eugenis: I think this is ready to be reviewed now.
i686:
(Note: The i686 needs some fix in Bionic or it'd sigsev https://android-review.googlesource.com/c/platform/bionic/+/1419435)
Comment Actions updated per review comments
Comment Actions Updated diff
Comment Actions updated diff
Comment Actions LGTM with 1 comment
Comment Actions This caused a build break in our compiler-rt build for Android: use of undeclared identifier '__interceptor_memalign' The name is referenced from https://github.com/llvm/llvm-project/blob/85e578f53ad1ba21771470dc9516068a259d29cf/compiler-rt/lib/asan/asan_malloc_linux.cpp#L274 but the definition is no longer provided now that SANITIZER_INTERCEPT_MEMALIGN has excluded Android. For anyone playing along at home: this landed in https://github.com/llvm/llvm-project/commit/a2291a58bf1c860d026581fee6fe96019dc25440, not sure why Phab didn't automatically mention that here. Comment Actions And later we also get use of undeclared identifier 'dl_iterate_phdr' in (EDIT:) lsan_common_linux.cpp. We compile for API 16, which doesn't implement that. Comment Actions Thanks for the report! Are you also building with API 16? (From your second comment)
I landed it with git push instead of arc land ... maybe that's the issue? Comment Actions Included the fix now. memalign is callled during lsan init for Android, causing the "ENSURE_LSAN_INITED" check and the stack-trace to fail.
|
Why is android special here?