File: CMakeLists.txt

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (223 lines) | stat: -rw-r--r-- 7,388 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
include_directories(..)

# Runtime library sources and build flags.
set(HWASAN_RTL_SOURCES
  hwasan.cpp
  hwasan_allocator.cpp
  hwasan_allocation_functions.cpp
  hwasan_dynamic_shadow.cpp
  hwasan_exceptions.cpp
  hwasan_fuchsia.cpp
  hwasan_globals.cpp
  hwasan_interceptors.cpp
  hwasan_interceptors_vfork.S
  hwasan_linux.cpp
  hwasan_memintrinsics.cpp
  hwasan_poisoning.cpp
  hwasan_report.cpp
  hwasan_setjmp.S
  hwasan_tag_mismatch_aarch64.S
  hwasan_thread.cpp
  hwasan_thread_list.cpp
  hwasan_type_test.cpp
  )

set(HWASAN_RTL_CXX_SOURCES
  hwasan_new_delete.cpp
  )

set(HWASAN_RTL_HEADERS
  hwasan.h
  hwasan_allocator.h
  hwasan_dynamic_shadow.h
  hwasan_flags.h
  hwasan_flags.inc
  hwasan_globals.h
  hwasan_interface_internal.h
  hwasan_malloc_bisect.h
  hwasan_mapping.h
  hwasan_poisoning.h
  hwasan_report.h
  hwasan_thread.h
  hwasan_thread_list.h
  )

set(HWASAN_DEFINITIONS)
append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)

if(FUCHSIA)
  # Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS.
  list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1)
endif()

set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
# Prevent clang from generating libc calls.
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS)

set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})

if(ANDROID)
# Put most Sanitizer shared libraries in the global group. For more details, see
# android-changes-for-ndk-developers.md#changes-to-library-search-order
  if (COMPILER_RT_HAS_Z_GLOBAL)
    list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
  endif()
endif()

set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
  -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)
append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS)

set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})

append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)

# Static runtime library.
add_compiler_rt_component(hwasan)

add_compiler_rt_object_libraries(RTHwasan
  ARCHS ${HWASAN_SUPPORTED_ARCH}
  SOURCES ${HWASAN_RTL_SOURCES}
  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
  CFLAGS ${HWASAN_RTL_CFLAGS}
  DEFS ${HWASAN_DEFINITIONS})
add_compiler_rt_object_libraries(RTHwasan_cxx
  ARCHS ${HWASAN_SUPPORTED_ARCH}
  SOURCES ${HWASAN_RTL_CXX_SOURCES}
  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
  CFLAGS ${HWASAN_RTL_CFLAGS}
  DEFS ${HWASAN_DEFINITIONS})
add_compiler_rt_object_libraries(RTHwasan_dynamic
  ARCHS ${HWASAN_SUPPORTED_ARCH}
  SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
  CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
  DEFS ${HWASAN_DEFINITIONS})

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
  ARCHS ${HWASAN_SUPPORTED_ARCH}
  SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
  CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
  DEFS ${HWASAN_DEFINITIONS})

# If use_aliases is TRUE, adds the HWASan runtime built with alias support.
# Otherwise adds the runtime without alias support.
function(add_hwasan_runtimes arch use_aliases)
  set(hwasan_object_lib RTHwasan)
  set(hwasan_object_dyn_lib RTHwasan_dynamic)
  set(hwasan_runtime clang_rt.hwasan)
  set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
  set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
  if(use_aliases)
    list(APPEND hwasan_rtl_flags -DHWASAN_ALIASING_MODE)
    list(APPEND hwasan_dyn_flags -DHWASAN_ALIASING_MODE)
    add_compiler_rt_object_libraries(RTHwasanAliases
      ARCHS ${arch}
      SOURCES ${HWASAN_RTL_SOURCES}
      ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
      CFLAGS ${hwasan_rtl_flags}
      DEFS ${HWASAN_DEFINITIONS})
    add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
      ARCHS ${arch}
      SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
      ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
      CFLAGS ${hwasan_dyn_flags}
      DEFS ${HWASAN_DEFINITIONS})

    set(hwasan_object_lib RTHwasanAliases)
    set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
    set(hwasan_runtime clang_rt.hwasan_aliases)
  endif()
  add_compiler_rt_runtime(${hwasan_runtime}
    STATIC
    ARCHS ${arch}
    OBJECT_LIBS ${hwasan_object_lib}
                RTInterception
                RTSanitizerCommon
                RTSanitizerCommonLibc
                RTSanitizerCommonCoverage
                RTSanitizerCommonSymbolizer
                RTUbsan
    CFLAGS ${hwasan_rtl_flags}
    PARENT_TARGET hwasan)
  add_compiler_rt_runtime(${hwasan_runtime}_cxx
    STATIC
    ARCHS ${arch}
    OBJECT_LIBS RTHwasan_cxx
                RTUbsan_cxx
    CFLAGS ${hwasan_rtl_flags}
    PARENT_TARGET hwasan)

  if (UNIX)
    add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch}
                                  LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch}
                                  EXTRA hwasan.syms.extra)
    set(VERSION_SCRIPT_FLAG
         -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
    set_property(SOURCE
      ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
      APPEND PROPERTY
      OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
  else()
    set(VERSION_SCRIPT_FLAG)
  endif()


  add_compiler_rt_runtime(${hwasan_runtime}
    SHARED
    ARCHS ${arch}
    OBJECT_LIBS
            ${hwasan_object_dyn_lib}
            RTInterception
            RTSanitizerCommon
            RTSanitizerCommonLibc
            RTSanitizerCommonCoverage
            RTSanitizerCommonSymbolizer
            RTUbsan
            RTUbsan_cxx
            # The only purpose of RTHWAsan_dynamic_version_script_dummy is to
            # carry a dependency of the shared runtime on the version script.
            # Replacing it with a straightforward
            # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
            # generates an order-only dependency in ninja.
            RTHwasan_dynamic_version_script_dummy
    CFLAGS ${hwasan_dyn_flags}
    LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS}
              ${VERSION_SCRIPT_FLAG}
    LINK_LIBS ${HWASAN_DYNAMIC_LIBS}
    DEFS ${ASAN_DYNAMIC_DEFINITIONS}
    PARENT_TARGET hwasan)

  if(SANITIZER_USE_SYMBOLS)
    add_sanitizer_rt_symbols(${hwasan_runtime}
      ARCHS ${arch}
      EXTRA hwasan.syms.extra)
    add_sanitizer_rt_symbols(${hwasan_runtime}_cxx
      ARCHS ${arch}
      EXTRA hwasan.syms.extra)
    add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols
                          ${hwasan_runtime}_cxx-${arch}-symbols)
  endif()
endfunction()

foreach(arch ${HWASAN_SUPPORTED_ARCH})
  add_hwasan_runtimes(${arch} FALSE)
  if(${arch} MATCHES "x86_64")
    add_hwasan_runtimes(${arch} TRUE)
  endif()
endforeach()

add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan)

add_subdirectory("scripts")

# if(COMPILER_RT_INCLUDE_TESTS)
#   add_subdirectory(tests)
# endif()