• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include_directories(..)
2
3# Runtime library sources and build flags.
4set(HWASAN_RTL_SOURCES
5  hwasan.cpp
6  hwasan_allocator.cpp
7  hwasan_dynamic_shadow.cpp
8  hwasan_exceptions.cpp
9  hwasan_globals.cpp
10  hwasan_interceptors.cpp
11  hwasan_interceptors_vfork.S
12  hwasan_linux.cpp
13  hwasan_memintrinsics.cpp
14  hwasan_poisoning.cpp
15  hwasan_report.cpp
16  hwasan_setjmp.S
17  hwasan_tag_mismatch_aarch64.S
18  hwasan_thread.cpp
19  hwasan_thread_list.cpp
20  hwasan_type_test.cpp
21  )
22
23set(HWASAN_RTL_CXX_SOURCES
24  hwasan_new_delete.cpp
25  )
26
27set(HWASAN_RTL_HEADERS
28  hwasan.h
29  hwasan_allocator.h
30  hwasan_dynamic_shadow.h
31  hwasan_flags.h
32  hwasan_flags.inc
33  hwasan_globals.h
34  hwasan_interface_internal.h
35  hwasan_malloc_bisect.h
36  hwasan_mapping.h
37  hwasan_poisoning.h
38  hwasan_report.h
39  hwasan_thread.h
40  hwasan_thread_list.h
41  )
42
43set(HWASAN_DEFINITIONS)
44append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)
45
46set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
47append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
48append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
49# Prevent clang from generating libc calls.
50append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS)
51
52set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
53
54if(ANDROID)
55# Put most Sanitizer shared libraries in the global group. For more details, see
56# android-changes-for-ndk-developers.md#changes-to-library-search-order
57  if (COMPILER_RT_HAS_Z_GLOBAL)
58    list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
59  endif()
60endif()
61
62set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
63append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
64  -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)
65append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS)
66
67set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})
68
69append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS)
70append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
71append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
72append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)
73
74# Static runtime library.
75add_compiler_rt_component(hwasan)
76
77add_compiler_rt_object_libraries(RTHwasan
78  ARCHS ${HWASAN_SUPPORTED_ARCH}
79  SOURCES ${HWASAN_RTL_SOURCES}
80  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
81  CFLAGS ${HWASAN_RTL_CFLAGS}
82  DEFS ${HWASAN_DEFINITIONS})
83add_compiler_rt_object_libraries(RTHwasan_cxx
84  ARCHS ${HWASAN_SUPPORTED_ARCH}
85  SOURCES ${HWASAN_RTL_CXX_SOURCES}
86  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
87  CFLAGS ${HWASAN_RTL_CFLAGS}
88  DEFS ${HWASAN_DEFINITIONS})
89add_compiler_rt_object_libraries(RTHwasan_dynamic
90  ARCHS ${HWASAN_SUPPORTED_ARCH}
91  SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
92  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
93  CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
94  DEFS ${HWASAN_DEFINITIONS})
95
96file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
97add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
98  ARCHS ${HWASAN_SUPPORTED_ARCH}
99  SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
100  CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
101  DEFS ${HWASAN_DEFINITIONS})
102
103foreach(arch ${HWASAN_SUPPORTED_ARCH})
104  add_compiler_rt_runtime(clang_rt.hwasan
105    STATIC
106    ARCHS ${arch}
107    OBJECT_LIBS RTHwasan
108                RTInterception
109                RTSanitizerCommon
110                RTSanitizerCommonLibc
111                RTSanitizerCommonCoverage
112                RTSanitizerCommonSymbolizer
113                RTUbsan
114    CFLAGS ${HWASAN_RTL_CFLAGS}
115    PARENT_TARGET hwasan)
116  add_compiler_rt_runtime(clang_rt.hwasan_cxx
117    STATIC
118    ARCHS ${arch}
119    OBJECT_LIBS RTHwasan_cxx
120                RTUbsan_cxx
121    CFLAGS ${HWASAN_RTL_CFLAGS}
122    PARENT_TARGET hwasan)
123
124  if (UNIX)
125    add_sanitizer_rt_version_list(clang_rt.hwasan-dynamic-${arch}
126                                  LIBS clang_rt.hwasan-${arch} clang_rt.hwasan_cxx-${arch}
127                                  EXTRA hwasan.syms.extra)
128    set(VERSION_SCRIPT_FLAG
129         -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.hwasan-dynamic-${arch}.vers)
130    set_property(SOURCE
131      ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
132      APPEND PROPERTY
133      OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.hwasan-dynamic-${arch}.vers)
134  else()
135    set(VERSION_SCRIPT_FLAG)
136  endif()
137
138
139  add_compiler_rt_runtime(clang_rt.hwasan
140    SHARED
141    ARCHS ${arch}
142    OBJECT_LIBS
143            RTHwasan_dynamic
144            RTInterception
145            RTSanitizerCommon
146            RTSanitizerCommonLibc
147            RTSanitizerCommonCoverage
148            RTSanitizerCommonSymbolizer
149            RTUbsan
150            RTUbsan_cxx
151            # The only purpose of RTHWAsan_dynamic_version_script_dummy is to
152            # carry a dependency of the shared runtime on the version script.
153            # Replacing it with a straightforward
154            # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
155            # generates an order-only dependency in ninja.
156            RTHwasan_dynamic_version_script_dummy
157    CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
158    LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS}
159              ${VERSION_SCRIPT_FLAG}
160    LINK_LIBS ${HWASAN_DYNAMIC_LIBS}
161    DEFS ${ASAN_DYNAMIC_DEFINITIONS}
162    PARENT_TARGET hwasan)
163
164  if(SANITIZER_USE_SYMBOLS)
165    add_sanitizer_rt_symbols(clang_rt.hwasan
166      ARCHS ${arch}
167      EXTRA hwasan.syms.extra)
168    add_sanitizer_rt_symbols(clang_rt.hwasan_cxx
169      ARCHS ${arch}
170      EXTRA hwasan.syms.extra)
171    add_dependencies(hwasan clang_rt.hwasan-${arch}-symbols
172                          clang_rt.hwasan_cxx-${arch}-symbols)
173  endif()
174endforeach()
175
176add_compiler_rt_resource_file(hwasan_blacklist hwasan_blacklist.txt hwasan)
177
178add_subdirectory("scripts")
179
180# if(COMPILER_RT_INCLUDE_TESTS)
181#   add_subdirectory(tests)
182# endif()
183