mirror of
https://github.com/triqs/dft_tools
synced 2024-12-23 04:43:42 +01:00
[cmake] Fixing usage of ubsan with Minimal RT, some cleaning
- Use UBsan Minimal RT if found - Prioritize gcc-7 directories over older - Set UBSan options for c++/python tests
This commit is contained in:
parent
82b10c1983
commit
6aa4eee0f4
@ -31,6 +31,7 @@ find_library(ASAN_RT_LIBRARY
|
|||||||
ENV LD_INCLUDE_PATH
|
ENV LD_INCLUDE_PATH
|
||||||
/usr/lib
|
/usr/lib
|
||||||
/usr/local/lib
|
/usr/local/lib
|
||||||
|
/usr/lib/gcc/*/7
|
||||||
/usr/lib/gcc/*/*
|
/usr/lib/gcc/*/*
|
||||||
/usr/lib/clang/*/lib/linux
|
/usr/lib/clang/*/lib/linux
|
||||||
/usr/lib/llvm-*/lib/clang/*/lib/linux
|
/usr/lib/llvm-*/lib/clang/*/lib/linux
|
||||||
|
@ -15,6 +15,19 @@
|
|||||||
# Results are reported in::
|
# Results are reported in::
|
||||||
#
|
#
|
||||||
# UBSAN_RT_LIBRARY Undefined Behavior Sanitizer Runtime Library
|
# UBSAN_RT_LIBRARY Undefined Behavior Sanitizer Runtime Library
|
||||||
|
# [UBSAN_MINIMAL_RT_LIBRARY] Minimal version of UBSan Runtime, To be used in combination with Asan
|
||||||
|
|
||||||
|
set(TRIAL_PATHS
|
||||||
|
ENV LIBRARY_PATH
|
||||||
|
ENV LD_INCLUDE_PATH
|
||||||
|
/usr/lib
|
||||||
|
/usr/local/lib
|
||||||
|
/usr/lib/gcc/7/*
|
||||||
|
/usr/lib/gcc/*/*
|
||||||
|
/usr/lib/clang/*/lib/linux
|
||||||
|
/usr/lib/llvm-*/lib/clang/*/lib/linux
|
||||||
|
/usr/local/opt/llvm/lib/clang/*/lib/darwin
|
||||||
|
)
|
||||||
|
|
||||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
set(name clang_rt.ubsan_standalone-x86_64)
|
set(name clang_rt.ubsan_standalone-x86_64)
|
||||||
@ -26,17 +39,17 @@ endif()
|
|||||||
|
|
||||||
find_library(UBSAN_RT_LIBRARY
|
find_library(UBSAN_RT_LIBRARY
|
||||||
NAMES ${name}
|
NAMES ${name}
|
||||||
PATHS
|
PATHS ${TRIAL_PATHS}
|
||||||
ENV LIBRARY_PATH
|
|
||||||
ENV LD_INCLUDE_PATH
|
|
||||||
/usr/lib
|
|
||||||
/usr/local/lib
|
|
||||||
/usr/lib/gcc/*/*
|
|
||||||
/usr/lib/clang/*/lib/linux
|
|
||||||
/usr/lib/llvm-*/lib/clang/*/lib/linux
|
|
||||||
/usr/local/opt/llvm/lib/clang/*/lib/darwin
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Try to find UBSan Minimal Runtime for Clang
|
||||||
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
|
find_library(UBSAN_MINIMAL_RT_LIBRARY
|
||||||
|
NAMES clang_rt.ubsan_minimal-x86_64
|
||||||
|
PATHS ${TRIAL_PATHS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
mark_as_advanced(UBSAN_RT_LIBRARY)
|
mark_as_advanced(UBSAN_RT_LIBRARY)
|
||||||
|
|
||||||
# Imported target
|
# Imported target
|
||||||
|
@ -26,3 +26,9 @@ foreach(t ${all_tests})
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# Set UBSan Options for all tests
|
||||||
|
set_property(TEST ${all_tests} PROPERTY
|
||||||
|
ENVIRONMENT
|
||||||
|
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
|
||||||
|
)
|
||||||
|
@ -8,9 +8,15 @@ foreach(t ${all_tests})
|
|||||||
add_test(NAME ${t} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${t}.py)
|
add_test(NAME ${t} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${t}.py)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Set the PythonPath and the Sanitizer Library Preloads
|
# If ASAN=ON use minimal runtime of UBSAN if it exists
|
||||||
|
if(${ASAN} AND UBSAN_MINIMAL_RT_LIBRARY)
|
||||||
|
set(UBSAN_RT_LIBRARY ${UBSAN_MINIMAL_RT_LIBRARY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set the PythonPath, Sanitizer Library Preloads and UBSan Options for all tests
|
||||||
set_property(TEST ${all_tests} PROPERTY
|
set_property(TEST ${all_tests} PROPERTY
|
||||||
ENVIRONMENT
|
ENVIRONMENT
|
||||||
PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}
|
PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}
|
||||||
LD_PRELOAD=$<$<BOOL:${ASAN}>:${ASAN_RT_LIBRARY}>:$<$<BOOL:${UBSAN}>:${UBSAN_RT_LIBRARY}>
|
LD_PRELOAD=$<$<BOOL:${ASAN}>:${ASAN_RT_LIBRARY}>:$<$<BOOL:${UBSAN}>:${UBSAN_RT_LIBRARY}>
|
||||||
|
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user