Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 1 | # Build for the undefined behavior sanitizer runtime support library. |
| 2 | |
| 3 | set(UBSAN_SOURCES |
| 4 | ubsan_diag.cc |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 5 | ubsan_init.cc |
| 6 | ubsan_flags.cc |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 7 | ubsan_handlers.cc |
Richard Smith | 3e587a4 | 2013-03-20 23:49:17 +0000 | [diff] [blame] | 8 | ubsan_value.cc |
| 9 | ) |
| 10 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 11 | set(UBSAN_STANDALONE_SOURCES |
| 12 | ubsan_init_standalone.cc |
| 13 | ) |
| 14 | |
Richard Smith | 3e587a4 | 2013-03-20 23:49:17 +0000 | [diff] [blame] | 15 | set(UBSAN_CXX_SOURCES |
Richard Smith | eda8bd0 | 2012-10-25 02:07:02 +0000 | [diff] [blame] | 16 | ubsan_handlers_cxx.cc |
| 17 | ubsan_type_hash.cc |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 18 | ) |
| 19 | |
| 20 | include_directories(..) |
| 21 | |
| 22 | set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 23 | append_no_rtti_flag(UBSAN_CFLAGS) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 24 | set(UBSAN_STANDALONE_CFLAGS ${SANITIZER_COMMON_CFLAGS}) |
| 25 | append_no_rtti_flag(UBSAN_STANDALONE_CFLAGS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 26 | set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS}) |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 27 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 28 | add_custom_target(ubsan) |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 29 | |
Alexey Samsonov | 5b16dba | 2012-11-16 12:57:07 +0000 | [diff] [blame] | 30 | if(APPLE) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 31 | # Common parts of UBSan runtime. |
| 32 | add_compiler_rt_object_libraries(RTUbsan |
| 33 | OS ${SANITIZER_COMMON_SUPPORTED_OS} |
| 34 | ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} |
| 35 | SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES} |
| 36 | CFLAGS ${UBSAN_CXXFLAGS}) |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 37 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 38 | if(COMPILER_RT_HAS_UBSAN) |
| 39 | # Initializer of standalone UBSan runtime. |
| 40 | add_compiler_rt_object_libraries(RTUbsan_standalone |
| 41 | OS ${SANITIZER_COMMON_SUPPORTED_OS} |
| 42 | ARCH ${UBSAN_SUPPORTED_ARCH} |
| 43 | SOURCES ${UBSAN_STANDALONE_SOURCES} |
| 44 | CFLAGS ${UBSAN_STANDALONE_CFLAGS}) |
| 45 | foreach(os ${SANITIZER_COMMON_SUPPORTED_OS}) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 46 | add_compiler_rt_darwin_dynamic_runtime(clang_rt.ubsan_${os}_dynamic ${os} |
| 47 | ARCH ${UBSAN_SUPPORTED_ARCH} |
| 48 | SOURCES $<TARGET_OBJECTS:RTUbsan.${os}> |
| 49 | $<TARGET_OBJECTS:RTUbsan_standalone.${os}> |
| 50 | $<TARGET_OBJECTS:RTSanitizerCommon.${os}>) |
| 51 | |
| 52 | add_dependencies(ubsan clang_rt.ubsan_${os}_dynamic) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 53 | endforeach() |
| 54 | endif() |
| 55 | |
Alexey Samsonov | 5b16dba | 2012-11-16 12:57:07 +0000 | [diff] [blame] | 56 | else() |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 57 | # Common parts of UBSan runtime. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 58 | add_compiler_rt_object_libraries(RTUbsan |
| 59 | ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} |
| 60 | SOURCES ${UBSAN_SOURCES} CFLAGS ${UBSAN_CFLAGS}) |
| 61 | # C++-specific parts of UBSan runtime. Requires a C++ ABI library. |
| 62 | add_compiler_rt_object_libraries(RTUbsan_cxx |
| 63 | ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} |
| 64 | SOURCES ${UBSAN_CXX_SOURCES} CFLAGS ${UBSAN_CXXFLAGS}) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 65 | |
| 66 | if(COMPILER_RT_HAS_UBSAN) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 67 | # Initializer of standalone UBSan runtime. |
| 68 | add_compiler_rt_object_libraries(RTUbsan_standalone |
| 69 | ARCH ${UBSAN_SUPPORTED_ARCH} |
| 70 | SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) |
| 71 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 72 | foreach(arch ${UBSAN_SUPPORTED_ARCH}) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 73 | # Standalone UBSan runtimes. |
| 74 | add_compiler_rt_runtime(clang_rt.ubsan_standalone-${arch} ${arch} STATIC |
| 75 | SOURCES $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 76 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
| 77 | $<TARGET_OBJECTS:RTUbsan.${arch}> |
| 78 | $<TARGET_OBJECTS:RTUbsan_standalone.${arch}> |
| 79 | CFLAGS ${UBSAN_CFLAGS}) |
| 80 | add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx-${arch} ${arch} STATIC |
| 81 | SOURCES $<TARGET_OBJECTS:RTUbsan_cxx.${arch}> |
| 82 | CFLAGS ${UBSAN_CXXFLAGS}) |
| 83 | |
| 84 | add_dependencies(ubsan |
| 85 | clang_rt.ubsan_standalone-${arch} |
| 86 | clang_rt.ubsan_standalone_cxx-${arch}) |
| 87 | if (UNIX AND NOT ${arch} MATCHES "i386|i686") |
| 88 | add_sanitizer_rt_symbols(clang_rt.ubsan_standalone-${arch} ubsan.syms.extra) |
| 89 | add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx-${arch} ubsan.syms.extra) |
| 90 | add_dependencies(ubsan |
| 91 | clang_rt.ubsan_standalone-${arch}-symbols |
| 92 | clang_rt.ubsan_standalone_cxx-${arch}-symbols) |
| 93 | endif() |
| 94 | endforeach() |
| 95 | endif() |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 96 | endif() |
| 97 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 98 | add_dependencies(compiler-rt ubsan) |