Skip to content

Commit

Permalink
Add ASAN wrap.sh workaround.
Browse files Browse the repository at this point in the history
It is regarding android/ndk#933
  • Loading branch information
atsushieno committed May 25, 2022
1 parent 581ea25 commit 4e4fa62
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
30 changes: 30 additions & 0 deletions asan-wrap-bugfixed.sh
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion docs/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<application>` element in `AndroidManifest.xml`

Expand Down
2 changes: 1 addition & 1 deletion setup-asan-for-debugging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4e4fa62

Please sign in to comment.