Skip to content

Commit

Permalink
first round of ASan
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 2, 2024
1 parent d650fa1 commit 8e7dc9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ add_library(${CMAKE_PROJECT_NAME} SHARED app.cpp)
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME} droidboot_gui)
target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize-recover=address)
Binary file not shown.
26 changes: 26 additions & 0 deletions app/src/main/resources/lib/arm64-v8a/wrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/system/bin/sh
HERE=$(cd "$(dirname "$0")" && pwd)
cmd=$1
shift
# This must be called *before* `LD_PRELOAD` is set. Otherwise, if this is a 32-
# bit app running on a 64-bit device, the 64-bit getprop will fail to load
# because it will preload a 32-bit ASan runtime.
# https://github.com/android/ndk/issues/1744
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
#export ASAN_OPTIONS=log_to_syslog=true,allow_user_segv_handler=1,detect_stack_use_after_return=true,check_initialization_order=true,halt_on_error=false
export ASAN_OPTIONS=log_to_syslog=true
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
exec $cmd

0 comments on commit 8e7dc9c

Please sign in to comment.