qt5base-lts/mkspecs/features/sanitizer.prf
BogDan Vatra e428cdc32c Android: Fix sanitize_address
Starting with Android 8.1.0 wrap.sh can be used to enable ASAN on Android.

Change-Id: I6ef6e5989475b9b7981d05e78a03f9680c1acb1b
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2019-05-29 15:03:47 +03:00

54 lines
2.5 KiB
Plaintext

# Sanitizer flags
sanitize_address {
QMAKE_CFLAGS += $$QMAKE_SANITIZE_ADDRESS_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_SANITIZE_ADDRESS_CXXFLAGS
QMAKE_LFLAGS += $$QMAKE_SANITIZE_ADDRESS_LFLAGS
android {
# ARM 32 (armeabi-v7a & arm5) are not supported because Qt must be rebuilt with -marm
equals(ANDROID_TARGET_ARCH, arm64-v8a): ANDROID_LIBCLANG_RT_FILE = "libclang_rt.asan-aarch64-android.so"
else: equals(ANDROID_TARGET_ARCH, x86): ANDROID_LIBCLANG_RT_FILE = "libclang_rt.asan-i686-android.so"
else: equals(ANDROID_TARGET_ARCH, x86_64): ANDROID_LIBCLANG_RT_FILE = "libclang_rt.asan-x86_64-android.so"
else: error("ASAN: Unsupported platform $${ANDROID_TARGET_ARCH}")
ANDROID_LIBCLANG_RT_PATH = $${NDK_LLVM_PATH}/lib64/clang
ANDROID_CLANG_RT_VERSIONS = $$files($$ANDROID_LIBCLANG_RT_PATH/*)
for (VERSION, ANDROID_CLANG_RT_VERSIONS) {
greaterThan(VERSION, $$ANDROID_LIBCLANG_RT_PATH): ANDROID_LIBCLANG_RT_PATH = $$VERSION
}
ANDROID_LIBCLANG_RT_PATH = "$${ANDROID_LIBCLANG_RT_PATH}/lib/linux/"
ANDROID_WRAP_SH_CONTENT = "$$LITERAL_HASH!/system/bin/sh"
ANDROID_WRAP_SH_CONTENT += "HERE=\"$(cd \"$(dirname \"$0\")\" && pwd)\""
isEmpty(ANDROID_ASAN_OPTIONS): ANDROID_ASAN_OPTIONS = "log_to_syslog=false,allow_user_segv_handler=1"
ANDROID_WRAP_SH_CONTENT += "export ASAN_OPTIONS=$${ANDROID_ASAN_OPTIONS}"
ANDROID_WRAP_SH_CONTENT += "export LD_PRELOAD=$HERE/$${ANDROID_LIBCLANG_RT_FILE}"
ANDROID_WRAP_SH_CONTENT += "exec \"$@\""
write_file($$OUT_PWD/android-build/resources/lib/$${ANDROID_TARGET_ARCH}/wrap.sh, ANDROID_WRAP_SH_CONTENT) | error()
libclang_rt.path = /libs/$$ANDROID_TARGET_ARCH/
libclang_rt.files = "$${ANDROID_LIBCLANG_RT_PATH}/$${ANDROID_LIBCLANG_RT_FILE}"
INSTALLS += libclang_rt
}
}
sanitize_memory {
QMAKE_CFLAGS += $$QMAKE_SANITIZE_MEMORY_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_SANITIZE_MEMORY_CXXFLAGS
QMAKE_LFLAGS += $$QMAKE_SANITIZE_MEMORY_LFLAGS
}
sanitize_thread {
QMAKE_CFLAGS += $$QMAKE_SANITIZE_THREAD_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_SANITIZE_THREAD_CXXFLAGS
QMAKE_LFLAGS += $$QMAKE_SANITIZE_THREAD_LFLAGS
}
sanitize_undefined {
QMAKE_CFLAGS += $$QMAKE_SANITIZE_UNDEFINED_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_SANITIZE_UNDEFINED_CXXFLAGS
QMAKE_LFLAGS += $$QMAKE_SANITIZE_UNDEFINED_LFLAGS
}
QMAKE_CFLAGS += $$QMAKE_COMMON_SANITIZE_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_COMMON_SANITIZE_CXXFLAGS