Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -225,6 +225,17 @@ # Warnings to turn off for all libraries, not just sanitizers. append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS) +if (CMAKE_LINKER MATCHES "link.exe$") + # Silence MSVC linker warnings caused by empty object files. The + # sanitizer libraries intentionally use ifdefs that result in empty + # files, rather than skipping these files in the build system. + # Ideally, we would pass this flag only for the libraries that need + # it, but CMake doesn't seem to have a way to set linker flags for + # individual static libraries, so we enable the suppression flag for + # the whole compiler-rt project. + append("/IGNORE:4221" CMAKE_STATIC_LINKER_FLAGS) +endif() + add_subdirectory(include) set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx) Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -136,10 +136,18 @@ if(type STREQUAL "STATIC") set(libname "${name}-${arch}") set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) + # We add empty files to archives, which makes MSVC's linker complain + # about not defining any previously undefined public symbols. Since + # we're doing that on purpose (it simplifies the build configuration), + # those warnings would only clutter the build diagnostics, so we + # suppress them. + # if(CMAKE_LINKER MATCHES "link.exe$") + set(extra_linkflags_${libname} "/IGNORE:4221") + # endif() else() set(libname "${name}-dynamic-${arch}") set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) - set(extra_linkflags_${libname} ${TARGET_${arch}_LINKFLAGS} ${LIB_LINKFLAGS}) + set(extra_linkflags_${libname} ${TARGET_${arch}_LINKFLAGS} ${LIB_LINKFLAGS} "/IGNORE:4221") if(WIN32) set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX}) else() @@ -188,7 +196,7 @@ add_library(${libname} ${type} ${sources_${libname}}) set_target_compile_flags(${libname} ${extra_cflags_${libname}}) - set_target_link_flags(${libname} ${extra_linkflags_${libname}}) + set_target_link_flags(${libname} ${extra_linkflags_${libname}} "/IGNORE:4221") set_property(TARGET ${libname} APPEND PROPERTY COMPILE_DEFINITIONS ${LIB_DEFS}) set_target_output_directories(${libname} ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) @@ -243,7 +251,7 @@ # when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help # in compilation and linking of unittests. string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") -set(COMPILER_RT_UNITTEST_LINKFLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) +set(COMPILER_RT_UNITTEST_LINKFLAGS ${COMPILER_RT_UNITTEST_CFLAGS} "/IGNORE:4221") # Unittests support. set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) @@ -310,7 +318,7 @@ add_custom_target(${test_name} COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}" - ${TEST_LINK_FLAGS} + ${TEST_LINK_FLAGS} "/IGNORE:4221" DEPENDS ${TEST_DEPS}) set_target_properties(${test_name} PROPERTIES FOLDER "Compiler-RT Tests") Index: lib/asan/CMakeLists.txt =================================================================== --- lib/asan/CMakeLists.txt +++ lib/asan/CMakeLists.txt @@ -38,7 +38,7 @@ set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) append_rtti_flag(OFF ASAN_CFLAGS) -set(ASAN_DYNAMIC_LINK_FLAGS) +set(ASAN_DYNAMIC_LINK_FLAGS "/IGNORE:4221") if(ANDROID) # On Android, -z global does not do what it is documented to do. @@ -184,6 +184,7 @@ RTUbsan_cxx CFLAGS ${ASAN_DYNAMIC_CFLAGS} LINKFLAGS ${ASAN_DYNAMIC_LINK_FLAGS} + "/IGNORE:4221" ${VERSION_SCRIPT_FLAG} LINK_LIBS ${ASAN_DYNAMIC_LIBS} DEFS ${ASAN_DYNAMIC_DEFINITIONS} Index: lib/asan/tests/CMakeLists.txt =================================================================== --- lib/asan/tests/CMakeLists.txt +++ lib/asan/tests/CMakeLists.txt @@ -66,6 +66,16 @@ list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -fno-exceptions -DGTEST_HAS_SEH=0) endif() +# We add empty files to archives, which makes MSVC's linker complain +# about not defining any previously undefined public symbols. Since +# we're doing that on purpose (it simplifies the build configuration), +# those warnings would only clutter the build diagnostics, so we +# suppress them. +# if(CMAKE_LINKER MATCHES "link.exe$") + set(SUPPRESS_NO_NEW_SYMBOLS_WARNING "/IGNORE:4221") + list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS ${SUPPRESS_NO_NEW_SYMBOLS_WARNING}) +# endif() + set(ASAN_BLACKLIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore") set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS ${ASAN_UNITTEST_COMMON_CFLAGS} @@ -168,6 +178,7 @@ OBJECTS ${TEST_OBJECTS} DEPS ${TEST_DEPS} LINK_FLAGS ${TEST_LINKFLAGS} + /IGNORE:4221 ${TARGET_LINK_FLAGS}) endmacro() @@ -265,7 +276,7 @@ add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test" ${arch} ${kind} SUBDIR "dynamic" OBJECTS ${ASAN_INST_DYNAMIC_TEST_OBJECTS} - LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS}) + LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS} "/IGNORE:4221") endif() # Add static ASan runtime that will be linked with uninstrumented tests. @@ -290,9 +301,18 @@ $) endif() add_library(${ASAN_TEST_RUNTIME} STATIC ${ASAN_TEST_RUNTIME_OBJECTS}) + # We add empty files to archives, which makes MSVC's linker complain + # about not defining any previously undefined public symbols. Since + # we're doing that on purpose (it simplifies the build configuration), + # those warnings would only clutter the build diagnostics, so we + # suppress them. + if(CMAKE_LINKER MATCHES "link.exe$") + set(SUPPRESS_NO_NEW_SYMBOLS_WARNING "/IGNORE:4221") + endif() set_target_properties(${ASAN_TEST_RUNTIME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - FOLDER "Compiler-RT Runtime tests") + FOLDER "Compiler-RT Runtime tests" + LINK_FLAGS "/IGNORE:4221") # Uninstrumented tests. set(ASAN_NOINST_TEST_OBJECTS) foreach(src ${ASAN_NOINST_TEST_SOURCES}) @@ -302,7 +322,7 @@ add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Noinst-Test" ${arch} ${kind} SUBDIR "default" OBJECTS ${ASAN_NOINST_TEST_OBJECTS} - LINKFLAGS ${ASAN_UNITTEST_NOINST_LINKFLAGS} + LINKFLAGS ${ASAN_UNITTEST_NOINST_LINKFLAGS} "/IGNORE:4221" WITH_TEST_RUNTIME) # Benchmarks. @@ -314,7 +334,7 @@ add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Benchmark" ${arch} ${kind} SUBDIR "default" OBJECTS ${ASAN_BENCHMARKS_OBJECTS} - LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) + LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS} "/IGNORE:4221") endmacro() if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID) @@ -342,7 +362,7 @@ ${COMPILER_RT_GTEST_SOURCE} ${ASAN_NOINST_TEST_SOURCES}) set_target_compile_flags(AsanNoinstTest ${ASAN_UNITTEST_COMMON_CFLAGS}) - set_target_link_flags(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LINKFLAGS}) + set_target_link_flags(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LINKFLAGS} "/IGNORE:4221") target_link_libraries(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LIBS}) # Test with ASan instrumentation. Link with ASan dynamic runtime. @@ -350,7 +370,7 @@ ${COMPILER_RT_GTEST_SOURCE} ${ASAN_INST_TEST_SOURCES}) set_target_compile_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS}) - set_target_link_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) + set_target_link_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS} "/IGNORE:4221") target_link_libraries(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LIBS}) # Setup correct output directory and link flags. Index: lib/ubsan/CMakeLists.txt =================================================================== --- lib/ubsan/CMakeLists.txt +++ lib/ubsan/CMakeLists.txt @@ -78,7 +78,9 @@ set(UBSAN_CXX_SOURCES ${UBSAN_CXXABI_SOURCES}) else() # Dummy target if we don't have C++ ABI library. - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cc "") + # It contains a dummy function so that linkers won't complain about the + # object file not adding any symbols. + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cc "int dummy_func() { return 0; }") set(UBSAN_CXX_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cc) endif()