• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Build for all components of the XRay runtime support library.
2
3# XRay runtime library implementation files.
4set(XRAY_SOURCES
5  xray_buffer_queue.cpp
6  xray_init.cpp
7  xray_flags.cpp
8  xray_interface.cpp
9  xray_log_interface.cpp
10  xray_utils.cpp
11  )
12
13# Implementation files for all XRay modes.
14set(XRAY_FDR_MODE_SOURCES
15  xray_fdr_flags.cpp
16  xray_fdr_logging.cpp
17  )
18
19set(XRAY_BASIC_MODE_SOURCES
20  xray_basic_flags.cpp
21  xray_basic_logging.cpp
22  )
23
24set(XRAY_PROFILING_MODE_SOURCES
25  xray_profile_collector.cpp
26  xray_profiling.cpp
27  xray_profiling_flags.cpp
28  )
29
30# Implementation files for all XRay architectures.
31set(x86_64_SOURCES
32  xray_x86_64.cpp
33  xray_trampoline_x86_64.S
34  )
35
36set(arm_SOURCES
37  xray_arm.cpp
38  xray_trampoline_arm.S
39  )
40
41set(armhf_SOURCES
42  ${arm_SOURCES}
43  )
44
45set(aarch64_SOURCES
46  xray_AArch64.cpp
47  xray_trampoline_AArch64.S
48  )
49
50set(mips_SOURCES
51  xray_mips.cpp
52  xray_trampoline_mips.S
53  )
54
55set(mipsel_SOURCES
56  xray_mips.cpp
57  xray_trampoline_mips.S
58  )
59
60set(mips64_SOURCES
61  xray_mips64.cpp
62  xray_trampoline_mips64.S
63  )
64
65set(mips64el_SOURCES
66  xray_mips64.cpp
67  xray_trampoline_mips64.S
68  )
69
70set(powerpc64le_SOURCES
71  xray_powerpc64.cpp
72  xray_trampoline_powerpc64.cpp
73  xray_trampoline_powerpc64_asm.S
74  )
75
76set(XRAY_IMPL_HEADERS
77  xray_allocator.h
78  xray_basic_flags.h
79  xray_basic_flags.inc
80  xray_basic_logging.h
81  xray_buffer_queue.h
82  xray_defs.h
83  xray_fdr_controller.h
84  xray_fdr_flags.h
85  xray_fdr_flags.inc
86  xray_fdr_log_records.h
87  xray_fdr_log_writer.h
88  xray_fdr_logging.h
89  xray_flags.h
90  xray_flags.inc
91  xray_function_call_trie.h
92  xray_interface_internal.h
93  xray_powerpc64.inc
94  xray_profile_collector.h
95  xray_profiling_flags.h
96  xray_profiling_flags.inc
97  xray_recursion_guard.h
98  xray_segmented_array.h
99  xray_tsc.h
100  xray_utils.h
101  xray_x86_64.inc
102  )
103
104# Create list of all source files for
105# consumption by tests.
106set(XRAY_ALL_SOURCE_FILES
107  ${XRAY_SOURCES}
108  ${XRAY_FDR_MODE_SOURCES}
109  ${XRAY_BASIC_MODE_SOURCES}
110  ${XRAY_PROFILING_MODE_SOURCES}
111  ${x86_64_SOURCES}
112  ${arm_SOURCES}
113  ${armhf_SOURCES}
114  ${mips_SOURCES}
115  ${mipsel_SOURCES}
116  ${mips64_SOURCES}
117  ${mips64el_SOURCES}
118  ${powerpc64le_SOURCES}
119  ${XRAY_IMPL_HEADERS}
120  )
121list(REMOVE_DUPLICATES XRAY_ALL_SOURCE_FILES)
122# Make list that uses absolute paths
123set(XRAY_ALL_SOURCE_FILES_ABS_PATHS "")
124foreach (src_file ${XRAY_ALL_SOURCE_FILES})
125  list(APPEND
126    XRAY_ALL_SOURCE_FILES_ABS_PATHS
127    "${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
128endforeach()
129
130
131# Now put it all together...
132include_directories(..)
133include_directories(../../include)
134
135set(XRAY_CFLAGS ${COMPILER_RT_COMMON_CFLAGS})
136set(XRAY_COMMON_DEFINITIONS XRAY_HAS_EXCEPTIONS=1)
137
138# We don't need RTTI in XRay, so turn that off.
139append_rtti_flag(OFF XRAY_CFLAGS)
140
141append_list_if(
142  COMPILER_RT_HAS_XRAY_COMPILER_FLAG XRAY_SUPPORTED=1 XRAY_COMMON_DEFINITIONS)
143append_list_if(
144  COMPILER_RT_BUILD_XRAY_NO_PREINIT XRAY_NO_PREINIT XRAY_COMMON_DEFINITIONS)
145
146add_compiler_rt_component(xray)
147
148set(XRAY_COMMON_RUNTIME_OBJECT_LIBS
149    RTSanitizerCommon
150    RTSanitizerCommonLibc)
151
152# XRay uses C++ standard library headers.
153if (TARGET cxx-headers OR HAVE_LIBCXX)
154  set(XRAY_DEPS cxx-headers)
155endif()
156
157if (APPLE)
158  set(XRAY_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS})
159  add_asm_sources(XRAY_ASM_SOURCES xray_trampoline_x86_64.S)
160
161  add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
162  add_weak_symbols("xray" WEAK_SYMBOL_LINK_FLAGS)
163
164  add_compiler_rt_object_libraries(RTXray
165    OS ${XRAY_SUPPORTED_OS}
166    ARCHS ${XRAY_SUPPORTED_ARCH}
167    SOURCES ${XRAY_SOURCES} ${x86_64_SOURCES}
168    ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
169    CFLAGS ${XRAY_CFLAGS}
170    DEFS ${XRAY_COMMON_DEFINITIONS}
171    DEPS ${XRAY_DEPS})
172  add_compiler_rt_object_libraries(RTXrayFDR
173    OS ${XRAY_SUPPORTED_OS}
174    ARCHS ${XRAY_SUPPORTED_ARCH}
175    SOURCES ${XRAY_FDR_MODE_SOURCES}
176    ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
177    CFLAGS ${XRAY_CFLAGS}
178    DEFS ${XRAY_COMMON_DEFINITIONS}
179    DEPS ${XRAY_DEPS})
180  add_compiler_rt_object_libraries(RTXrayBASIC
181    OS ${XRAY_SUPPORTED_OS}
182    ARCHS ${XRAY_SUPPORTED_ARCH}
183    SOURCES ${XRAY_BASIC_MODE_SOURCES}
184    ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
185    CFLAGS ${XRAY_CFLAGS}
186    DEFS ${XRAY_COMMON_DEFINITIONS}
187    DEPS ${XRAY_DEPS})
188  add_compiler_rt_object_libraries(RTXrayPROFILING
189    OS ${XRAY_SUPPORTED_OS}
190    ARCHS ${XRAY_SUPPORTED_ARCH}
191    SOURCES ${XRAY_PROFILING_MODE_SOURCES}
192    ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
193    CFLAGS ${XRAY_CFLAGS}
194    DEFS ${XRAY_COMMON_DEFINITIONS}
195    DEPS ${XRAY_DEPS})
196
197  # We only support running on osx for now.
198  add_compiler_rt_runtime(clang_rt.xray
199    STATIC
200    OS ${XRAY_SUPPORTED_OS}
201    ARCHS ${XRAY_SUPPORTED_ARCH}
202    OBJECT_LIBS RTXray
203                RTSanitizerCommon
204                RTSanitizerCommonLibc
205    CFLAGS ${XRAY_CFLAGS}
206    DEFS ${XRAY_COMMON_DEFINITIONS}
207    LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
208    LINK_LIBS ${XRAY_LINK_LIBS}
209    PARENT_TARGET xray)
210  add_compiler_rt_runtime(clang_rt.xray-fdr
211    STATIC
212    OS ${XRAY_SUPPORTED_OS}
213    ARCHS ${XRAY_SUPPORTED_ARCH}
214    OBJECT_LIBS RTXrayFDR
215    CFLAGS ${XRAY_CFLAGS}
216    DEFS ${XRAY_COMMON_DEFINITIONS}
217    LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
218    LINK_LIBS ${XRAY_LINK_LIBS}
219    PARENT_TARGET xray)
220  add_compiler_rt_runtime(clang_rt.xray-basic
221    STATIC
222    OS ${XRAY_SUPPORTED_OS}
223    ARCHS ${XRAY_SUPPORTED_ARCH}
224    OBJECT_LIBS RTXrayBASIC
225    CFLAGS ${XRAY_CFLAGS}
226    DEFS ${XRAY_COMMON_DEFINITIONS}
227    LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
228    LINK_LIBS ${XRAY_LINK_LIBS}
229    PARENT_TARGET xray)
230  add_compiler_rt_runtime(clang_rt.xray-profiling
231    STATIC
232    OS ${XRAY_SUPPORTED_OS}
233    ARCHS ${XRAY_SUPPORTED_ARCH}
234    OBJECT_LIBS RTXrayPROFILING
235    CFLAGS ${XRAY_CFLAGS}
236    DEFS ${XRAY_COMMON_DEFINITIONS}
237    LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
238    LINK_LIBS ${XRAY_LINK_LIBS}
239    PARENT_TARGET xray)
240else() # not Apple
241  foreach(arch ${XRAY_SUPPORTED_ARCH})
242    if(NOT CAN_TARGET_${arch})
243      continue()
244    endif()
245    add_compiler_rt_object_libraries(RTXray
246      ARCHS ${arch}
247      SOURCES ${XRAY_SOURCES} ${${arch}_SOURCES}
248      ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
249      CFLAGS ${XRAY_CFLAGS}
250      DEFS ${XRAY_COMMON_DEFINITIONS}
251      DEPS ${XRAY_DEPS})
252    add_compiler_rt_object_libraries(RTXrayFDR
253      ARCHS ${arch}
254      SOURCES ${XRAY_FDR_MODE_SOURCES}
255      ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
256      CFLAGS ${XRAY_CFLAGS}
257      DEFS ${XRAY_COMMON_DEFINITIONS}
258      DEPS ${XRAY_DEPS})
259    add_compiler_rt_object_libraries(RTXrayBASIC
260      ARCHS ${arch}
261      SOURCES ${XRAY_BASIC_MODE_SOURCES}
262      ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
263      CFLAGS ${XRAY_CFLAGS}
264      DEFS ${XRAY_COMMON_DEFINITIONS}
265      DEPS ${XRAY_DEPS})
266    add_compiler_rt_object_libraries(RTXrayPROFILING
267      ARCHS ${arch}
268      SOURCES ${XRAY_PROFILING_MODE_SOURCES}
269      ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
270      CFLAGS ${XRAY_CFLAGS}
271      DEFS ${XRAY_COMMON_DEFINITIONS}
272      DEPS ${XRAY_DEPS})
273
274    # Common XRay archive for instrumented binaries.
275    add_compiler_rt_runtime(clang_rt.xray
276     STATIC
277     ARCHS ${arch}
278     CFLAGS ${XRAY_CFLAGS}
279     DEFS ${XRAY_COMMON_DEFINITIONS}
280     OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS} RTXray
281     PARENT_TARGET xray)
282    # FDR mode runtime archive (addon for clang_rt.xray)
283    add_compiler_rt_runtime(clang_rt.xray-fdr
284      STATIC
285      ARCHS ${arch}
286      CFLAGS ${XRAY_CFLAGS}
287      DEFS ${XRAY_COMMON_DEFINITIONS}
288      OBJECT_LIBS RTXrayFDR
289      PARENT_TARGET xray)
290    # Basic mode runtime archive (addon for clang_rt.xray)
291    add_compiler_rt_runtime(clang_rt.xray-basic
292      STATIC
293      ARCHS ${arch}
294      CFLAGS ${XRAY_CFLAGS}
295      DEFS ${XRAY_COMMON_DEFINITIONS}
296      OBJECT_LIBS RTXrayBASIC
297      PARENT_TARGET xray)
298   # Profiler Mode runtime
299   add_compiler_rt_runtime(clang_rt.xray-profiling
300     STATIC
301     ARCHS ${arch}
302     CFLAGS ${XRAY_CFLAGS}
303     DEFS ${XRAY_COMMON_DEFINITIONS}
304     OBJECT_LIBS RTXrayPROFILING
305     PARENT_TARGET xray)
306  endforeach()
307endif() # not Apple
308
309if(COMPILER_RT_INCLUDE_TESTS)
310  add_subdirectory(tests)
311endif()
312