xref: /netbsd-src/external/apache2/llvm/dist/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn (revision 82d56013d7b633d116a93943de88e08335357a7c)
1import("//compiler-rt/target.gni")
2
3source_set("cxx_sources") {
4  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
5  configs += [ "//llvm/utils/gn/build:crt_code" ]
6  sources = [ "asan_new_delete.cpp" ]
7}
8
9if (current_os == "mac") {
10  asan_target_type = "shared_library"
11} else {
12  asan_target_type = "static_library"
13}
14
15target(asan_target_type, "asan") {
16  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
17  configs += [ "//llvm/utils/gn/build:crt_code" ]
18
19  output_dir = crt_current_out_dir
20  if (current_os == "mac") {
21    output_name = "clang_rt.asan_osx_dynamic"
22  } else {
23    assert(current_os != "win", "FIXME")
24    output_name = "clang_rt.asan$crt_current_target_suffix"
25  }
26
27  deps = [
28    "//compiler-rt/lib/interception:sources",
29    "//compiler-rt/lib/lsan:common_sources",
30    "//compiler-rt/lib/sanitizer_common:sources",
31    "//compiler-rt/lib/ubsan:sources",
32  ]
33
34  if (asan_target_type == "static_library") {
35    complete_static_lib = true
36    configs -= [ "//llvm/utils/gn/build:thin_archive" ]
37    deps += [ ":asan_cxx" ]
38  } else {
39    deps += [
40      ":cxx_sources",
41      "//compiler-rt/lib/ubsan:cxx_sources",
42    ]
43    defines = [ "ASAN_DYNAMIC" ]
44  }
45
46  sources = [
47    "asan_activation.cpp",
48    "asan_activation.h",
49    "asan_activation_flags.inc",
50    "asan_allocator.cpp",
51    "asan_allocator.h",
52    "asan_debugging.cpp",
53    "asan_descriptions.cpp",
54    "asan_descriptions.h",
55    "asan_errors.cpp",
56    "asan_errors.h",
57    "asan_fake_stack.cpp",
58    "asan_fake_stack.h",
59    "asan_flags.cpp",
60    "asan_flags.h",
61    "asan_flags.inc",
62    "asan_fuchsia.cpp",
63    "asan_globals.cpp",
64    "asan_globals_win.cpp",
65    "asan_init_version.h",
66    "asan_interceptors.cpp",
67    "asan_interceptors.h",
68    "asan_interceptors_memintrinsics.cpp",
69    "asan_interceptors_memintrinsics.h",
70    "asan_interface.inc",
71    "asan_interface_internal.h",
72    "asan_internal.h",
73    "asan_linux.cpp",
74    "asan_lock.h",
75    "asan_mac.cpp",
76    "asan_malloc_linux.cpp",
77    "asan_malloc_local.h",
78    "asan_malloc_mac.cpp",
79    "asan_malloc_win.cpp",
80    "asan_mapping.h",
81    "asan_mapping_myriad.h",
82    "asan_memory_profile.cpp",
83    "asan_poisoning.cpp",
84    "asan_poisoning.h",
85    "asan_posix.cpp",
86    "asan_premap_shadow.cpp",
87    "asan_premap_shadow.h",
88    "asan_report.cpp",
89    "asan_report.h",
90    "asan_rtems.cpp",
91    "asan_rtl.cpp",
92    "asan_scariness_score.h",
93    "asan_shadow_setup.cpp",
94    "asan_stack.cpp",
95    "asan_stack.h",
96    "asan_stats.cpp",
97    "asan_stats.h",
98    "asan_suppressions.cpp",
99    "asan_suppressions.h",
100    "asan_thread.cpp",
101    "asan_thread.h",
102    "asan_win.cpp",
103  ]
104  if (target_os != "mac" && target_os != "win") {
105    sources += [ "asan_interceptors_vfork.S" ]
106  }
107
108  # To be able to include sanitizer_common.
109  include_dirs = [ ".." ]
110
111  # FIXME: have SANITIZER_COMMON_CFLAGS thingy? should fno-builtin be in
112  # crt_code?
113  cflags = [ "-fno-builtin" ]
114  if (target_os != "win") {
115    cflags += [ "-ftls-model=initial-exec" ]
116  }
117
118  # FIXME: link rt dl m pthread log
119  # FIXME: dep on libcxx-headers?
120  # FIXME: add_sanitizer_rt_version_list (cf hwasan)
121  # FIXME: need libclang_rt.asan*.a.syms?
122  # FIXME: windows flags (-Zl -nodefaultlibs)
123  # FIXME: asan_ignorelist.txt
124
125  if (target_os == "android") {
126    ldflags = [ "-Wl,-z,global" ]
127  }
128
129  if (target_os == "mac") {
130    # The -U flags below correspond to the add_weak_symbols() calls in CMake.
131    ldflags = [
132      "-lc++",
133      "-lc++abi",
134
135      # asan
136      "-Wl,-U,___asan_default_options",
137      "-Wl,-U,___asan_default_suppressions",
138      "-Wl,-U,___asan_on_error",
139      "-Wl,-U,___asan_set_shadow_00",
140      "-Wl,-U,___asan_set_shadow_f1",
141      "-Wl,-U,___asan_set_shadow_f2",
142      "-Wl,-U,___asan_set_shadow_f3",
143      "-Wl,-U,___asan_set_shadow_f4",
144      "-Wl,-U,___asan_set_shadow_f5",
145      "-Wl,-U,___asan_set_shadow_f6",
146      "-Wl,-U,___asan_set_shadow_f7",
147      "-Wl,-U,___asan_set_shadow_f8",
148
149      # lsan
150      "-Wl,-U,___lsan_default_options",
151      "-Wl,-U,___lsan_default_suppressions",
152      "-Wl,-U,___lsan_is_turned_off",
153
154      # ubsan
155      "-Wl,-U,___ubsan_default_options",
156
157      # sanitizer_common
158      "-Wl,-U,___sanitizer_free_hook",
159      "-Wl,-U,___sanitizer_malloc_hook",
160      "-Wl,-U,___sanitizer_report_error_summary",
161      "-Wl,-U,___sanitizer_sandbox_on_notify",
162      "-Wl,-U,___sanitizer_symbolize_code",
163      "-Wl,-U,___sanitizer_symbolize_data",
164      "-Wl,-U,___sanitizer_symbolize_demangle",
165      "-Wl,-U,___sanitizer_symbolize_flush",
166
167      # xray
168      "-Wl,-U,___start_xray_fn_idx",
169      "-Wl,-U,___start_xray_instr_map",
170      "-Wl,-U,___stop_xray_fn_idx",
171      "-Wl,-U,___stop_xray_instr_map",
172
173      # FIXME: better
174      "-Wl,-install_name,@rpath/libclang_rt.asan_osx_dynamic.dylib",
175    ]
176    # FIXME: -Wl,-rpath
177    # FIXME: codesign (??)
178  }
179}
180
181if (asan_target_type == "static_library") {
182  static_library("asan_cxx") {
183    assert(current_os != "win", "FIXME")
184    output_dir = crt_current_out_dir
185    output_name = "clang_rt.asan_cxx$crt_current_target_suffix"
186    complete_static_lib = true
187    configs -= [ "//llvm/utils/gn/build:thin_archive" ]
188    deps = [
189      ":cxx_sources",
190      "//compiler-rt/lib/ubsan:cxx_sources",
191    ]
192  }
193}
194
195# FIXME: Move these to real targets.
196source_set("unused") {
197  sources = [
198    "asan_preinit.cpp",
199    "asan_win_dll_thunk.cpp",
200    "asan_win_dynamic_runtime_thunk.cpp",
201  ]
202}
203