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