1# Build system for the common Sanitizer runtime support library components. 2# These components are shared between AddressSanitizer and ThreadSanitizer. 3 4set(SANITIZER_SOURCES 5 sanitizer_allocator.cc 6 sanitizer_common.cc 7 sanitizer_deadlock_detector1.cc 8 sanitizer_deadlock_detector2.cc 9 sanitizer_flags.cc 10 sanitizer_libc.cc 11 sanitizer_libignore.cc 12 sanitizer_linux.cc 13 sanitizer_mac.cc 14 sanitizer_persistent_allocator.cc 15 sanitizer_platform_limits_linux.cc 16 sanitizer_platform_limits_posix.cc 17 sanitizer_posix.cc 18 sanitizer_printf.cc 19 sanitizer_procmaps_linux.cc 20 sanitizer_procmaps_mac.cc 21 sanitizer_stackdepot.cc 22 sanitizer_stacktrace.cc 23 sanitizer_suppressions.cc 24 sanitizer_symbolizer.cc 25 sanitizer_symbolizer_libbacktrace.cc 26 sanitizer_symbolizer_win.cc 27 sanitizer_tls_get_addr.cc 28 sanitizer_thread_registry.cc 29 sanitizer_win.cc) 30 31set(SANITIZER_LIBCDEP_SOURCES 32 sanitizer_common_libcdep.cc 33 sanitizer_coverage_libcdep.cc 34 sanitizer_coverage_mapping_libcdep.cc 35 sanitizer_linux_libcdep.cc 36 sanitizer_posix_libcdep.cc 37 sanitizer_stacktrace_libcdep.cc 38 sanitizer_stoptheworld_linux_libcdep.cc 39 sanitizer_symbolizer_libcdep.cc 40 sanitizer_symbolizer_posix_libcdep.cc) 41 42# Explicitly list all sanitizer_common headers. Not all of these are 43# included in sanitizer_common source files, but we need to depend on 44# headers when building our custom unit tests. 45set(SANITIZER_HEADERS 46 sanitizer_addrhashmap.h 47 sanitizer_allocator.h 48 sanitizer_allocator_interface.h 49 sanitizer_allocator_internal.h 50 sanitizer_atomic.h 51 sanitizer_atomic_clang.h 52 sanitizer_atomic_msvc.h 53 sanitizer_bitvector.h 54 sanitizer_bvgraph.h 55 sanitizer_common.h 56 sanitizer_common_interceptors.inc 57 sanitizer_common_interceptors_ioctl.inc 58 sanitizer_common_interceptors_format.inc 59 sanitizer_common_syscalls.inc 60 sanitizer_deadlock_detector.h 61 sanitizer_deadlock_detector_interface.h 62 sanitizer_flags.h 63 sanitizer_internal_defs.h 64 sanitizer_lfstack.h 65 sanitizer_libc.h 66 sanitizer_libignore.h 67 sanitizer_linux.h 68 sanitizer_list.h 69 sanitizer_mac.h 70 sanitizer_mutex.h 71 sanitizer_persistent_allocator.h 72 sanitizer_placement_new.h 73 sanitizer_platform.h 74 sanitizer_platform_interceptors.h 75 sanitizer_platform_limits_posix.h 76 sanitizer_procmaps.h 77 sanitizer_quarantine.h 78 sanitizer_report_decorator.h 79 sanitizer_stackdepot.h 80 sanitizer_stackdepotbase.h 81 sanitizer_stacktrace.h 82 sanitizer_stoptheworld.h 83 sanitizer_suppressions.h 84 sanitizer_symbolizer.h 85 sanitizer_symbolizer_libbacktrace.h 86 sanitizer_syscall_generic.inc 87 sanitizer_syscall_linux_x86_64.inc 88 sanitizer_thread_registry.h) 89 90set(SANITIZER_COMMON_DEFINITIONS) 91 92if(MSVC) 93 list(APPEND SANITIZER_COMMON_DEFINITIONS 94 SANITIZER_NEEDS_SEGV=0) 95else() 96 list(APPEND SANITIZER_COMMON_DEFINITIONS 97 SANITIZER_NEEDS_SEGV=1) 98endif() 99 100set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 101append_no_rtti_flag(SANITIZER_CFLAGS) 102 103append_if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512 SANITIZER_CFLAGS) 104append_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors SANITIZER_CFLAGS) 105 106add_custom_target(sanitizer_common) 107set(SANITIZER_RUNTIME_LIBRARIES) 108if(APPLE) 109 # Build universal binary on APPLE. 110 foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) 111 add_compiler_rt_darwin_object_library(RTSanitizerCommon ${os} 112 ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} 113 SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES} 114 CFLAGS ${SANITIZER_CFLAGS} 115 DEFS ${SANITIZER_COMMON_DEFINITIONS}) 116 list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${os}) 117 endforeach() 118elseif(ANDROID) 119 add_library(RTSanitizerCommon.arm.android OBJECT 120 ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES}) 121 set_target_compile_flags(RTSanitizerCommon.arm.android 122 ${SANITIZER_CFLAGS}) 123 set_property(TARGET RTSanitizerCommon.arm.android APPEND PROPERTY 124 COMPILE_DEFINITIONS ${SANITIZER_COMMON_DEFINITIONS}) 125 list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.arm.android) 126else() 127 # Otherwise, build separate libraries for each target. 128 foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH}) 129 add_compiler_rt_object_library(RTSanitizerCommon ${arch} 130 SOURCES ${SANITIZER_SOURCES} CFLAGS ${SANITIZER_CFLAGS} 131 DEFS ${SANITIZER_COMMON_DEFINITIONS}) 132 add_compiler_rt_object_library(RTSanitizerCommonLibc ${arch} 133 SOURCES ${SANITIZER_LIBCDEP_SOURCES} CFLAGS ${SANITIZER_CFLAGS} 134 DEFS ${SANITIZER_COMMON_DEFINITIONS}) 135 list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${arch} 136 RTSanitizerCommonLibc.${arch}) 137 add_compiler_rt_runtime(clang_rt.san-${arch} ${arch} STATIC 138 SOURCES $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> 139 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> 140 CFLAGS ${SANITIZER_CFLAGS} 141 DEFS ${SANITIZER_COMMON_DEFINITIONS}) 142 add_dependencies(sanitizer_common clang_rt.san-${arch}) 143 endforeach() 144endif() 145 146add_dependencies(compiler-rt sanitizer_common) 147 148# Unit tests for common sanitizer runtime. 149if(COMPILER_RT_INCLUDE_TESTS) 150 add_subdirectory(tests) 151endif() 152