diff --git a/CMakeLists.txt b/CMakeLists.txt index 60880be..d5def3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,24 @@ option(ENABLE_LIBCXX "assume libc++ is available" ON) option(ENABLE_STATIC_LIBCXX "assume libc++.a is available" ON) option(ENABLE_LIBUNWIND "assume libunwind is available" ON) +message(STATUS "Checking kernel support for tagged address ABI") +try_run( + _TEST_RUN_RESULT + _BUILD_RESULT_UNUSED + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/test_tagged_addr_abi_support.c + ) +if(DEFINED _TEST_RUN_RESULT AND _TEST_RUN_RESULT EQUAL 0) + set(SUPPORT_HWASAN ON) +else() + message(STATUS "Tagged address ABI disabled, disabling hwasan test(s)") + set(SUPPORT_HWASAN OFF) +endif() +option(ENABLE_HWASAN + "The host supports Aarch64 tagged address ABI" + ${SUPPORT_HWASAN} + ) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in ${CMAKE_BINARY_DIR}/tests/lit.site.cfg diff --git a/README.rst b/README.rst index ed71502..ceede8c 100644 --- a/README.rst +++ b/README.rst @@ -40,6 +40,7 @@ Sensible configuration variables - ``ENABLE_COMPILER_RT``: ON (the default) if we assume compiler-rt is available - ``ENABLE_LIBCXX``: ON (the default) if we assume libc++ is available - ``ENABLE_UNWIND``: ON (the default) if we assume libunwind is available +- ``ENABLE_HWASAN``: Run hwasan tests. Autodetected based on the host system. Writing new tests ----------------- diff --git a/test_tagged_addr_abi_support.c b/test_tagged_addr_abi_support.c new file mode 100644 index 0000000..619bdfa --- /dev/null +++ b/test_tagged_addr_abi_support.c @@ -0,0 +1,14 @@ +/* + * This simple program checks if the kernel running the testsuite has support + * for tagged address ABI, needed to test hardware assisted address sanitizer. + * https://www.kernel.org/doc/html/next/arm64/tagged-address-abi.html + * + * The program returns 0 if the kernel supports tagged address ABI. + */ + +#include +int main(void) +{ + return prctl(PR_GET_TAGGED_ADDR_CTRL, 0,0,0,0); +} + diff --git a/tests/lit.site.cfg.in b/tests/lit.site.cfg.in index f5c0bb7..a40946f 100644 --- a/tests/lit.site.cfg.in +++ b/tests/lit.site.cfg.in @@ -51,3 +51,4 @@ enable_feature("compiler-rt", "@ENABLE_COMPILER_RT@") enable_feature("libc++", "@ENABLE_LIBCXX@") enable_feature("static-libc++", "@ENABLE_STATIC_LIBCXX@") enable_feature("libunwind", "@ENABLE_LIBUNWIND@") +enable_feature("support_hwasan", "@ENABLE_HWASAN@") diff --git a/tests/test_hwasan.c b/tests/test_hwasan.c index 275f2a1..5d6c123 100644 --- a/tests/test_hwasan.c +++ b/tests/test_hwasan.c @@ -1,6 +1,6 @@ // Test hwasan use after free -- aarch64 only. // -// REQUIRES: clang, compiler-rt, aarch64 +// REQUIRES: clang, compiler-rt, support_hwasan // RUN: %clang -o %t -fsanitize=hwaddress -g %s // RUN: env HWASAN_OPTIONS="log_path=stdout:exitcode=0" %t 2>&1 > %t.out // RUN: grep -q "HWAddressSanitizer: tag-mismatch" %t.out