google / google/sanitizers

sanitizers do not work when compile by android.mk, however is working well when compile by cmakelists.txt

Open
#987 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

**1. my phone is pixel with android 8.1**
**2. i use wrap.sh to setup sanitizers**
```
#!/system/bin/sh
HERE="$(cd "$(dirname "$0")" && pwd)"
export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
export LD_PRELOAD=$HERE/libclang_rt.asan-arm-android.so
"$@"
```

**3. when i config my CMakeLists.txt like this, it working well**
```
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
```

**4. copy `libclang_rt.asan-arm-android.so` from NDK fold to my project**

**4. sanitizers working well, when is run the bad code:**
```
int a[2] = {1, 0};
for (int i = 0; i < 1000; ++i) {
a[i];
}
int b=a[2];
```

```
08-01 08:49:04.134 6303-6303/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-01 08:49:04.135 6303-6303/? A/DEBUG: Build fingerprint: 'Android/aosp_sailfish/sailfish:8.1.0/OPM1.171019.021/chenwa07210144:userdebug/test-keys'
Revision: '0'
ABI: 'arm'
pid: 6287, tid: 6287, name: com.memoryfling >>> demo.qiu.liang.com.memoryfling <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
r0 00000000 r1 0000188f r2 00000006 r3 00000008
r4 0000188f r5 0000188f r6 ffbf526c r7 0000010c
r8 00000000 r9 ffbf5d58 sl ffbf5e70 fp ffbf5d18
ip ffbf5d30 sp ffbf5258 lr f4832bdf pc f482c5ec cpsr 200d0030
08-01 08:49:04.146 6303-6303/? A/DEBUG: backtrace:
#00 pc 0001a5ec /system/lib/libc.so (abort+63)
#01 pc 000a18b3 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libclang_rt.asan-arm-android.so
#02 pc 000a6449 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libclang_rt.asan-arm-android.so
#03 pc 0008ffc0 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libclang_rt.asan-arm-android.so
#04 pc 000912e0 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libclang_rt.asan-arm-android.so
#05 pc 00091f74 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libclang_rt.asan-arm-android.so (__asan_report_load4+68)
#06 pc 00000b17 /data/app/demo.qiu.liang.com.memoryfling-P7k1E3cKXQ4Y9LlhlhUBXw==/lib/arm/libnative-lib.so (Java_demo_qiu_liang_com_memoryfling_MainActivity_stringFromJNI+390)
```

**5. however, when i change to Android.mk, sanitizers not work, the bad code run, however crash not happen**
Android.mk
```
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := native-lib
LOCAL_SRC_FILES := $(LOCAL_PATH)/../cpp/native-lib.cpp

LOCAL_CFLAGS := -fsanitize=address -fno-omit-frame-pointer
LOCAL_LDFLAGS := -fsanitize=address
LOCAL_ARM_MODE := arm

LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)
```
Application.mk
```
APP_ABI := armeabi-v7a
```

**6. i also try `asan_device_setup`, it alway not work when compile by Android.mk**

there are many binary library compile by `Android.mk` in my project,so help me !!!!!

Contributor guide

Open the contributing guide

Research direction

Compare the Android.mk and Application.mk configuration with the working CMakeLists.txt flags, then review the wrap.sh and asan_device_setup steps. Reproduce the sample out-of-bounds access using the Android.mk build and verify that AddressSanitizer reports the failure as it does for the CMake build.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, c, cmake
Domain
build-system, mobile-dev, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.