From 4e4fa629853bfdda8fba83ade4e52bce60ca899d Mon Sep 17 00:00:00 2001 From: atsushieno Date: Wed, 25 May 2022 18:46:02 +0900 Subject: [PATCH] Add ASAN wrap.sh workaround. It is regarding https://github.com/android/ndk/issues/933 --- asan-wrap-bugfixed.sh | 30 ++++++++++++++++++++++++++++++ docs/HACKING.md | 2 +- setup-asan-for-debugging.sh | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 asan-wrap-bugfixed.sh diff --git a/asan-wrap-bugfixed.sh b/asan-wrap-bugfixed.sh new file mode 100644 index 00000000..5f8a91f6 --- /dev/null +++ b/asan-wrap-bugfixed.sh @@ -0,0 +1,30 @@ +#!/system/bin/sh + +# It is taken from https://github.com/android/ndk/issues/933 + +HERE=$(cd "$(dirname "$0")" && pwd) + +cmd=$1 +shift + +export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1 +ASAN_LIB=$(ls "$HERE"/libclang_rt.asan-*-android.so) +if [ -f "$HERE/libc++_shared.so" ]; then + # Workaround for https://github.com/android-ndk/ndk/issues/988. + export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so" +else + export LD_PRELOAD="$ASAN_LIB" +fi + +os_version=$(getprop ro.build.version.sdk) + +if [ "$os_version" -eq "27" ]; then + cmd="$cmd -Xrunjdwp:transport=dt_android_adb,suspend=n,server=y -Xcompiler-option --debuggable $@" +elif [ "$os_version" -eq "28" ]; then + cmd="$cmd -XjdwpProvider:adbconnection -XjdwpOptions:suspend=n,server=y -Xcompiler-option --debuggable $@" +else + cmd="$cmd -XjdwpProvider:adbconnection -XjdwpOptions:suspend=n,server=y $@" +fi + +exec $cmd + diff --git a/docs/HACKING.md b/docs/HACKING.md index d8839bf9..722a4787 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -59,7 +59,7 @@ To enable asan in this project, there are three things to do: - In the top-level `build.gradle.kts`, change `enable_asan` value to `true`. It will delegate the option to cmake as well as enable the ASAN settings in the library modules as well as sample apps. - In your app module (or ours outside this repo e.g. `aap-juce-plugin-host/app`): - Similarly to `./setup-asan-for-debugging.sh` in this repo, you will have to copy ASAN libraries and `wrap.sh` into the app module. For more details, see [NDK documentation](https://developer.android.com/ndk/guides/asan). - - **WARNING**: as of May 2022 there is a blocking NDK bug that prevents you from debugging ASAN-enabled code. See [this issue](https://github.com/android/ndk/issues/933) and find the latest script fix. + - **WARNING**: as of May 2022 there is a blocking NDK bug that prevents you from debugging ASAN-enabled code. See [this issue](https://github.com/android/ndk/issues/933) and find the latest script fix. We now have a temporary fix and actually use the script from there, but as it often happens, such a stale file could lead to future issues when the issue is fixed in the NDK upgrades. It should be removed whenever the issue goes away. - Add `android { packagingOptions { jniLibs { useLegacyPackaging = true } } }` (you would most likely have to copy "part of" this script in your existing build script e.g. only within `androoid { ... }` part) - Add `android:extractNativeLibs='true'` on `` element in `AndroidManifest.xml` diff --git a/setup-asan-for-debugging.sh b/setup-asan-for-debugging.sh index f22db468..b90c25c5 100755 --- a/setup-asan-for-debugging.sh +++ b/setup-asan-for-debugging.sh @@ -31,7 +31,7 @@ for sample in "${ALL_APPS[@]}"; do mkdir -p $SAMPLE/jniLibs/$a ; # This is causing unresponsive debugger. Do not use it. Load asan so at using System.loadLibrary() instead. mkdir -p $SAMPLE_RES/$a - cp -R $ANDROID_NDK_PATH/wrap.sh/asan.sh $SAMPLE_RES/$a/wrap.sh + cp -R asan-wrap-bugfixed.sh $SAMPLE_RES/$a/wrap.sh dos2unix $SAMPLE_RES/$a/wrap.sh done