Skip to content

Commit e95a8f8

Browse files
grooverdanvuvova
authored andcommitted
MDEV-36156: MSAN Compile and Link flags needed for compile/run checks
When MSAN adds the -fsantize=memory this significantly affects compile and link tests. Whether this is a compile/run/or looking for a symbol in a library these cmake tests require the same flags be set. Ideally the minimum invocation of cmake to create a MSAN build as investigated in MDBF-793 should be: -DWITH_MSAN=ON \ -DCMAKE_{EXE,MODULE}_LINKER_FLAGS="-L${MSAN_LIBDIR} -Wl,-rpath=${MSAN_LIBDIR}" On the assumption that the compiler supports msan and the instrumented libraries are in MSAN_LIBDIR (maybe later can be made a cmake option). Without cmake policy below, the checking of everything from libc++ to libfmt will not have the supplied linker flags or the compile options that WITH_MSAN=ON invokes. Many try_compile and CMake functions that wrapped this and headers failed to be recognised due to missing msan symbols when linking. Also without the -L path, they where applying a link test to the default path libraries rather than the MSAN instrumented ones. The CMake policy enabled is CMP0056, added CMake 3.2, applies CMAKE_EXE_LINKER_FLAGS to try_compile. With this change the MY_CHECK_AND_SET_COMPILER_FLAG remove explict build types resulting in just CMAKE_{C,CXX}_FLAGS being set rather than CMAKE_{C,CXX}_FLAGS_{DEBUG,RELWITHDEBINFO}. These are needed for the default CMP0066 policy to be correctly applied and the msan flags of -fsanitizer=memory are applied to all compile checks. Likewise with MY_CHECK_AND_SET_LINKER_FLAG for CMAKE_{EXE,MODULE,SHARED}_LINKER_FLAGS for those check that involve full linking and CHECK_CXX_SOURCE_RUNS for example.
1 parent 7bb0885 commit e95a8f8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ENDIF()
3131
# in RPM's:
3232

3333
#set(CPACK_RPM_SPEC_MORE_DEFINE "%define __spec_install_post /bin/true")
34-
FOREACH(p CMP0022 CMP0046 CMP0040 CMP0048 CMP0054 CMP0067 CMP0074 CMP0075 CMP0069 CMP0135)
34+
FOREACH(p CMP0022 CMP0046 CMP0040 CMP0048 CMP0054 CMP0056 CMP0067 CMP0074 CMP0075 CMP0069 CMP0135)
3535
IF(POLICY ${p})
3636
CMAKE_POLICY(SET ${p} NEW)
3737
ENDIF()
@@ -245,7 +245,7 @@ ENDIF()
245245

246246
OPTION(WITH_MSAN "Enable memory sanitizer" OFF)
247247
IF (WITH_MSAN)
248-
MY_CHECK_AND_SET_COMPILER_FLAG("-fsanitize=memory -fsanitize-memory-track-origins -U_FORTIFY_SOURCE" DEBUG RELWITHDEBINFO)
248+
MY_CHECK_AND_SET_COMPILER_FLAG("-fsanitize=memory -fsanitize-memory-track-origins -U_FORTIFY_SOURCE")
249249
IF(NOT (have_C__fsanitize_memory__fsanitize_memory_track_origins__U_FORTIFY_SOURCE
250250
AND have_CXX__fsanitize_memory__fsanitize_memory_track_origins__U_FORTIFY_SOURCE))
251251
MESSAGE(FATAL_ERROR "Compiler doesn't support -fsanitize=memory flags")
@@ -255,7 +255,7 @@ IF (WITH_MSAN)
255255
MESSAGE(FATAL_ERROR "C++ Compiler requires support for -stdlib=libc++")
256256
ENDIF()
257257
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
258-
MY_CHECK_AND_SET_LINKER_FLAG("-fsanitize=memory" DEBUG RELWITHDEBINFO)
258+
MY_CHECK_AND_SET_LINKER_FLAG("-fsanitize=memory")
259259
IF(NOT HAVE_LINK_FLAG__fsanitize_memory)
260260
MESSAGE(FATAL_ERROR "Linker doesn't support -fsanitize=memory flags")
261261
ENDIF()

0 commit comments

Comments
 (0)