mirror of
https://github.com/triqs/dft_tools
synced 2024-12-23 04:43:42 +01:00
Fix the sanitizers for MacOs
This commit is contained in:
parent
46cbea69d9
commit
759bb9da1d
@ -58,26 +58,25 @@ endif()
|
|||||||
|
|
||||||
# ========= Dynamic Analyzer Checks ==========
|
# ========= Dynamic Analyzer Checks ==========
|
||||||
|
|
||||||
|
# Make additional cmake Modules available
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/share/cmake)
|
||||||
|
|
||||||
# Address Sanitizer
|
# Address Sanitizer
|
||||||
option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer")
|
option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer")
|
||||||
if(ASAN)
|
if(ASAN)
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
message(FATAL_ERROR "Address Sanitizer Checks currently not compatible with OSX.")
|
|
||||||
endif()
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/share/cmake)
|
|
||||||
find_package(libasan_rt REQUIRED)
|
find_package(libasan_rt REQUIRED)
|
||||||
target_compile_options(app4triqs_c PUBLIC -fsanitize=address -fno-omit-frame-pointer)
|
target_compile_options(app4triqs_c PUBLIC -fsanitize=address -fno-omit-frame-pointer)
|
||||||
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=address -fno-omit-frame-pointer -fuse-ld=gold")
|
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=address -fno-omit-frame-pointer")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Undefined Behavior Sanitizer
|
# Undefined Behavior Sanitizer
|
||||||
option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer")
|
option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer")
|
||||||
if(UBSAN)
|
if(UBSAN)
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
message(FATAL_ERROR "Undefined Behavior Sanitizer Checks currently not compatible with OSX.")
|
|
||||||
endif()
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/share/cmake)
|
|
||||||
find_package(libubsan_rt REQUIRED)
|
find_package(libubsan_rt REQUIRED)
|
||||||
target_compile_options(app4triqs_c PUBLIC -fsanitize=undefined -fno-omit-frame-pointer -fno-sanitize=vptr)
|
target_compile_options(app4triqs_c PUBLIC -fsanitize=undefined -fno-omit-frame-pointer -fno-sanitize=vptr)
|
||||||
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=undefined -fno-omit-frame-pointer -fuse-ld=gold")
|
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=undefined -fno-omit-frame-pointer")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ASAN OR UBSAN AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||||
|
target_link_libraries(app4triqs_c INTERFACE "-fuse-ld=gold")
|
||||||
endif()
|
endif()
|
||||||
|
@ -10,7 +10,7 @@ namespace app4triqs {
|
|||||||
*/
|
*/
|
||||||
class toto {
|
class toto {
|
||||||
|
|
||||||
int i = 0.0;
|
int i = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
toto() = default;
|
toto() = default;
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
# ASAN_RT_LIBRARY Address Sanitizer Runtime Library
|
# ASAN_RT_LIBRARY Address Sanitizer Runtime Library
|
||||||
|
|
||||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
set(name clang_rt.asan-x86_64)
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(name clang_rt.asan_osx_dynamic)
|
||||||
|
elseif()
|
||||||
|
set(name clang_rt.asan-x86_64)
|
||||||
|
endif()
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||||
set(name asan)
|
set(name asan)
|
||||||
else()
|
else()
|
||||||
|
@ -30,7 +30,11 @@ set(TRIAL_PATHS
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
set(name clang_rt.ubsan_standalone-x86_64)
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(name clang_rt.ubsan_osx_dynamic)
|
||||||
|
else()
|
||||||
|
set(name clang_rt.ubsan_standalone-x86_64)
|
||||||
|
endif()
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||||
set(name ubsan)
|
set(name ubsan)
|
||||||
else()
|
else()
|
||||||
@ -42,16 +46,23 @@ find_library(UBSAN_RT_LIBRARY
|
|||||||
PATHS ${TRIAL_PATHS}
|
PATHS ${TRIAL_PATHS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mark_as_advanced(UBSAN_RT_LIBRARY)
|
||||||
|
|
||||||
# Try to find UBSan Minimal Runtime for Clang
|
# Try to find UBSan Minimal Runtime for Clang
|
||||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(name libclang_rt.ubsan_minimal_osx_dynamic)
|
||||||
|
else()
|
||||||
|
set(name clang_rt.ubsan_minimal-x86_64)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_library(UBSAN_MINIMAL_RT_LIBRARY
|
find_library(UBSAN_MINIMAL_RT_LIBRARY
|
||||||
NAMES clang_rt.ubsan_minimal-x86_64
|
NAMES ${name}
|
||||||
PATHS ${TRIAL_PATHS}
|
PATHS ${TRIAL_PATHS}
|
||||||
)
|
)
|
||||||
|
mark_as_advanced(UBSAN_MINIMAL_RT_LIBRARY)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
mark_as_advanced(UBSAN_RT_LIBRARY)
|
|
||||||
|
|
||||||
# Imported target
|
# Imported target
|
||||||
add_library(libubsan_rt SHARED IMPORTED)
|
add_library(libubsan_rt SHARED IMPORTED)
|
||||||
set_property(TARGET libubsan_rt PROPERTY IMPORTED_LOCATION ${UBSAN_RT_LIBRARY})
|
set_property(TARGET libubsan_rt PROPERTY IMPORTED_LOCATION ${UBSAN_RT_LIBRARY})
|
||||||
|
@ -4,19 +4,40 @@ file(COPY ${all_h5_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
|||||||
|
|
||||||
set(all_tests Toto chain)
|
set(all_tests Toto chain)
|
||||||
|
|
||||||
|
# Nasty Workaround for Mac Os Homebrew Python to find the proper Sanitizer Compatible Python Executable
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
execute_process(COMMAND bash "-c" "readlink -f $(which python) | xargs dirname" OUTPUT_VARIABLE PYTHON_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
set(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}/../Resources/Python.app/Contents/MacOS/Python")
|
||||||
|
if(NOT EXISTS ${PYTHON_EXECUTABLE})
|
||||||
|
message(FATAL_ERROR "Could not find the proper Python executable for MacOs")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(PYTHON_EXECUTABLE python)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Python Executable: ${PYTHON_EXECUTABLE}")
|
||||||
|
|
||||||
foreach(t ${all_tests})
|
foreach(t ${all_tests})
|
||||||
add_test(NAME ${t} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${t}.py)
|
add_test(NAME ${t} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${t}.py)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# Set the PythonPath
|
||||||
|
set_property(TEST ${all_tests} PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH})
|
||||||
|
|
||||||
|
# === Preload Sanitizer Libraries ===
|
||||||
|
|
||||||
# If ASAN=ON use minimal runtime of UBSAN if it exists
|
# If ASAN=ON use minimal runtime of UBSAN if it exists
|
||||||
if(${ASAN} AND UBSAN_MINIMAL_RT_LIBRARY)
|
if(ASAN AND UBSAN_MINIMAL_RT_LIBRARY)
|
||||||
set(UBSAN_RT_LIBRARY ${UBSAN_MINIMAL_RT_LIBRARY})
|
set(UBSAN_RT_LIBRARY ${UBSAN_MINIMAL_RT_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set the PythonPath, Sanitizer Library Preloads and UBSan Options for all tests
|
# Set the Sanitizer Library Preloads and UBSan Options for all tests
|
||||||
set_property(TEST ${all_tests} PROPERTY
|
if(ASAN OR UBSAN)
|
||||||
ENVIRONMENT
|
set_property(TEST ${all_tests} PROPERTY
|
||||||
PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}
|
ENVIRONMENT
|
||||||
LD_PRELOAD=$<$<BOOL:${ASAN}>:${ASAN_RT_LIBRARY}>:$<$<BOOL:${UBSAN}>:${UBSAN_RT_LIBRARY}>
|
PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}
|
||||||
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1:$ENV{UBSAN_OPTIONS}
|
LD_PRELOAD=$<$<BOOL:${ASAN}>:${ASAN_RT_LIBRARY}>:$<$<BOOL:${UBSAN}>:${UBSAN_RT_LIBRARY}>
|
||||||
)
|
DYLD_INSERT_LIBRARIES=$<$<BOOL:${ASAN}>:${ASAN_RT_LIBRARY}>:$<$<BOOL:${UBSAN}>:${UBSAN_RT_LIBRARY}>
|
||||||
|
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1:$ENV{UBSAN_OPTIONS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user