diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt index 74c0e998226491..cfa5a0552a3edc 100644 --- a/be/CMakeLists.txt +++ b/be/CMakeLists.txt @@ -470,7 +470,10 @@ set(CXX_FLAGS_ASAN_UT "-O0 -fsanitize=address -DADDRESS_SANITIZER") # Set the flags to the undefined behavior sanitizer, also known as "ubsan" # Turn on sanitizer and debug symbols to get stack traces: -set(CXX_FLAGS_UBSAN "-O0 -fno-wrapv -mcmodel=medium -fsanitize=undefined -DUNDEFINED_BEHAVIOR_SANITIZER") +set(CXX_FLAGS_UBSAN "-O0 -fno-wrapv -fsanitize=undefined -DUNDEFINED_BEHAVIOR_SANITIZER") +if (ARCH_AMD64) + set(CXX_FLAGS_UBSAN "${CXX_FLAGS_UBSAN} -mcmodel=medium") +endif() # Set the flags to the thread sanitizer, also known as "tsan" # Turn on sanitizer and debug symbols to get stack traces: diff --git a/be/src/common/phdr_cache.cpp b/be/src/common/phdr_cache.cpp index e0f5ff43fed6a5..deb543bc3716a6 100644 --- a/be/src/common/phdr_cache.cpp +++ b/be/src/common/phdr_cache.cpp @@ -107,7 +107,7 @@ extern "C" */ extern "C" { -#ifdef ADDRESS_SANITIZER +#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) void __lsan_ignore_object(const void*); #else void __lsan_ignore_object(const void*) {} // NOLINT diff --git a/be/src/storage/index/ann/cmake-protect/CMakeLists.txt b/be/src/storage/index/ann/cmake-protect/CMakeLists.txt index 0c65e4ae170f7e..c5c35c1c32a077 100644 --- a/be/src/storage/index/ann/cmake-protect/CMakeLists.txt +++ b/be/src/storage/index/ann/cmake-protect/CMakeLists.txt @@ -16,6 +16,19 @@ # under the License. # Make sure compile check in doris will not break compilation of faiss and openblas +# Strip sanitizer flags to prevent build-time tools (e.g., openblas getarch) from +# triggering LeakSanitizer/AddressSanitizer errors during CMake configure phase +string(REGEX REPLACE "-fsanitize=[a-z,=_./-]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REGEX REPLACE "-fsanitize=[a-z,=_./-]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-fno-sanitize=[a-z,=_./-]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REGEX REPLACE "-fno-sanitize=[a-z,=_./-]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-fsanitize-ignorelist=[a-z,=_./-]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REGEX REPLACE "-fsanitize-ignorelist=[a-z,=_./-]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-D[A-Z_]+SANITIZER" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REGEX REPLACE "-D[A-Z_]+SANITIZER" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +# Strip -mcmodel= which is x86_64-specific and unsupported on aarch64 +string(REGEX REPLACE "-mcmodel=[a-z]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REGEX REPLACE "-mcmodel=[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")