1 # Build for all components of the XRay runtime support library.
3 # XRay runtime library implementation files.
17 # Implementation files for all XRay modes.
18 set(XRAY_FDR_MODE_SOURCES
23 set(XRAY_BASIC_MODE_SOURCES
25 xray_basic_logging.cpp
28 set(XRAY_PROFILING_MODE_SOURCES
29 xray_profile_collector.cpp
31 xray_profiling_flags.cpp
34 # Implementation files for all XRay architectures.
37 xray_trampoline_x86_64.S
40 set(x86_64_DSO_SOURCES
41 xray_trampoline_x86_64.S
56 xray_trampoline_AArch64.S
59 set(aarch64_DSO_SOURCES
60 xray_trampoline_AArch64.S
63 set(loongarch64_SOURCES
65 xray_trampoline_loongarch64.S
70 xray_trampoline_mips.S
75 xray_trampoline_mips.S
80 xray_trampoline_mips64.S
85 xray_trampoline_mips64.S
88 set(powerpc64le_SOURCES
90 xray_trampoline_powerpc64.cpp
91 xray_trampoline_powerpc64_asm.S
96 xray_trampoline_hexagon.S
101 xray_trampoline_riscv32.S
106 xray_trampoline_riscv64.S
109 set(XRAY_SOURCE_ARCHS
122 set(XRAY_IMPL_HEADERS
129 xray_fdr_controller.h
132 xray_fdr_log_records.h
133 xray_fdr_log_writer.h
137 xray_function_call_trie.h
138 xray_interface_internal.h
140 xray_profile_collector.h
141 xray_profiling_flags.h
142 xray_profiling_flags.inc
143 xray_recursion_guard.h
144 xray_segmented_array.h
150 # Create list of all source files for
151 # consumption by tests.
152 set(XRAY_ALL_SOURCE_FILES
155 ${XRAY_FDR_MODE_SOURCES}
156 ${XRAY_BASIC_MODE_SOURCES}
157 ${XRAY_PROFILING_MODE_SOURCES}
159 ${x86_64_DSO_SOURCES}
163 ${loongarch64_SOURCES}
168 ${powerpc64le_SOURCES}
173 list(REMOVE_DUPLICATES XRAY_ALL_SOURCE_FILES)
174 # Make list that uses absolute paths
175 set(XRAY_ALL_SOURCE_FILES_ABS_PATHS "")
176 foreach (src_file ${XRAY_ALL_SOURCE_FILES})
178 XRAY_ALL_SOURCE_FILES_ABS_PATHS
179 "${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
183 # Now put it all together...
184 include_directories(..)
185 include_directories(../../include)
188 ${COMPILER_RT_COMMON_CFLAGS}
189 ${COMPILER_RT_CXX_CFLAGS})
190 set(XRAY_COMMON_DEFINITIONS SANITIZER_COMMON_NO_REDEFINE_BUILTINS XRAY_HAS_EXCEPTIONS=1)
192 # DSO trampolines need to be compiled with GOT addressing
193 set(XRAY_COMMON_DEFINITIONS_DSO ${XRAY_COMMON_DEFINITIONS} XRAY_PIC)
195 # Too many existing bugs, needs cleanup.
196 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format XRAY_CFLAGS)
198 # We don't need RTTI in XRay, so turn that off.
199 append_rtti_flag(OFF XRAY_CFLAGS)
201 set(XRAY_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS})
203 ${COMPILER_RT_UNWINDER_LINK_LIBS}
204 ${COMPILER_RT_CXX_LINK_LIBS})
207 COMPILER_RT_HAS_XRAY_COMPILER_FLAG XRAY_SUPPORTED=1 XRAY_COMMON_DEFINITIONS)
209 COMPILER_RT_BUILD_XRAY_NO_PREINIT XRAY_NO_PREINIT XRAY_COMMON_DEFINITIONS)
211 add_compiler_rt_component(xray)
213 set(XRAY_COMMON_RUNTIME_OBJECT_LIBS
215 RTSanitizerCommonLibc)
217 # XRay uses C++ standard library headers.
218 if (TARGET cxx-headers OR HAVE_LIBCXX)
219 set(XRAY_DEPS cxx-headers)
223 add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
224 add_weak_symbols("xray" WEAK_SYMBOL_LINK_FLAGS)
226 add_compiler_rt_object_libraries(RTXray
227 OS ${XRAY_SUPPORTED_OS}
228 ARCHS ${XRAY_SUPPORTED_ARCH}
229 SOURCES ${XRAY_SOURCES}
230 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
231 CFLAGS ${XRAY_CFLAGS}
232 DEFS ${XRAY_COMMON_DEFINITIONS}
234 add_compiler_rt_object_libraries(RTXrayDSO
235 OS ${XRAY_SUPPORTED_OS}
236 ARCHS ${XRAY_DSO_SUPPORTED_ARCH}
237 SOURCES ${XRAY_DSO_SOURCES}
238 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
239 CFLAGS ${XRAY_CFLAGS}
240 DEFS ${XRAY_COMMON_DEFINITIONS_DSO}
242 set(XRAY_RTXRAY_ARCH_LIBS "")
243 set(XRAY_DSO_RTXRAY_ARCH_LIBS "")
244 foreach(arch ${XRAY_SUPPORTED_ARCH})
245 if(NOT ${arch} IN_LIST XRAY_SOURCE_ARCHS)
248 add_compiler_rt_object_libraries(RTXray_${arch}
249 OS ${XRAY_SUPPORTED_OS}
251 SOURCES ${${arch}_SOURCES}
252 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
253 CFLAGS ${XRAY_CFLAGS}
254 DEFS ${XRAY_COMMON_DEFINITIONS}
256 list(APPEND XRAY_RTXRAY_ARCH_LIBS RTXray_${arch})
257 if (${arch} IN_LIST XRAY_DSO_SUPPORTED_ARCH)
258 add_compiler_rt_object_libraries(RTXrayDSO_${arch}
259 OS ${XRAY_SUPPORTED_OS}
261 SOURCES ${${arch}_DSO_SOURCES}
262 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
263 CFLAGS ${XRAY_CFLAGS}
264 DEFS ${XRAY_COMMON_DEFINITIONS_DSO}
266 list(APPEND XRAY_DSO_RTXRAY_ARCH_LIBS RTXrayDSO_${arch})
269 add_compiler_rt_object_libraries(RTXrayFDR
270 OS ${XRAY_SUPPORTED_OS}
271 ARCHS ${XRAY_SUPPORTED_ARCH}
272 SOURCES ${XRAY_FDR_MODE_SOURCES}
273 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
274 CFLAGS ${XRAY_CFLAGS}
275 DEFS ${XRAY_COMMON_DEFINITIONS}
277 add_compiler_rt_object_libraries(RTXrayBASIC
278 OS ${XRAY_SUPPORTED_OS}
279 ARCHS ${XRAY_SUPPORTED_ARCH}
280 SOURCES ${XRAY_BASIC_MODE_SOURCES}
281 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
282 CFLAGS ${XRAY_CFLAGS}
283 DEFS ${XRAY_COMMON_DEFINITIONS}
285 add_compiler_rt_object_libraries(RTXrayPROFILING
286 OS ${XRAY_SUPPORTED_OS}
287 ARCHS ${XRAY_SUPPORTED_ARCH}
288 SOURCES ${XRAY_PROFILING_MODE_SOURCES}
289 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
290 CFLAGS ${XRAY_CFLAGS}
291 DEFS ${XRAY_COMMON_DEFINITIONS}
294 # We only support running on osx for now.
295 add_compiler_rt_runtime(clang_rt.xray
297 OS ${XRAY_SUPPORTED_OS}
298 ARCHS ${XRAY_SUPPORTED_ARCH}
299 OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS} RTXray ${XRAY_RTXRAY_ARCH_LIBS}
300 CFLAGS ${XRAY_CFLAGS}
301 DEFS ${XRAY_COMMON_DEFINITIONS}
302 LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
303 LINK_LIBS ${XRAY_LINK_LIBS}
305 add_compiler_rt_runtime(clang_rt.xray-dso
307 OS ${XRAY_SUPPORTED_OS}
308 ARCHS ${XRAY_DSO_SUPPORTED_ARCH}
309 OBJECT_LIBS RTXrayDSO ${XRAY_DSO_RTXRAY_ARCH_LIBS}
310 CFLAGS ${XRAY_CFLAGS}
311 DEFS ${XRAY_COMMON_DEFINITIONS}
312 LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
313 LINK_LIBS ${XRAY_LINK_LIBS}
316 add_compiler_rt_runtime(clang_rt.xray-fdr
318 OS ${XRAY_SUPPORTED_OS}
319 ARCHS ${XRAY_SUPPORTED_ARCH}
320 OBJECT_LIBS RTXrayFDR
321 CFLAGS ${XRAY_CFLAGS}
322 DEFS ${XRAY_COMMON_DEFINITIONS}
323 LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
324 LINK_LIBS ${XRAY_LINK_LIBS}
326 add_compiler_rt_runtime(clang_rt.xray-basic
328 OS ${XRAY_SUPPORTED_OS}
329 ARCHS ${XRAY_SUPPORTED_ARCH}
330 OBJECT_LIBS RTXrayBASIC
331 CFLAGS ${XRAY_CFLAGS}
332 DEFS ${XRAY_COMMON_DEFINITIONS}
333 LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
334 LINK_LIBS ${XRAY_LINK_LIBS}
336 add_compiler_rt_runtime(clang_rt.xray-profiling
338 OS ${XRAY_SUPPORTED_OS}
339 ARCHS ${XRAY_SUPPORTED_ARCH}
340 OBJECT_LIBS RTXrayPROFILING
341 CFLAGS ${XRAY_CFLAGS}
342 DEFS ${XRAY_COMMON_DEFINITIONS}
343 LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
344 LINK_LIBS ${XRAY_LINK_LIBS}
347 foreach(arch ${XRAY_SUPPORTED_ARCH})
348 if(NOT CAN_TARGET_${arch})
351 add_compiler_rt_object_libraries(RTXray
353 SOURCES ${XRAY_SOURCES} ${${arch}_SOURCES}
354 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
355 CFLAGS ${XRAY_CFLAGS}
356 DEFS ${XRAY_COMMON_DEFINITIONS}
358 add_compiler_rt_object_libraries(RTXrayFDR
360 SOURCES ${XRAY_FDR_MODE_SOURCES}
361 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
362 CFLAGS ${XRAY_CFLAGS}
363 DEFS ${XRAY_COMMON_DEFINITIONS}
365 add_compiler_rt_object_libraries(RTXrayBASIC
367 SOURCES ${XRAY_BASIC_MODE_SOURCES}
368 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
369 CFLAGS ${XRAY_CFLAGS}
370 DEFS ${XRAY_COMMON_DEFINITIONS}
372 add_compiler_rt_object_libraries(RTXrayPROFILING
374 SOURCES ${XRAY_PROFILING_MODE_SOURCES}
375 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
376 CFLAGS ${XRAY_CFLAGS}
377 DEFS ${XRAY_COMMON_DEFINITIONS}
380 # Common XRay archive for instrumented binaries.
381 add_compiler_rt_runtime(clang_rt.xray
384 CFLAGS ${XRAY_CFLAGS}
385 LINK_FLAGS ${XRAY_LINK_FLAGS}
386 LINK_LIBS ${XRAY_LINK_LIBS}
387 DEFS ${XRAY_COMMON_DEFINITIONS}
388 OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS} RTXray
390 # FDR mode runtime archive (addon for clang_rt.xray)
391 add_compiler_rt_runtime(clang_rt.xray-fdr
394 CFLAGS ${XRAY_CFLAGS}
395 LINK_FLAGS ${XRAY_LINK_FLAGS}
396 LINK_LIBS ${XRAY_LINK_LIBS}
397 DEFS ${XRAY_COMMON_DEFINITIONS}
398 OBJECT_LIBS RTXrayFDR
400 # Basic mode runtime archive (addon for clang_rt.xray)
401 add_compiler_rt_runtime(clang_rt.xray-basic
404 CFLAGS ${XRAY_CFLAGS}
405 LINK_FLAGS ${XRAY_LINK_FLAGS}
406 LINK_LIBS ${XRAY_LINK_LIBS}
407 DEFS ${XRAY_COMMON_DEFINITIONS}
408 OBJECT_LIBS RTXrayBASIC
410 # Profiler Mode runtime
411 add_compiler_rt_runtime(clang_rt.xray-profiling
414 CFLAGS ${XRAY_CFLAGS}
415 LINK_FLAGS ${XRAY_LINK_FLAGS}
416 LINK_LIBS ${XRAY_LINK_LIBS}
417 DEFS ${XRAY_COMMON_DEFINITIONS}
418 OBJECT_LIBS RTXrayPROFILING
421 if (${arch} IN_LIST XRAY_DSO_SUPPORTED_ARCH)
422 add_compiler_rt_object_libraries(RTXrayDSO
424 SOURCES ${XRAY_DSO_SOURCES} ${${arch}_DSO_SOURCES}
425 ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
426 CFLAGS ${XRAY_CFLAGS}
427 DEFS ${XRAY_COMMON_DEFINITIONS_DSO}
429 # DSO runtime archive
430 add_compiler_rt_runtime(clang_rt.xray-dso
433 CFLAGS ${XRAY_CFLAGS}
434 LINK_FLAGS ${XRAY_LINK_FLAGS}
435 LINK_LIBS ${XRAY_LINK_LIBS}
436 DEFS ${XRAY_COMMON_DEFINITIONS}
437 OBJECT_LIBS RTXrayDSO
443 if(COMPILER_RT_INCLUDE_TESTS)
444 add_subdirectory(tests)