From 988fab3f66efb04310b703d7028267dbf59adf01 Mon Sep 17 00:00:00 2001 From: Kostya Kortchinsky Date: Thu, 22 Mar 2018 15:04:31 +0000 Subject: [PATCH] [sanitizer] Split coverage into separate RT in sanitizer_common Summary: `sanitizer_common`'s coverage support is fairly well separated, and libcdep by default. Several sanitizers don't make use of coverage, and as far as I can tell do no benefit from the extra dependencies pulled in by the coverage public interface functions. The following sanitizers call `InitializeCoverage` explicitely: MSan, ASan, LSan, HWAsan, UBSan. On top of this, any sanitizer bundling RTUBSan should add the coverage RT as well: ASan, Scudo, UBSan, CFI (diag), TSan, MSan, HWAsan. So in the end the following have no need: DFSan, ESan, CFI, SafeStack (nolibc anyway), XRay, and the upcoming Scudo minimal runtime. I tested this with all the sanitizers check-* with gcc & clang, and in standalone on Linux & Android, and there was no issue. I couldn't test this on Mac, Fuchsia, BSDs, & Windows for lack of an environment, so adding a bunch of people for additional scrunity. I couldn't test HWAsan either. Reviewers: eugenis, vitalybuka, alekseyshl, flowerhack, kubamracek, dberris, rnk, krytarowski Reviewed By: vitalybuka, alekseyshl, flowerhack, dberris Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D44701 llvm-svn: 328204 --- compiler-rt/lib/asan/CMakeLists.txt | 2 ++ compiler-rt/lib/asan/tests/CMakeLists.txt | 3 +++ compiler-rt/lib/cfi/CMakeLists.txt | 1 + compiler-rt/lib/hwasan/CMakeLists.txt | 6 ++++-- compiler-rt/lib/lsan/CMakeLists.txt | 2 ++ compiler-rt/lib/msan/CMakeLists.txt | 1 + compiler-rt/lib/sanitizer_common/CMakeLists.txt | 16 ++++++++++++---- compiler-rt/lib/scudo/CMakeLists.txt | 2 ++ compiler-rt/lib/tsan/CMakeLists.txt | 2 ++ compiler-rt/lib/tsan/tests/CMakeLists.txt | 1 + compiler-rt/lib/ubsan/CMakeLists.txt | 4 ++++ 11 files changed, 34 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index fbd72f6..31747ad 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -125,6 +125,7 @@ if(APPLE) RTInterception RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTLSanCommon RTUbsan CFLAGS ${ASAN_DYNAMIC_CFLAGS} @@ -138,6 +139,7 @@ else() RTInterception RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTLSanCommon RTUbsan) diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index 7c2cf5b..3b1cedd 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -251,6 +251,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID) $ $ $ + $ $ $) else() @@ -260,6 +261,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID) $ $ $ + $ $ $ $) @@ -283,6 +285,7 @@ if(ANDROID) $ $ $ + $ $ $ ${COMPILER_RT_GTEST_SOURCE} diff --git a/compiler-rt/lib/cfi/CMakeLists.txt b/compiler-rt/lib/cfi/CMakeLists.txt index 6c53144..934f121 100644 --- a/compiler-rt/lib/cfi/CMakeLists.txt +++ b/compiler-rt/lib/cfi/CMakeLists.txt @@ -30,6 +30,7 @@ if(OS_NAME MATCHES "Linux") OBJECT_LIBS RTInterception RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTUbsan CFLAGS ${CFI_CFLAGS} ${CFI_DIAG_CFLAGS} PARENT_TARGET cfi) diff --git a/compiler-rt/lib/hwasan/CMakeLists.txt b/compiler-rt/lib/hwasan/CMakeLists.txt index 15013c0..34f5f15b 100644 --- a/compiler-rt/lib/hwasan/CMakeLists.txt +++ b/compiler-rt/lib/hwasan/CMakeLists.txt @@ -78,7 +78,8 @@ foreach(arch ${HWASAN_SUPPORTED_ARCH}) RTInterception RTSanitizerCommon RTSanitizerCommonLibc - RTUbsan + RTSanitizerCommonCoverage + RTUbsan CFLAGS ${HWASAN_RTL_CFLAGS} PARENT_TARGET hwasan) add_compiler_rt_runtime(clang_rt.hwasan_cxx @@ -112,7 +113,8 @@ foreach(arch ${HWASAN_SUPPORTED_ARCH}) RTInterception RTSanitizerCommon RTSanitizerCommonLibc - RTUbsan + RTSanitizerCommonCoverage + RTUbsan # The only purpose of RTHWAsan_dynamic_version_script_dummy is to # carry a dependency of the shared runtime on the version script. # Replacing it with a straightforward diff --git a/compiler-rt/lib/lsan/CMakeLists.txt b/compiler-rt/lib/lsan/CMakeLists.txt index 60da3e1..86b2bc1 100644 --- a/compiler-rt/lib/lsan/CMakeLists.txt +++ b/compiler-rt/lib/lsan/CMakeLists.txt @@ -43,6 +43,7 @@ if(COMPILER_RT_HAS_LSAN) RTInterception RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage CFLAGS ${LSAN_CFLAGS} LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${LSAN_LINK_LIBS} @@ -56,6 +57,7 @@ if(COMPILER_RT_HAS_LSAN) $ $ $ + $ $ CFLAGS ${LSAN_CFLAGS} PARENT_TARGET lsan) diff --git a/compiler-rt/lib/msan/CMakeLists.txt b/compiler-rt/lib/msan/CMakeLists.txt index 61c7bd7..ebe0b64 100644 --- a/compiler-rt/lib/msan/CMakeLists.txt +++ b/compiler-rt/lib/msan/CMakeLists.txt @@ -40,6 +40,7 @@ foreach(arch ${MSAN_SUPPORTED_ARCH}) $ $ $ + $ $ CFLAGS ${MSAN_RTL_CFLAGS} PARENT_TARGET msan) diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt index ca82458..563dca3 100644 --- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt @@ -64,10 +64,6 @@ set(SANITIZER_NOLIBC_SOURCES set(SANITIZER_LIBCDEP_SOURCES sanitizer_common_libcdep.cc sanitizer_allocator_checks.cc - sancov_flags.cc - sanitizer_coverage_fuchsia.cc - sanitizer_coverage_libcdep_new.cc - sanitizer_coverage_win_sections.cc sanitizer_linux_libcdep.cc sanitizer_mac_libcdep.cc sanitizer_posix_libcdep.cc @@ -77,6 +73,12 @@ set(SANITIZER_LIBCDEP_SOURCES sanitizer_symbolizer_posix_libcdep.cc sanitizer_unwind_linux_libcdep.cc) +set(SANITIZER_COVERAGE_SOURCES + sancov_flags.cc + sanitizer_coverage_fuchsia.cc + sanitizer_coverage_libcdep_new.cc + sanitizer_coverage_win_sections.cc) + # Explicitly list all sanitizer_common headers. Not all of these are # included in sanitizer_common source files, but we need to depend on # headers when building our custom unit tests. @@ -208,6 +210,12 @@ add_compiler_rt_object_libraries(RTSanitizerCommonLibc SOURCES ${SANITIZER_LIBCDEP_SOURCES} CFLAGS ${SANITIZER_CFLAGS} DEFS ${SANITIZER_COMMON_DEFINITIONS}) +add_compiler_rt_object_libraries(RTSanitizerCommonCoverage + ${OS_OPTION} + ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${SANITIZER_COVERAGE_SOURCES} + CFLAGS ${SANITIZER_CFLAGS} + DEFS ${SANITIZER_COMMON_DEFINITIONS}) set(SANITIZER_NO_WEAK_HOOKS_CFLAGS ${SANITIZER_CFLAGS}) list(APPEND SANITIZER_NO_WEAK_HOOKS_CFLAGS "-DSANITIZER_SUPPORTS_WEAK_HOOKS=0") diff --git a/compiler-rt/lib/scudo/CMakeLists.txt b/compiler-rt/lib/scudo/CMakeLists.txt index 0aba0ca..97a26fa 100644 --- a/compiler-rt/lib/scudo/CMakeLists.txt +++ b/compiler-rt/lib/scudo/CMakeLists.txt @@ -51,6 +51,7 @@ if(COMPILER_RT_HAS_SCUDO) SOURCES ${SCUDO_SOURCES} OBJECT_LIBS RTSanitizerCommonNoTermination RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTInterception RTUbsan CFLAGS ${SCUDO_CFLAGS} @@ -70,6 +71,7 @@ if(COMPILER_RT_HAS_SCUDO) SOURCES ${SCUDO_SOURCES} ${SCUDO_CXX_SOURCES} OBJECT_LIBS RTSanitizerCommonNoTermination RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTInterception RTUbsan RTUbsan_cxx diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index 11ec9d8..9dbd6e9 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -114,6 +114,7 @@ if(APPLE) OBJECT_LIBS RTInterception RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTUbsan CFLAGS ${TSAN_RTL_CFLAGS} LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} @@ -163,6 +164,7 @@ else() $ $ $ + $ $ CFLAGS ${TSAN_RTL_CFLAGS} PARENT_TARGET tsan) diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt index ad8d02e..a451feb 100644 --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -22,6 +22,7 @@ if(APPLE) $ $ $ + $ $) set(TSAN_TEST_RUNTIME RTTsanTest) add_library(${TSAN_TEST_RUNTIME} STATIC ${TSAN_TEST_RUNTIME_OBJECTS}) diff --git a/compiler-rt/lib/ubsan/CMakeLists.txt b/compiler-rt/lib/ubsan/CMakeLists.txt index 911bd3e..0461803 100644 --- a/compiler-rt/lib/ubsan/CMakeLists.txt +++ b/compiler-rt/lib/ubsan/CMakeLists.txt @@ -76,6 +76,7 @@ if(APPLE) RTUbsan_standalone RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTInterception LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS} PARENT_TARGET ubsan) @@ -88,6 +89,7 @@ if(APPLE) RTUbsan_standalone RTSanitizerCommonNoHooks RTSanitizerCommonLibcNoHooks + RTSanitizerCommonCoverage RTInterception LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS} PARENT_TARGET ubsan) @@ -154,6 +156,7 @@ else() SOURCES ubsan_init_standalone_preinit.cc OBJECT_LIBS RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTUbsan RTUbsan_standalone RTInterception @@ -173,6 +176,7 @@ else() ARCHS ${UBSAN_SUPPORTED_ARCH} OBJECT_LIBS RTSanitizerCommon RTSanitizerCommonLibc + RTSanitizerCommonCoverage RTUbsan RTUbsan_cxx RTUbsan_standalone -- 2.7.4