1 # Build for the undefined behavior sanitizer runtime support library. 2 3 set(UBSAN_SOURCES 4 ubsan_diag.cc 5 ubsan_init.cc 6 ubsan_flags.cc 7 ubsan_handlers.cc 8 ubsan_value.cc 9 ) 10 11 set(UBSAN_STANDALONE_SOURCES 12 ubsan_init_standalone.cc 13 ) 14 15 set(UBSAN_CXX_SOURCES 16 ubsan_handlers_cxx.cc 17 ubsan_type_hash.cc 18 ubsan_type_hash_itanium.cc 19 ubsan_type_hash_win.cc 20 ) 21 22 include_directories(..) 23 24 set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 25 append_no_rtti_flag(UBSAN_CFLAGS) 26 set(UBSAN_STANDALONE_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 27 append_no_rtti_flag(UBSAN_STANDALONE_CFLAGS) 28 set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS}) 29 30 add_custom_target(ubsan) 31 32 if(APPLE) 33 set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES}) 34 if(SANITIZER_CAN_USE_CXXABI) 35 list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXX_SOURCES}) 36 endif() 37 38 # Common parts of UBSan runtime. 39 add_compiler_rt_object_libraries(RTUbsan 40 OS ${SANITIZER_COMMON_SUPPORTED_OS} 41 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH} 42 SOURCES ${UBSAN_COMMON_SOURCES} 43 CFLAGS ${UBSAN_CXXFLAGS}) 44 45 if(COMPILER_RT_HAS_UBSAN) 46 # Initializer of standalone UBSan runtime. 47 add_compiler_rt_object_libraries(RTUbsan_standalone 48 OS ${SANITIZER_COMMON_SUPPORTED_OS} 49 ARCHS ${UBSAN_SUPPORTED_ARCH} 50 SOURCES ${UBSAN_STANDALONE_SOURCES} 51 CFLAGS ${UBSAN_STANDALONE_CFLAGS}) 52 53 add_compiler_rt_runtime(clang_rt.ubsan 54 SHARED 55 OS ${SANITIZER_COMMON_SUPPORTED_OS} 56 ARCHS ${UBSAN_SUPPORTED_ARCH} 57 OBJECT_LIBS RTUbsan 58 RTUbsan_standalone 59 RTSanitizerCommon 60 RTSanitizerCommonLibc 61 PARENT_TARGET ubsan) 62 endif() 63 64 else() 65 # Common parts of UBSan runtime. 66 add_compiler_rt_object_libraries(RTUbsan 67 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH} 68 SOURCES ${UBSAN_SOURCES} CFLAGS ${UBSAN_CFLAGS}) 69 # C++-specific parts of UBSan runtime. Requires a C++ ABI library. 70 add_compiler_rt_object_libraries(RTUbsan_cxx 71 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH} 72 SOURCES ${UBSAN_CXX_SOURCES} CFLAGS ${UBSAN_CXXFLAGS}) 73 74 if(COMPILER_RT_HAS_UBSAN) 75 # Initializer of standalone UBSan runtime. 76 add_compiler_rt_object_libraries(RTUbsan_standalone 77 ARCHS ${UBSAN_SUPPORTED_ARCH} 78 SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) 79 80 # Standalone UBSan runtimes. 81 add_compiler_rt_runtime(clang_rt.ubsan_standalone 82 STATIC 83 ARCHS ${UBSAN_SUPPORTED_ARCH} 84 OBJECT_LIBS RTSanitizerCommon 85 RTSanitizerCommonLibc 86 RTUbsan 87 RTUbsan_standalone 88 CFLAGS ${UBSAN_CFLAGS} 89 PARENT_TARGET ubsan) 90 91 add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx 92 STATIC 93 ARCHS ${UBSAN_SUPPORTED_ARCH} 94 OBJECT_LIBS RTUbsan_cxx 95 CFLAGS ${UBSAN_CXXFLAGS} 96 PARENT_TARGET ubsan) 97 98 if (UNIX) 99 set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) 100 list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386 i686) 101 add_sanitizer_rt_symbols(clang_rt.ubsan_standalone 102 ARCHS ${ARCHS_FOR_SYMBOLS} 103 PARENT_TARGET ubsan 104 EXTRA ubsan.syms.extra) 105 add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx 106 ARCHS ${ARCHS_FOR_SYMBOLS} 107 PARENT_TARGET ubsan 108 EXTRA ubsan.syms.extra) 109 endif() 110 endif() 111 endif() 112 113 add_dependencies(compiler-rt ubsan) 114