[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / asan / CMakeLists.txt
blob0e7250a8fa10bc8da46dc322129b3798cca6fa5f
1 # Build for the AddressSanitizer runtime support library.
3 set(ASAN_SOURCES
4   asan_allocator.cpp
5   asan_activation.cpp
6   asan_debugging.cpp
7   asan_descriptions.cpp
8   asan_errors.cpp
9   asan_fake_stack.cpp
10   asan_flags.cpp
11   asan_fuchsia.cpp
12   asan_globals.cpp
13   asan_globals_win.cpp
14   asan_interceptors.cpp
15   asan_interceptors_memintrinsics.cpp
16   asan_linux.cpp
17   asan_mac.cpp
18   asan_malloc_linux.cpp
19   asan_malloc_mac.cpp
20   asan_malloc_win.cpp
21   asan_memory_profile.cpp
22   asan_poisoning.cpp
23   asan_posix.cpp
24   asan_premap_shadow.cpp
25   asan_report.cpp
26   asan_rtl.cpp
27   asan_shadow_setup.cpp
28   asan_stack.cpp
29   asan_stats.cpp
30   asan_suppressions.cpp
31   asan_thread.cpp
32   asan_win.cpp
33   )
35 if (NOT WIN32 AND NOT APPLE)
36   list(APPEND ASAN_SOURCES
37     asan_interceptors_vfork.S
38     )
39 endif()
41 set(ASAN_CXX_SOURCES
42   asan_new_delete.cpp
43   )
45 set(ASAN_STATIC_SOURCES
46   asan_rtl_static.cpp
47   )
49 if (NOT WIN32 AND NOT APPLE)
50   list(APPEND ASAN_STATIC_SOURCES
51     asan_rtl_x86_64.S
52   )
53 endif()
55 set(ASAN_PREINIT_SOURCES
56   asan_preinit.cpp
57   )
59 SET(ASAN_HEADERS
60   asan_activation.h
61   asan_activation_flags.inc
62   asan_allocator.h
63   asan_descriptions.h
64   asan_errors.h
65   asan_fake_stack.h
66   asan_flags.h
67   asan_flags.inc
68   asan_init_version.h
69   asan_interceptors.h
70   asan_interceptors_memintrinsics.h
71   asan_interface.inc
72   asan_interface_internal.h
73   asan_internal.h
74   asan_lock.h
75   asan_mapping.h
76   asan_poisoning.h
77   asan_premap_shadow.h
78   asan_report.h
79   asan_scariness_score.h
80   asan_stack.h
81   asan_stats.h
82   asan_suppressions.h
83   asan_thread.h
84   )
86 include_directories(..)
88 set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
89 set(ASAN_COMMON_DEFINITIONS ${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
91 append_rtti_flag(OFF ASAN_CFLAGS)
93 # Silence warnings in system headers with MSVC.
94 if(NOT CLANG_CL)
95   append_list_if(COMPILER_RT_HAS_EXTERNAL_FLAG "/experimental:external /external:W0 /external:anglebrackets" ASAN_CFLAGS)
96 endif()
98 # Too many existing bugs, needs cleanup.
99 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format ASAN_CFLAGS)
101 set(ASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
103 if(ANDROID)
104 # Put most Sanitizer shared libraries in the global group. For more details, see
105 # android-changes-for-ndk-developers.md#changes-to-library-search-order
106   if (COMPILER_RT_HAS_Z_GLOBAL)
107     list(APPEND ASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
108   endif()
109 endif()
111 set(ASAN_DYNAMIC_DEFINITIONS
112   ${ASAN_COMMON_DEFINITIONS} ASAN_DYNAMIC=1)
113 append_list_if(WIN32 INTERCEPTION_DYNAMIC_CRT ASAN_DYNAMIC_DEFINITIONS)
115 set(ASAN_DYNAMIC_CFLAGS ${ASAN_CFLAGS})
116 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
117   -ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS)
118 append_list_if(MSVC /DEBUG ASAN_DYNAMIC_LINK_FLAGS)
120 set(ASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})
122 append_list_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS)
123 append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS)
124 append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
125 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
126 append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
127 append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
129 # Compile ASan sources into an object library.
131 add_compiler_rt_object_libraries(RTAsan_dynamic
132   OS ${SANITIZER_COMMON_SUPPORTED_OS}
133   ARCHS ${ASAN_SUPPORTED_ARCH}
134   SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
135   ADDITIONAL_HEADERS ${ASAN_HEADERS}
136   CFLAGS ${ASAN_DYNAMIC_CFLAGS}
137   DEFS ${ASAN_DYNAMIC_DEFINITIONS})
139 if(NOT APPLE)
140   add_compiler_rt_object_libraries(RTAsan
141     ARCHS ${ASAN_SUPPORTED_ARCH}
142     SOURCES ${ASAN_SOURCES}
143     ADDITIONAL_HEADERS ${ASAN_HEADERS}
144     CFLAGS ${ASAN_CFLAGS}
145     DEFS ${ASAN_COMMON_DEFINITIONS})
146   add_compiler_rt_object_libraries(RTAsan_cxx
147     ARCHS ${ASAN_SUPPORTED_ARCH}
148     SOURCES ${ASAN_CXX_SOURCES}
149     ADDITIONAL_HEADERS ${ASAN_HEADERS}
150     CFLAGS ${ASAN_CFLAGS}
151     DEFS ${ASAN_COMMON_DEFINITIONS})
152   add_compiler_rt_object_libraries(RTAsan_static
153     ARCHS ${ASAN_SUPPORTED_ARCH}
154     SOURCES ${ASAN_STATIC_SOURCES}
155     ADDITIONAL_HEADERS ${ASAN_HEADERS}
156     CFLAGS ${ASAN_CFLAGS}
157     DEFS ${ASAN_COMMON_DEFINITIONS})
158   add_compiler_rt_object_libraries(RTAsan_preinit
159     ARCHS ${ASAN_SUPPORTED_ARCH}
160     SOURCES ${ASAN_PREINIT_SOURCES}
161     ADDITIONAL_HEADERS ${ASAN_HEADERS}
162     CFLAGS ${ASAN_CFLAGS}
163     DEFS ${ASAN_COMMON_DEFINITIONS})
165   file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
166   add_compiler_rt_object_libraries(RTAsan_dynamic_version_script_dummy
167     ARCHS ${ASAN_SUPPORTED_ARCH}
168     SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
169     CFLAGS ${ASAN_DYNAMIC_CFLAGS}
170     DEFS ${ASAN_DYNAMIC_DEFINITIONS})
171 endif()
173 # Build ASan runtimes shipped with Clang.
174 add_compiler_rt_component(asan)
176 if(APPLE)
177   add_weak_symbols("asan" WEAK_SYMBOL_LINK_FLAGS)
178   add_weak_symbols("lsan" WEAK_SYMBOL_LINK_FLAGS)
179   add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
180   add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
181   add_weak_symbols("xray" WEAK_SYMBOL_LINK_FLAGS)
183   add_compiler_rt_runtime(clang_rt.asan
184     SHARED
185     OS ${SANITIZER_COMMON_SUPPORTED_OS}
186     ARCHS ${ASAN_SUPPORTED_ARCH}
187     OBJECT_LIBS RTAsan_dynamic
188                 RTInterception
189                 RTSanitizerCommon
190                 RTSanitizerCommonLibc
191                 RTSanitizerCommonCoverage
192                 RTSanitizerCommonSymbolizer
193                 RTLSanCommon
194                 RTUbsan
195     CFLAGS ${ASAN_DYNAMIC_CFLAGS}
196     LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
197     DEFS ${ASAN_DYNAMIC_DEFINITIONS}
198     PARENT_TARGET asan)
200   add_compiler_rt_runtime(clang_rt.asan_static
201     STATIC
202     ARCHS ${ASAN_SUPPORTED_ARCH}
203     OBJECT_LIBS RTAsan_static
204     CFLAGS ${ASAN_CFLAGS}
205     DEFS ${ASAN_COMMON_DEFINITIONS}
206     PARENT_TARGET asan)
207 else()
208   # Build separate libraries for each target.
210   set(ASAN_COMMON_RUNTIME_OBJECT_LIBS
211     RTInterception
212     RTSanitizerCommon
213     RTSanitizerCommonLibc
214     RTSanitizerCommonCoverage
215     RTSanitizerCommonSymbolizer
216     RTLSanCommon
217     RTUbsan)
219   add_compiler_rt_runtime(clang_rt.asan
220     STATIC
221     ARCHS ${ASAN_SUPPORTED_ARCH}
222     OBJECT_LIBS RTAsan_preinit
223                 RTAsan
224                 ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
225     CFLAGS ${ASAN_CFLAGS}
226     DEFS ${ASAN_COMMON_DEFINITIONS}
227     PARENT_TARGET asan)
229   add_compiler_rt_runtime(clang_rt.asan_cxx
230     STATIC
231     ARCHS ${ASAN_SUPPORTED_ARCH}
232     OBJECT_LIBS RTAsan_cxx
233                 RTUbsan_cxx
234     CFLAGS ${ASAN_CFLAGS}
235     DEFS ${ASAN_COMMON_DEFINITIONS}
236     PARENT_TARGET asan)
238   add_compiler_rt_runtime(clang_rt.asan_static
239     STATIC
240     ARCHS ${ASAN_SUPPORTED_ARCH}
241     OBJECT_LIBS RTAsan_static
242     CFLAGS ${ASAN_CFLAGS}
243     DEFS ${ASAN_COMMON_DEFINITIONS}
244     PARENT_TARGET asan)
246   add_compiler_rt_runtime(clang_rt.asan-preinit
247     STATIC
248     ARCHS ${ASAN_SUPPORTED_ARCH}
249     OBJECT_LIBS RTAsan_preinit
250     CFLAGS ${ASAN_CFLAGS}
251     DEFS ${ASAN_COMMON_DEFINITIONS}
252     PARENT_TARGET asan)
254   foreach(arch ${ASAN_SUPPORTED_ARCH})
255     if (COMPILER_RT_HAS_VERSION_SCRIPT)
256       add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch}
257                                     LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch}
258                                     EXTRA asan.syms.extra)
259       set(VERSION_SCRIPT_FLAG
260            -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
261       # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
262       # but requires a special option to enable it.
263       if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
264           list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
265       endif()
266       set_property(SOURCE
267         ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
268         APPEND PROPERTY
269         OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
270     else()
271       set(VERSION_SCRIPT_FLAG)
272     endif()
274     set(ASAN_DYNAMIC_WEAK_INTERCEPTION)
275     if (WIN32)
276       add_compiler_rt_object_libraries(AsanWeakInterception
277         ${SANITIZER_COMMON_SUPPORTED_OS}
278         ARCHS ${arch}
279         SOURCES
280           asan_win_weak_interception.cpp
281         CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DYNAMIC
282         DEFS ${ASAN_COMMON_DEFINITIONS})
283       set(ASAN_DYNAMIC_WEAK_INTERCEPTION
284           AsanWeakInterception
285           UbsanWeakInterception
286           SancovWeakInterception
287           SanitizerCommonWeakInterception)
288     endif()
290     add_compiler_rt_runtime(clang_rt.asan
291       SHARED
292       ARCHS ${arch}
293       OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
294               RTAsan_dynamic
295               # The only purpose of RTAsan_dynamic_version_script_dummy is to
296               # carry a dependency of the shared runtime on the version script.
297               # Replacing it with a straightforward
298               # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
299               # generates an order-only dependency in ninja.
300               RTAsan_dynamic_version_script_dummy
301               RTUbsan_cxx
302               ${ASAN_DYNAMIC_WEAK_INTERCEPTION}
303       CFLAGS ${ASAN_DYNAMIC_CFLAGS}
304       LINK_FLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
305                 ${VERSION_SCRIPT_FLAG}
306       LINK_LIBS ${ASAN_DYNAMIC_LIBS}
307       DEFS ${ASAN_DYNAMIC_DEFINITIONS}
308       PARENT_TARGET asan)
310     if (SANITIZER_USE_SYMBOLS AND NOT ${arch} STREQUAL "i386")
311       add_sanitizer_rt_symbols(clang_rt.asan_cxx
312         ARCHS ${arch})
313       add_dependencies(asan clang_rt.asan_cxx-${arch}-symbols)
314       add_sanitizer_rt_symbols(clang_rt.asan
315         ARCHS ${arch}
316         EXTRA asan.syms.extra)
317       add_dependencies(asan clang_rt.asan-${arch}-symbols)
318     endif()
320     if (WIN32)
321       add_compiler_rt_object_libraries(AsanDllThunk
322         ${SANITIZER_COMMON_SUPPORTED_OS}
323         ARCHS ${arch}
324         SOURCES asan_globals_win.cpp
325                 asan_win_dll_thunk.cpp
326         CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DLL_THUNK
327         DEFS ${ASAN_COMMON_DEFINITIONS})
329       add_compiler_rt_runtime(clang_rt.asan_dll_thunk
330         STATIC
331         ARCHS ${arch}
332         OBJECT_LIBS AsanDllThunk
333                     UbsanDllThunk
334                     SancovDllThunk
335                     SanitizerCommonDllThunk
336         SOURCES $<TARGET_OBJECTS:RTInterception.${arch}>
337         PARENT_TARGET asan)
339       set(DYNAMIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_DYNAMIC_RUNTIME_THUNK")
340       if(MSVC)
341         list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-Zl")
342       elseif(CMAKE_C_COMPILER_ID MATCHES Clang)
343         list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-nodefaultlibs")
344       endif()
346       add_compiler_rt_object_libraries(AsanDynamicRuntimeThunk
347         ${SANITIZER_COMMON_SUPPORTED_OS}
348         ARCHS ${arch}
349         SOURCES asan_globals_win.cpp
350                 asan_win_dynamic_runtime_thunk.cpp
351         CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
352         DEFS ${ASAN_COMMON_DEFINITIONS})
354       add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk
355         STATIC
356         ARCHS ${arch}
357         OBJECT_LIBS AsanDynamicRuntimeThunk
358                     UbsanDynamicRuntimeThunk
359                     SancovDynamicRuntimeThunk
360                     SanitizerCommonDynamicRuntimeThunk
361         CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
362         DEFS ${ASAN_COMMON_DEFINITIONS}
363         PARENT_TARGET asan)
364     endif()
365   endforeach()
366 endif()
368 add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan)
370 add_subdirectory(scripts)
372 if(COMPILER_RT_INCLUDE_TESTS)
373   add_subdirectory(tests)
374 endif()