qt5base-lts/mkspecs/features/sanitizer.prf
Robert Loehning 6e42ed217c configure: Add sanitizer "fuzzer-no-link"
Adds instrumentation for fuzzing to the binaries but links to the usual
main function instead of a fuzzer's. The similar sanitizer "fuzzer"
should then be used only for building the test itself.

Requires clang 6 or higher.

Change-Id: I24ee1f018b0b97f2977dc86fbdc29a164d7c4e01
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-11-14 15:45:02 +01:00

60 lines
2.7 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_fuzzer_no_link {
QMAKE_CFLAGS += $$QMAKE_SANITIZE_FUZZERNL_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_SANITIZE_FUZZERNL_CXXFLAGS
QMAKE_LFLAGS += $$QMAKE_SANITIZE_FUZZERNL_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