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