Debian Codegraph @

llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn

raw
1 import("//compiler-rt/target.gni")
2
3 if (current_toolchain == host_toolchain) {
4 copy("ignorelist") {
5 sources = [ "asan_ignorelist.txt" ]
6 outputs = [ "$clang_resource_dir/share/{{source_target_relative}}" ]
7 }
8 } else {
9 asan_sources = [
10 "asan_activation.cpp",
11 "asan_activation.h",
12 "asan_activation_flags.inc",
13 "asan_allocator.cpp",
14 "asan_allocator.h",
15 "asan_debugging.cpp",
16 "asan_descriptions.cpp",
17 "asan_descriptions.h",
18 "asan_errors.cpp",
19 "asan_errors.h",
20 "asan_fake_stack.cpp",
21 "asan_fake_stack.h",
22 "asan_flags.cpp",
23 "asan_flags.h",
24 "asan_flags.inc",
25 "asan_fuchsia.cpp",
26 "asan_globals.cpp",
27 "asan_globals_win.cpp",
28 "asan_init_version.h",
29 "asan_interceptors.cpp",
30 "asan_interceptors.h",
31 "asan_interceptors_memintrinsics.cpp",
32 "asan_interceptors_memintrinsics.h",
33 "asan_interface.inc",
34 "asan_interface_internal.h",
35 "asan_internal.h",
36 "asan_linux.cpp",
37 "asan_mac.cpp",
38 "asan_malloc_linux.cpp",
39 "asan_malloc_mac.cpp",
40 "asan_malloc_win.cpp",
41 "asan_mapping.h",
42 "asan_memory_profile.cpp",
43 "asan_poisoning.cpp",
44 "asan_poisoning.h",
45 "asan_posix.cpp",
46 "asan_premap_shadow.cpp",
47 "asan_premap_shadow.h",
48 "asan_report.cpp",
49 "asan_report.h",
50 "asan_rtl.cpp",
51 "asan_scariness_score.h",
52 "asan_shadow_setup.cpp",
53 "asan_stack.cpp",
54 "asan_stack.h",
55 "asan_stats.cpp",
56 "asan_stats.h",
57 "asan_suppressions.cpp",
58 "asan_suppressions.h",
59 "asan_thread.cpp",
60 "asan_thread.h",
61 "asan_win.cpp",
62 ]
63 if (current_os != "mac" && current_os != "win") {
64 asan_sources += [ "asan_interceptors_vfork.S" ]
65 }
66 config("asan_config") {
67 cflags = []
68 if (current_os != "win") {
69 cflags += [ "-ftls-model=initial-exec" ]
70 } else {
71 ldflags = [ "/OPT:NOICF" ]
72 }
73
74 # FIXME: link rt dl m pthread log
75 # FIXME: dep on libcxx-headers?
76 # FIXME: add_sanitizer_rt_version_list (cf hwasan)
77 # FIXME: need libclang_rt.asan*.a.syms?
78
79 if (current_os == "android") {
80 ldflags = [ "-Wl,-z,global" ]
81 }
82
83 if (current_os == "mac") {
84 # The -U flags below correspond to the add_weak_symbols() calls in CMake.
85 ldflags = [
86 "-lc++",
87 "-lc++abi",
88
89 # asan
90 "-Wl,-U,___asan_default_options",
91 "-Wl,-U,___asan_default_suppressions",
92 "-Wl,-U,___asan_on_error",
93 "-Wl,-U,___asan_set_shadow_00",
94 "-Wl,-U,___asan_set_shadow_f1",
95 "-Wl,-U,___asan_set_shadow_f2",
96 "-Wl,-U,___asan_set_shadow_f3",
97 "-Wl,-U,___asan_set_shadow_f4",
98 "-Wl,-U,___asan_set_shadow_f5",
99 "-Wl,-U,___asan_set_shadow_f6",
100 "-Wl,-U,___asan_set_shadow_f7",
101 "-Wl,-U,___asan_set_shadow_f8",
102
103 # lsan
104 "-Wl,-U,___lsan_default_options",
105 "-Wl,-U,___lsan_default_suppressions",
106 "-Wl,-U,___lsan_is_turned_off",
107
108 # ubsan
109 "-Wl,-U,___ubsan_default_options",
110
111 # sanitizer_common
112 "-Wl,-U,___sanitizer_free_hook",
113 "-Wl,-U,___sanitizer_malloc_hook",
114 "-Wl,-U,___sanitizer_report_error_summary",
115 "-Wl,-U,___sanitizer_sandbox_on_notify",
116 "-Wl,-U,___sanitizer_symbolize_code",
117 "-Wl,-U,___sanitizer_symbolize_data",
118 "-Wl,-U,___sanitizer_symbolize_frame",
119 "-Wl,-U,___sanitizer_symbolize_demangle",
120 "-Wl,-U,___sanitizer_symbolize_flush",
121 "-Wl,-U,___sanitizer_symbolize_set_demangle",
122 "-Wl,-U,___sanitizer_symbolize_set_inline_frames",
123
124 # xray
125 "-Wl,-U,___start_xray_fn_idx",
126 "-Wl,-U,___start_xray_instr_map",
127 "-Wl,-U,___stop_xray_fn_idx",
128 "-Wl,-U,___stop_xray_instr_map",
129
130 # FIXME: better
131 "-Wl,-install_name,@rpath/libclang_rt.asan_osx_dynamic.dylib",
132 ]
133 # FIXME: -Wl,-rpath
134 # FIXME: codesign (??)
135 }
136 }
137
138 source_set("cxx_sources") {
139 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
140 configs += [ "//llvm/utils/gn/build:crt_code" ]
141 sources = [ "asan_new_delete.cpp" ]
142 }
143
144 source_set("static_sources") {
145 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
146 configs += [ "//llvm/utils/gn/build:crt_code" ]
147 sources = [ "asan_rtl_static.cpp" ]
148 if (current_os != "mac" && current_os != "win") {
149 sources += [ "asan_rtl_x86_64.S" ]
150 }
151 }
152
153 source_set("preinit_sources") {
154 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
155 configs += [ "//llvm/utils/gn/build:crt_code" ]
156 sources = [ "asan_preinit.cpp" ]
157 }
158
159 shared_library("asan_shared_library") {
160 output_dir = crt_current_out_dir
161 if (current_os == "mac") {
162 output_name = "clang_rt.asan_osx_dynamic"
163 } else if (current_os == "win") {
164 output_name = "clang_rt.asan_dynamic$crt_current_target_suffix"
165 } else {
166 output_name = "clang_rt.asan$crt_current_target_suffix"
167 }
168 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
169 configs += [ "//llvm/utils/gn/build:crt_code" ]
170 configs += [ ":asan_config" ]
171 sources = asan_sources
172 deps = [
173 ":cxx_sources",
174 "//compiler-rt/lib/interception:sources",
175 "//compiler-rt/lib/lsan:common_sources",
176 "//compiler-rt/lib/sanitizer_common:sources",
177 "//compiler-rt/lib/ubsan:cxx_sources",
178 "//compiler-rt/lib/ubsan:sources",
179 ]
180 defines = [ "ASAN_DYNAMIC" ]
181 if (current_os == "win") {
182 defines += [ "INTERCEPTION_DYNAMIC_CRT" ]
183 }
184 }
185
186 if (current_os != "mac" && current_os != "win") {
187 static_library("asan_static_library") {
188 output_dir = crt_current_out_dir
189 output_name = "clang_rt.asan$crt_current_target_suffix"
190 complete_static_lib = true
191 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
192 configs += [ "//llvm/utils/gn/build:crt_code" ]
193 configs += [ ":asan_config" ]
194 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
195 sources = asan_sources
196 deps = [
197 ":preinit_sources",
198 "//compiler-rt/lib/interception:sources",
199 "//compiler-rt/lib/lsan:common_sources",
200 "//compiler-rt/lib/sanitizer_common:sources",
201 "//compiler-rt/lib/ubsan:sources",
202 ]
203 }
204
205 static_library("asan_cxx") {
206 output_dir = crt_current_out_dir
207 output_name = "clang_rt.asan_cxx$crt_current_target_suffix"
208 complete_static_lib = true
209 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
210 deps = [
211 ":cxx_sources",
212 "//compiler-rt/lib/ubsan:cxx_sources",
213 ]
214 }
215
216 static_library("asan_static") {
217 output_dir = crt_current_out_dir
218 output_name = "clang_rt.asan_static$crt_current_target_suffix"
219 complete_static_lib = true
220 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
221 deps = [ ":static_sources" ]
222 }
223
224 static_library("asan_preinit") {
225 output_dir = crt_current_out_dir
226 output_name = "clang_rt.asan-preinit$crt_current_target_suffix"
227 complete_static_lib = true
228 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
229 deps = [ ":preinit_sources" ]
230 }
231 }
232 if (current_os == "win") {
233 static_library("asan_static_runtime_thunk") {
234 output_dir = crt_current_out_dir
235 output_name =
236 "clang_rt.asan_static_runtime_thunk$crt_current_target_suffix"
237 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
238 configs += [ "//llvm/utils/gn/build:crt_code" ]
239 complete_static_lib = true
240 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
241 sources = [
242 "asan_globals_win.cpp",
243 "asan_malloc_win_thunk.cpp",
244 "asan_win_common_runtime_thunk.cpp",
245 "asan_win_static_runtime_thunk.cpp",
246 ]
247 defines = [ "SANITIZER_STATIC_RUNTIME_THUNK" ]
248 deps = [
249 "//compiler-rt/lib/interception:sources",
250 "//compiler-rt/lib/sanitizer_common:runtime_thunk",
251 "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk",
252 "//compiler-rt/lib/ubsan:runtime_thunk",
253 ]
254 }
255 static_library("asan_dynamic_runtime_thunk") {
256 output_dir = crt_current_out_dir
257 output_name =
258 "clang_rt.asan_dynamic_runtime_thunk$crt_current_target_suffix"
259 configs -= [ "//llvm/utils/gn/build:llvm_code" ]
260 configs += [ "//llvm/utils/gn/build:crt_code" ]
261 complete_static_lib = true
262 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
263 sources = [
264 "asan_globals_win.cpp",
265 "asan_win_common_runtime_thunk.cpp",
266 "asan_win_dynamic_runtime_thunk.cpp",
267 ]
268 defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ]
269 deps = [
270 "//compiler-rt/lib/sanitizer_common:runtime_thunk",
271 "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk",
272 "//compiler-rt/lib/ubsan:runtime_thunk",
273 ]
274 cflags = [ "-Zl" ]
275 }
276 }
277 group("asan") {
278 deps = [ ":asan_shared_library" ]
279 if (current_os == "win") {
280 deps += [
281 ":asan_dynamic_runtime_thunk",
282 ":asan_static_runtime_thunk",
283 ]
284 }
285 if (current_os != "mac" && current_os != "win") {
286 deps += [
287 ":asan_cxx",
288 ":asan_preinit",
289 ":asan_static",
290 ":asan_static_library",
291 ]
292 }
293 }
294 }