2012-12-25 20:39:56 +08:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CompilerRTCompile)
|
|
|
|
include(CompilerRTLink)
|
|
|
|
|
|
|
|
include_directories(..)
|
|
|
|
include_directories(../..)
|
|
|
|
|
|
|
|
set(MSAN_LIBCXX_CFLAGS
|
|
|
|
-fsanitize=memory
|
|
|
|
-fsanitize-memory-track-origins
|
2019-10-30 06:04:43 +08:00
|
|
|
-Wno-pedantic
|
2021-05-04 21:50:43 +08:00
|
|
|
-Xclang -fdepfile-entry=${COMPILER_RT_OUTPUT_DIR}/share/msan_ignorelist.txt
|
2019-10-30 06:04:43 +08:00
|
|
|
)
|
2012-12-25 20:39:56 +08:00
|
|
|
|
|
|
|
# Unittest sources and build flags.
|
2019-08-01 22:09:37 +08:00
|
|
|
set(MSAN_UNITTEST_SOURCES
|
|
|
|
msan_test.cpp
|
|
|
|
msan_test_main.cpp
|
|
|
|
)
|
|
|
|
set(MSAN_LOADABLE_SOURCE
|
|
|
|
msan_loadable.cpp
|
|
|
|
)
|
2013-01-29 22:33:29 +08:00
|
|
|
set(MSAN_UNITTEST_HEADERS
|
2013-03-22 17:01:26 +08:00
|
|
|
msan_test_config.h
|
2013-01-29 22:33:29 +08:00
|
|
|
../../../include/sanitizer/msan_interface.h
|
2019-08-01 22:09:37 +08:00
|
|
|
)
|
2012-12-25 20:39:56 +08:00
|
|
|
set(MSAN_UNITTEST_COMMON_CFLAGS
|
2015-10-09 06:21:36 +08:00
|
|
|
-nostdinc++
|
2016-01-15 02:18:49 +08:00
|
|
|
${COMPILER_RT_UNITTEST_CFLAGS}
|
2014-03-24 21:29:20 +08:00
|
|
|
${COMPILER_RT_GTEST_CFLAGS}
|
2012-12-25 20:39:56 +08:00
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/include
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib/msan
|
|
|
|
-g
|
|
|
|
-O2
|
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-mno-omit-leaf-frame-pointer
|
2013-10-25 21:01:31 +08:00
|
|
|
-Wno-deprecated-declarations
|
2014-03-24 17:42:12 +08:00
|
|
|
-Wno-unused-variable
|
|
|
|
-Wno-zero-length-array
|
2015-03-05 05:54:20 +08:00
|
|
|
-Wno-uninitialized
|
2014-03-24 17:42:12 +08:00
|
|
|
-Werror=sign-compare
|
2017-04-11 05:03:18 +08:00
|
|
|
-Wno-gnu-zero-variadic-macro-arguments
|
2012-12-25 20:39:56 +08:00
|
|
|
)
|
2018-02-01 21:57:24 +08:00
|
|
|
# Remove -stdlib= which is unused when passing -nostdinc++.
|
|
|
|
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
|
2012-12-25 20:39:56 +08:00
|
|
|
set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS
|
|
|
|
${MSAN_UNITTEST_COMMON_CFLAGS}
|
|
|
|
-fsanitize=memory
|
|
|
|
-fsanitize-memory-track-origins
|
|
|
|
-mllvm -msan-keep-going=1
|
|
|
|
)
|
|
|
|
set(MSAN_UNITTEST_LINK_FLAGS
|
2021-12-01 17:07:14 +08:00
|
|
|
-nostdlib++
|
[compiler-rt][tests] Propagate COMPILER_RT_UNITTEST_LINK_FLAGS
`COMPILER_RT_UNITTEST_LINK_FLAGS` is dropped in many places, unlike
`COMPILER_RT_UNITTEST_CFLAGS`. This patch attempts to remove that
inconsistency.
Previously reviewed as part of D58951.
Reviewers: sfertile, peter.smith, pzheng, phosek, Hahnfeld, nemanjai, jasonliu
Reviewed By: sfertile
Subscribers: jsji, kubamracek, dberris, mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D60143
llvm-svn: 359733
2019-05-02 06:25:16 +08:00
|
|
|
${COMPILER_RT_UNITTEST_LINK_FLAGS}
|
2012-12-25 20:39:56 +08:00
|
|
|
-fsanitize=memory
|
2019-02-17 20:16:20 +08:00
|
|
|
# Don't need -stdlib=libc++ because we explicitly list libc++.a in the linker
|
2015-10-09 06:21:36 +08:00
|
|
|
# inputs.
|
2012-12-25 20:39:56 +08:00
|
|
|
)
|
2014-04-18 20:19:28 +08:00
|
|
|
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS)
|
2012-12-25 20:39:56 +08:00
|
|
|
|
2017-07-29 01:32:37 +08:00
|
|
|
macro(msan_compile obj_list source arch kind cflags)
|
|
|
|
sanitizer_test_compile(
|
|
|
|
${obj_list} ${source} ${arch}
|
|
|
|
KIND ${kind}
|
|
|
|
COMPILE_DEPS ${MSAN_UNITTEST_HEADERS}
|
2022-03-05 04:08:04 +08:00
|
|
|
DEPS llvm_gtest msan
|
2020-10-22 07:14:48 +08:00
|
|
|
CFLAGS -isystem ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch}/include/c++/v1
|
|
|
|
${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
|
2017-07-29 01:32:37 +08:00
|
|
|
)
|
2012-12-25 20:39:56 +08:00
|
|
|
endmacro()
|
|
|
|
|
2014-04-18 20:19:28 +08:00
|
|
|
macro(msan_link_shared so_list so_name arch kind)
|
2017-01-10 12:33:04 +08:00
|
|
|
cmake_parse_arguments(SOURCE "" "" "OBJECTS;LINK_FLAGS;DEPS" ${ARGN})
|
2014-04-18 20:19:28 +08:00
|
|
|
set(output_so "${CMAKE_CURRENT_BINARY_DIR}/${so_name}.${arch}${kind}.so")
|
2017-01-10 12:33:04 +08:00
|
|
|
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
2014-02-20 20:03:56 +08:00
|
|
|
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
|
|
|
list(APPEND SOURCE_DEPS msan)
|
|
|
|
endif()
|
2012-12-25 20:39:56 +08:00
|
|
|
clang_link_shared(${output_so}
|
|
|
|
OBJECTS ${SOURCE_OBJECTS}
|
[compiler-rt][tests] Propagate COMPILER_RT_UNITTEST_LINK_FLAGS
`COMPILER_RT_UNITTEST_LINK_FLAGS` is dropped in many places, unlike
`COMPILER_RT_UNITTEST_CFLAGS`. This patch attempts to remove that
inconsistency.
Previously reviewed as part of D58951.
Reviewers: sfertile, peter.smith, pzheng, phosek, Hahnfeld, nemanjai, jasonliu
Reviewed By: sfertile
Subscribers: jsji, kubamracek, dberris, mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D60143
llvm-svn: 359733
2019-05-02 06:25:16 +08:00
|
|
|
LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS}
|
2012-12-25 20:39:56 +08:00
|
|
|
DEPS ${SOURCE_DEPS})
|
|
|
|
list(APPEND ${so_list} ${output_so})
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# Main MemorySanitizer unit tests.
|
|
|
|
add_custom_target(MsanUnitTests)
|
|
|
|
set_target_properties(MsanUnitTests PROPERTIES FOLDER "MSan unit tests")
|
|
|
|
|
|
|
|
# Adds MSan unit tests and benchmarks for architecture.
|
2017-07-29 01:32:37 +08:00
|
|
|
macro(add_msan_tests_for_arch arch kind cflags)
|
2012-12-25 20:39:56 +08:00
|
|
|
# Build gtest instrumented with MSan.
|
|
|
|
set(MSAN_INST_GTEST)
|
2017-07-29 04:29:29 +08:00
|
|
|
msan_compile(MSAN_INST_GTEST ${COMPILER_RT_GTEST_SOURCE} ${arch} "${kind}"
|
2017-07-29 01:32:37 +08:00
|
|
|
"${cflags}")
|
2012-12-25 20:39:56 +08:00
|
|
|
|
|
|
|
# Instrumented tests.
|
|
|
|
set(MSAN_INST_TEST_OBJECTS)
|
2013-03-22 17:01:26 +08:00
|
|
|
foreach (SOURCE ${MSAN_UNITTEST_SOURCES})
|
2017-07-29 01:32:37 +08:00
|
|
|
msan_compile(MSAN_INST_TEST_OBJECTS ${SOURCE} ${arch} "${kind}" "${cflags}")
|
2013-03-22 17:01:26 +08:00
|
|
|
endforeach(SOURCE)
|
2012-12-25 20:39:56 +08:00
|
|
|
|
2013-03-12 02:07:42 +08:00
|
|
|
# Instrumented loadable module objects.
|
|
|
|
set(MSAN_INST_LOADABLE_OBJECTS)
|
2014-04-18 20:19:28 +08:00
|
|
|
msan_compile(MSAN_INST_LOADABLE_OBJECTS ${MSAN_LOADABLE_SOURCE} ${arch} "${kind}"
|
2017-07-29 01:32:37 +08:00
|
|
|
"-fPIC;${cflags}")
|
2013-03-12 02:07:42 +08:00
|
|
|
|
|
|
|
# Instrumented loadable library tests.
|
|
|
|
set(MSAN_LOADABLE_SO)
|
2014-04-18 20:19:28 +08:00
|
|
|
msan_link_shared(MSAN_LOADABLE_SO "libmsan_loadable" ${arch} "${kind}"
|
2013-03-12 02:07:42 +08:00
|
|
|
OBJECTS ${MSAN_INST_LOADABLE_OBJECTS}
|
2014-02-20 20:03:56 +08:00
|
|
|
DEPS ${MSAN_INST_LOADABLE_OBJECTS})
|
2013-03-12 02:07:42 +08:00
|
|
|
|
2014-11-25 23:00:23 +08:00
|
|
|
set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
|
2018-03-08 02:14:09 +08:00
|
|
|
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build
|
2019-10-30 06:04:43 +08:00
|
|
|
${MSAN_LOADABLE_SO}
|
|
|
|
"${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a")
|
2014-05-10 06:11:03 +08:00
|
|
|
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
|
|
|
list(APPEND MSAN_TEST_DEPS msan)
|
|
|
|
endif()
|
|
|
|
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
|
|
|
add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
|
2019-10-30 06:04:43 +08:00
|
|
|
OBJECTS ${MSAN_TEST_OBJECTS} "${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a"
|
2015-08-01 05:15:34 +08:00
|
|
|
DEPS ${MSAN_TEST_DEPS}
|
|
|
|
LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
|
2019-02-17 20:16:20 +08:00
|
|
|
${TARGET_LINK_FLAGS})
|
2012-12-25 20:39:56 +08:00
|
|
|
endmacro()
|
|
|
|
|
2014-02-14 21:02:58 +08:00
|
|
|
# We should only build MSan unit tests if we can build instrumented libcxx.
|
2019-02-17 20:16:20 +08:00
|
|
|
if(COMPILER_RT_CAN_EXECUTE_TESTS AND
|
|
|
|
COMPILER_RT_LIBCXX_PATH AND
|
|
|
|
COMPILER_RT_LIBCXXABI_PATH)
|
2015-01-27 20:38:25 +08:00
|
|
|
foreach(arch ${MSAN_SUPPORTED_ARCH})
|
2015-08-01 05:15:34 +08:00
|
|
|
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
|
|
|
|
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
|
|
|
|
add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
|
|
|
|
DEPS ${MSAN_RUNTIME_LIBRARIES}
|
2018-01-21 09:01:53 +08:00
|
|
|
CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
|
|
|
|
USE_TOOLCHAIN)
|
2019-02-17 20:16:20 +08:00
|
|
|
set(MSAN_LIBCXX_DIR ${LIBCXX_PREFIX}/lib/)
|
2015-08-01 05:15:34 +08:00
|
|
|
|
2017-07-29 01:32:37 +08:00
|
|
|
add_msan_tests_for_arch(${arch} "" "")
|
2015-01-27 20:38:25 +08:00
|
|
|
add_msan_tests_for_arch(${arch} "-with-call"
|
2017-07-29 01:32:37 +08:00
|
|
|
"-mllvm;-msan-instrumentation-with-call-threshold=0")
|
2015-01-27 20:38:25 +08:00
|
|
|
endforeach()
|
2012-12-27 21:19:23 +08:00
|
|
|
endif()
|