我正在尝试使用此处描述的地址清理程序(使用 clang)构建我的应用程序(https://github.com/google/sanitizers/wiki/AddressSanitizer https://github.com/google/sanitizers/wiki/AddressSanitizer,更准确地说在这里:https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid),但我很难理解整个过程,尤其是使用 gradle。
看起来至少有 3 种方法可以启用它:
1°) 在第一个链接之后,t 表示您所要做的就是这样做:
2°)在第二个链接之后,似乎你必须这样做:
- 与第一个相同
- root 设备然后通过 adb 运行 asan_device_setup
- add a
LD_PRELOAD=libclang_rt.asan-arm-android.so
某处?我想它应该放在 gradle externalNativeBuild 的“参数”部分?但是应用程序在哪里可以找到这个库呢?我必须自己链接吗?或者它已经在设备上的某个地方了?
3°)我还找到了一种“新”的方法,它不需要根访问(确实如此,但这是一个错误,需要在某些时候纠正):
https://virtualrealitypop.com/oreo-ndk-secrets-7d075a9b084 https://virtualrealitypop.com/oreo-ndk-secrets-7d075a9b084
此方法实际上执行第一点和第二点中所做的操作,并通过启动 shell 脚本来运行应用程序,该脚本导出一些值以便 asan 工作。
就我的调查而言,我对在我的 root 模拟器上运行完全清理的应用程序(带有静态链接库)的正确方法有点困惑。
我走得更远的是实际构建和启动应用程序(使用 2°),但没有指定 LD_PRELOAD 标志),但应用程序因某些eglMakeCurrent函数中的容器溢出而崩溃,而该函数甚至不是我的代码的一部分,并且我没有得到任何堆栈:
02-19 16:26:21.553 28771-28789/com.mycompany.myapp I/zygote: Background concurrent copying GC freed 10159(1175KB) AllocSpace objects, 12(304KB) LOS objects, 50% free, 2MB/4MB, paused 144.861ms total 1.252s
[ 02-19 16:26:21.554 28771:28956 I/ ]
=================================================================
[ 02-19 16:26:21.554 28771:28956 I/ ]
[ 02-19 16:26:21.557 28771:28956 I/ ]
[ 02-19 16:26:21.563 28771:28956 I/ ]
==28771==ERROR: AddressSanitizer: container-overflow on address 0xa136e990 at pc 0xa49849e2 bp 0x82e60558 sp 0x82e60128
[ 02-19 16:26:21.563 28771:28956 I/ ]
[ 02-19 16:26:21.565 28771:28956 I/ ]
[ 02-19 16:26:21.566 28771:28956 I/ ]
WRITE of size 2 at 0xa136e990 thread T334 (GLThread 337)
[ 02-19 16:26:21.566 28771:28956 I/ ]
我不确定这是否是真正的溢出,因为我不确定我的所有应用程序都是用消毒剂构建的(我已经用它构建了我的 so+ 所有静态数据,但这足够了吗?),并且https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow说如果你的整个应用程序不是用消毒剂构建的,你可能会得到误报。
所以我的问题是:
A°)有人真的成功地使用 android studio 构建了一个经过净化的应用程序吗?
B°)如果是,正确的方法是什么(指将得到支持的方法)?