[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / hwasan / CMakeLists.txt
blob1f0aa0b2777f75fbf74ef32f9f6ef730a9a4dc13
1 include_directories(..)
3 # Runtime library sources and build flags.
4 set(HWASAN_RTL_SOURCES
5   hwasan.cpp
6   hwasan_allocator.cpp
7   hwasan_allocation_functions.cpp
8   hwasan_dynamic_shadow.cpp
9   hwasan_exceptions.cpp
10   hwasan_fuchsia.cpp
11   hwasan_globals.cpp
12   hwasan_interceptors.cpp
13   hwasan_interceptors_vfork.S
14   hwasan_linux.cpp
15   hwasan_memintrinsics.cpp
16   hwasan_poisoning.cpp
17   hwasan_report.cpp
18   hwasan_setjmp_aarch64.S
19   hwasan_setjmp_x86_64.S
20   hwasan_tag_mismatch_aarch64.S
21   hwasan_thread.cpp
22   hwasan_thread_list.cpp
23   hwasan_type_test.cpp
24   )
26 set(HWASAN_RTL_CXX_SOURCES
27   hwasan_new_delete.cpp
28   )
30 set(HWASAN_RTL_PREINIT_SOURCES
31   hwasan_preinit.cpp
32   )
34 set(HWASAN_RTL_HEADERS
35   hwasan.h
36   hwasan_allocator.h
37   hwasan_dynamic_shadow.h
38   hwasan_flags.h
39   hwasan_flags.inc
40   hwasan_globals.h
41   hwasan_interface_internal.h
42   hwasan_malloc_bisect.h
43   hwasan_mapping.h
44   hwasan_poisoning.h
45   hwasan_report.h
46   hwasan_thread.h
47   hwasan_thread_list.h
48   )
50 set(HWASAN_DEFINITIONS)
51 append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)
53 if(FUCHSIA)
54   # Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS.
55   list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1)
56 endif()
58 set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
59 append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
60 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
61 # Prevent clang from generating libc calls.
62 append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS)
64 # Too many existing bugs, needs cleanup.
65 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format HWASAN_RTL_CFLAGS)
67 set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
69 if(ANDROID)
70 # Put most Sanitizer shared libraries in the global group. For more details, see
71 # android-changes-for-ndk-developers.md#changes-to-library-search-order
72   if (COMPILER_RT_HAS_Z_GLOBAL)
73     list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
74   endif()
75 endif()
77 set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
78 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
79   -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)
80 append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS)
82 set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})
84 append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS)
85 append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
86 append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
87 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)
89 # Static runtime library.
90 add_compiler_rt_component(hwasan)
92 add_compiler_rt_object_libraries(RTHwasan
93   ARCHS ${HWASAN_SUPPORTED_ARCH}
94   SOURCES ${HWASAN_RTL_SOURCES}
95   ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
96   CFLAGS ${HWASAN_RTL_CFLAGS}
97   DEFS ${HWASAN_DEFINITIONS})
98 add_compiler_rt_object_libraries(RTHwasan_cxx
99   ARCHS ${HWASAN_SUPPORTED_ARCH}
100   SOURCES ${HWASAN_RTL_CXX_SOURCES}
101   ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
102   CFLAGS ${HWASAN_RTL_CFLAGS}
103   DEFS ${HWASAN_DEFINITIONS})
104 add_compiler_rt_object_libraries(RTHwasan_dynamic
105   ARCHS ${HWASAN_SUPPORTED_ARCH}
106   SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
107   ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
108   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
109   DEFS ${HWASAN_DEFINITIONS})
110 add_compiler_rt_object_libraries(RTHwasan_preinit
111   ARCHS ${HWASAN_SUPPORTED_ARCH}
112   SOURCES ${HWASAN_RTL_PREINIT_SOURCES}
113   ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
114   CFLAGS ${HWASAN_RTL_CFLAGS}
115   DEFS ${HWASAN_DEFINITIONS})
117 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
118 add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
119   ARCHS ${HWASAN_SUPPORTED_ARCH}
120   SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
121   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
122   DEFS ${HWASAN_DEFINITIONS})
124 # If use_aliases is TRUE, adds the HWASan runtime built with alias support.
125 # Otherwise adds the runtime without alias support.
126 function(add_hwasan_runtimes arch use_aliases)
127   set(hwasan_object_lib RTHwasan)
128   set(hwasan_object_dyn_lib RTHwasan_dynamic)
129   set(hwasan_runtime clang_rt.hwasan)
130   set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
131   set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
132   if(use_aliases)
133     list(APPEND hwasan_rtl_flags -DHWASAN_ALIASING_MODE)
134     list(APPEND hwasan_dyn_flags -DHWASAN_ALIASING_MODE)
135     add_compiler_rt_object_libraries(RTHwasanAliases
136       ARCHS ${arch}
137       SOURCES ${HWASAN_RTL_SOURCES}
138       ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
139       CFLAGS ${hwasan_rtl_flags}
140       DEFS ${HWASAN_DEFINITIONS})
141     add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
142       ARCHS ${arch}
143       SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
144       ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
145       CFLAGS ${hwasan_dyn_flags}
146       DEFS ${HWASAN_DEFINITIONS})
148     set(hwasan_object_lib RTHwasanAliases)
149     set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
150     set(hwasan_runtime clang_rt.hwasan_aliases)
151   endif()
152   add_compiler_rt_runtime(${hwasan_runtime}
153     STATIC
154     ARCHS ${arch}
155     OBJECT_LIBS ${hwasan_object_lib}
156                 RTHwasan_preinit
157                 RTInterception
158                 RTSanitizerCommon
159                 RTSanitizerCommonLibc
160                 RTSanitizerCommonCoverage
161                 RTSanitizerCommonSymbolizer
162                 RTUbsan
163     CFLAGS ${hwasan_rtl_flags}
164     PARENT_TARGET hwasan)
165   add_compiler_rt_runtime(${hwasan_runtime}_cxx
166     STATIC
167     ARCHS ${arch}
168     OBJECT_LIBS RTHwasan_cxx
169                 RTUbsan_cxx
170     CFLAGS ${hwasan_rtl_flags}
171     PARENT_TARGET hwasan)
173   if (UNIX)
174     add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch}
175                                   LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch}
176                                   EXTRA hwasan.syms.extra)
177     set(VERSION_SCRIPT_FLAG
178          -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
179     set_property(SOURCE
180       ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
181       APPEND PROPERTY
182       OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
183   else()
184     set(VERSION_SCRIPT_FLAG)
185   endif()
188   add_compiler_rt_runtime(${hwasan_runtime}
189     SHARED
190     ARCHS ${arch}
191     OBJECT_LIBS
192             ${hwasan_object_dyn_lib}
193             RTInterception
194             RTSanitizerCommon
195             RTSanitizerCommonLibc
196             RTSanitizerCommonCoverage
197             RTSanitizerCommonSymbolizer
198             RTUbsan
199             RTUbsan_cxx
200             # The only purpose of RTHWAsan_dynamic_version_script_dummy is to
201             # carry a dependency of the shared runtime on the version script.
202             # Replacing it with a straightforward
203             # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
204             # generates an order-only dependency in ninja.
205             RTHwasan_dynamic_version_script_dummy
206     CFLAGS ${hwasan_dyn_flags}
207     LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS}
208               ${VERSION_SCRIPT_FLAG}
209     LINK_LIBS ${HWASAN_DYNAMIC_LIBS}
210     DEFS ${ASAN_DYNAMIC_DEFINITIONS}
211     PARENT_TARGET hwasan)
213   if(SANITIZER_USE_SYMBOLS)
214     add_sanitizer_rt_symbols(${hwasan_runtime}
215       ARCHS ${arch}
216       EXTRA hwasan.syms.extra)
217     add_sanitizer_rt_symbols(${hwasan_runtime}_cxx
218       ARCHS ${arch}
219       EXTRA hwasan.syms.extra)
220     add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols
221                           ${hwasan_runtime}_cxx-${arch}-symbols)
222   endif()
223 endfunction()
225 foreach(arch ${HWASAN_SUPPORTED_ARCH})
226   add_hwasan_runtimes(${arch} FALSE)
227   if(${arch} MATCHES "x86_64")
228     add_hwasan_runtimes(${arch} TRUE)
229   endif()
230 endforeach()
232 add_compiler_rt_runtime(clang_rt.hwasan-preinit
233   STATIC
234   ARCHS ${HWASAN_SUPPORTED_ARCH}
235   OBJECT_LIBS RTHwasan_preinit
236   CFLAGS ${HWASAN_RTL_CFLAGS}
237   PARENT_TARGET hwasan)
239 add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan)
241 add_subdirectory("scripts")
243 # if(COMPILER_RT_INCLUDE_TESTS)
244 #   add_subdirectory(tests)
245 # endif()