diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index c7478dbea2..8acbe2821d 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -1210,6 +1210,29 @@ if(NOT BUN_CPP_ONLY) ) endif() + # somehow on some Linux systems we need to disable ASLR for ASAN-instrumented binaries to run + # when spawned by cmake (they run fine from a shell!) + # otherwise they crash with: + # ==856230==Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING. + # ==856230==ASan shadow was supposed to be located in the [0x00007fff7000-0x10007fff7fff] range. + # ==856230==This might be related to ELF_ET_DYN_BASE change in Linux 4.12. + # ==856230==See https://github.com/google/sanitizers/issues/856 for possible workarounds. + # the linked issue refers to very old kernels but this still happens to us on modern ones. + # disabling ASLR to run the binary works around it + set(TEST_BUN_COMMAND_BASE + env BUN_DEBUG_QUIET_LOGS=1 + ${BUILD_PATH}/${bunExe} --revision) + set(TEST_BUN_COMMAND_ENV_WRAP + ${CMAKE_COMMAND} -E env BUN_DEBUG_QUIET_LOGS=1) + if (LINUX AND ENABLE_ASAN) + set(TEST_BUN_COMMAND + ${TEST_BUN_COMMAND_ENV_WRAP} setarch ${CMAKE_HOST_SYSTEM_PROCESSOR} -R ${TEST_BUN_COMMAND_BASE} + || ${TEST_BUN_COMMAND_ENV_WRAP} ${TEST_BUN_COMMAND_BASE}) + else() + set(TEST_BUN_COMMAND + ${TEST_BUN_COMMAND_ENV_WRAP} ${TEST_BUN_COMMAND_BASE}) + endif() + register_command( TARGET ${bun} @@ -1218,10 +1241,7 @@ if(NOT BUN_CPP_ONLY) COMMENT "Testing ${bun}" COMMAND - ${CMAKE_COMMAND} - -E env BUN_DEBUG_QUIET_LOGS=1 - ${BUILD_PATH}/${bunExe} - --revision + ${TEST_BUN_COMMAND} CWD ${BUILD_PATH} ) diff --git a/patches/tinycc/CMakeLists.txt b/patches/tinycc/CMakeLists.txt index 971f0952ad..cca27c5c97 100644 --- a/patches/tinycc/CMakeLists.txt +++ b/patches/tinycc/CMakeLists.txt @@ -109,11 +109,28 @@ endif() add_executable(c2str.exe conftest.c) target_compile_options(c2str.exe PRIVATE -DC2STR) +# somehow on some Linux systems we need to disable ASLR for ASAN-instrumented binaries to run +# when spawned by cmake (they run fine from a shell!) +# otherwise they crash with: +# ==856230==Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING. +# ==856230==ASan shadow was supposed to be located in the [0x00007fff7000-0x10007fff7fff] range. +# ==856230==This might be related to ELF_ET_DYN_BASE change in Linux 4.12. +# ==856230==See https://github.com/google/sanitizers/issues/856 for possible workarounds. +# the linked issue refers to very old kernels but this still happens to us on modern ones. +# disabling ASLR to run the binary works around it +set(C2STR_COMMAND $ include/tccdefs.h tccdefs_.h) +if(LINUX AND (CMAKE_C_FLAGS MATCHES "-fsanitize")) + # our CI builds run in a container where setarch isn't allowed to change the personality. + # but the ASan binaries seem to run fine there without ASLR disabled + # so, if the command fails with setarch, we try again without (|| ${C2STR_COMMAND}) as a fallback + set(C2STR_COMMAND setarch ${CMAKE_HOST_SYSTEM_PROCESSOR} -R ${C2STR_COMMAND} || ${C2STR_COMMAND}) +endif() + add_custom_command( TARGET c2str.exe POST_BUILD COMMAND - c2str.exe include/tccdefs.h tccdefs_.h + ${C2STR_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )