Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]wrap.sh LD_PRELOAD and java debug support conflict #1744

Closed
xiaoyur347 opened this issue Aug 4, 2022 · 1 comment
Closed

[BUG]wrap.sh LD_PRELOAD and java debug support conflict #1744

xiaoyur347 opened this issue Aug 4, 2022 · 1 comment
Assignees
Labels

Comments

@xiaoyur347
Copy link

xiaoyur347 commented Aug 4, 2022

Description

Background:
Android ndk r25 fixes Issue 933: Updated reference ASan wrap.sh to support attaching the Java debugger.

Current wrap.sh:

#!/system/bin/sh
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

Problem:
LD_PRELOAD should be put just before 'exec' command to make sure only the app has the LD_PRELOAD env.
But now, getprop is also putted with LD_PRELOAD env.
Error message:
F libc : CANNOT LINK EXECUTABLE "getprop": "/data/app/xxx/lib/arm/libclang_rt.asan-arm-android.so" is 32-bit instead of 64-bit

Suggestion:

#!/system/bin/sh
HERE=$(cd "$(dirname "$0")" && pwd)

cmd=$1
shift

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=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

exec $cmd

Affected versions

r25

Canary version

No response

Host OS

Linux

Host OS version

android

Affected ABIs

armeabi-v7a

Build system

CMake

Other build system

No response

minSdkVersion

14

Device API level

No response

@xiaoyur347 xiaoyur347 added the bug label Aug 4, 2022
@DanAlbert
Copy link
Member

Thanks, applied your patch: https://android-review.googlesource.com/c/platform/ndk/+/2175186. Will cherry-pick to r25b.

@DanAlbert DanAlbert self-assigned this Aug 15, 2022
osspop pushed a commit to osspop/android-ndk that referenced this issue Jan 17, 2023
Bug: android/ndk#1744
Test: User tested and sent the patch
Change-Id: I193500856b8d2540eb2fdc50e3c6848941dca3b0
osspop pushed a commit to osspop/android-ndk that referenced this issue Jan 17, 2023
Bug: android/ndk#1744
Test: User tested and sent the patch
Change-Id: I193500856b8d2540eb2fdc50e3c6848941dca3b0
(cherry picked from commit 12414a4)
Merged-In: I193500856b8d2540eb2fdc50e3c6848941dca3b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Merged
Development

No branches or pull requests

2 participants