From 0a6cb303f533499cbf92a9f99336dc3d9d9fdf0c Mon Sep 17 00:00:00 2001 From: "Tachikoma (Codex GPT-5)" Date: Mon, 3 Aug 2026 07:28:40 -0400 Subject: [PATCH] Run ThreadSanitizer tests without ASLR Co-authored-by: Andrew Kesterson --- CMakeLists.txt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4495af..4ea8499 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,19 @@ if(AKERR_SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") "AKERR_SANITIZE requires GCC or Clang, not ${CMAKE_C_COMPILER_ID}") endif() +if(AKERR_SANITIZE STREQUAL "thread" AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + # ThreadSanitizer reserves a fixed, very large virtual-address range. Linux + # ASLR can put a loader mapping inside it before the runtime starts, which + # makes every test fail with "unexpected memory mapping" before main(). + # Run the instrumented tests under the normal util-linux ASLR wrapper. + find_program(AKERR_SETARCH_EXECUTABLE setarch) + if(NOT AKERR_SETARCH_EXECUTABLE) + message(FATAL_ERROR + "AKERR_SANITIZE=thread on Linux requires setarch (util-linux) to " + "start tests with ASLR disabled.") + endif() +endif() + function(akerr_instrument_for_sanitizers _target) if(AKERR_SANITIZE) target_compile_options(${_target} PRIVATE @@ -252,7 +265,13 @@ foreach(_test IN LISTS AKERR_TESTS) target_link_libraries(test_${_test} PRIVATE Threads::Threads) endif() akerr_instrument_for_sanitizers(test_${_test}) - add_test(NAME ${_test} COMMAND test_${_test}) + if(AKERR_SANITIZE STREQUAL "thread" AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_test(NAME ${_test} + COMMAND ${AKERR_SETARCH_EXECUTABLE} ${CMAKE_SYSTEM_PROCESSOR} + -R $) + else() + add_test(NAME ${_test} COMMAND test_${_test}) + endif() # A sanitizer report is a test failure. Without halt_on_error the runtime # prints and continues, which leaves a race to be noticed in the log by # somebody reading it -- and under a race storm the reporting itself is slow