aboutsummaryrefslogtreecommitdiff
path: root/lib/ubsan/CMakeLists.txt
blob: 09c7a851e0753faab4e190f12b16136bb7ccea87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Build for the undefined behavior sanitizer runtime support library.

set(UBSAN_SOURCES
  ubsan_diag.cc
  ubsan_init.cc
  ubsan_flags.cc
  ubsan_handlers.cc
  ubsan_value.cc
  )

set(UBSAN_CXX_SOURCES
  ubsan_handlers_cxx.cc
  ubsan_type_hash.cc
  )

include_directories(..)

set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_no_rtti_flag(UBSAN_CFLAGS)
set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS})

add_custom_target(ubsan)

if(APPLE)
  # Build universal binary on APPLE.
  add_compiler_rt_osx_static_runtime(clang_rt.ubsan_osx
    ARCH ${UBSAN_SUPPORTED_ARCH}
    SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES}
            $<TARGET_OBJECTS:RTSanitizerCommon.osx>
    CFLAGS ${UBSAN_CXXFLAGS})
  add_dependencies(ubsan clang_rt.ubsan_osx)
else()
  # Build separate libraries for each target.
  foreach(arch ${UBSAN_SUPPORTED_ARCH})
    # Main UBSan runtime.
    add_compiler_rt_runtime(clang_rt.ubsan-${arch} ${arch} STATIC
      SOURCES ${UBSAN_SOURCES}
      CFLAGS ${UBSAN_CFLAGS})
    # C++-specific parts of UBSan runtime. Requires a C++ ABI library.
    add_compiler_rt_runtime(clang_rt.ubsan_cxx-${arch} ${arch} STATIC
      SOURCES ${UBSAN_CXX_SOURCES}
      CFLAGS ${UBSAN_CXXFLAGS})
    add_dependencies(ubsan
      clang_rt.san-${arch}
      clang_rt.ubsan-${arch}
      clang_rt.ubsan_cxx-${arch})
    if (UNIX AND NOT ${arch} STREQUAL "i386" AND NOT ${arch} STREQUAL "i686")
      add_sanitizer_rt_symbols(clang_rt.ubsan-${arch} ubsan.syms.extra)
      add_sanitizer_rt_symbols(clang_rt.ubsan_cxx-${arch} ubsan.syms.extra)
      add_dependencies(ubsan
        clang_rt.ubsan-${arch}-symbols
        clang_rt.ubsan_cxx-${arch}-symbols)
    endif()
  endforeach()
endif()

add_dependencies(compiler-rt ubsan)