1import("//compiler-rt/gen_version_script.gni")
2import("//compiler-rt/target.gni")
3
4if (current_cpu == "x64") {
5  hwasan_name = "hwasan_aliases"
6} else {
7  hwasan_name = "hwasan"
8}
9
10gen_version_script("version_script") {
11  extra = "hwasan.syms.extra"
12  output = "$target_gen_dir/hwasan.vers"
13  libs = [
14    ":hwasan",
15    ":hwasan_cxx",
16  ]
17  lib_names = [
18    "$hwasan_name",
19    "${hwasan_name}_cxx",
20  ]
21}
22
23source_set("sources") {
24  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
25  configs += [ "//llvm/utils/gn/build:crt_code" ]
26  defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
27  if (current_cpu == "x64") {
28    defines += [ "HWASAN_ALIASING_MODE" ]
29  }
30  deps = [
31    "//compiler-rt/lib/interception:sources",
32    "//compiler-rt/lib/lsan:common_sources",
33    "//compiler-rt/lib/sanitizer_common:sources",
34    "//compiler-rt/lib/ubsan:sources",
35  ]
36  sources = [
37    "hwasan.cpp",
38    "hwasan.h",
39    "hwasan_allocation_functions.cpp",
40    "hwasan_allocator.cpp",
41    "hwasan_allocator.h",
42    "hwasan_dynamic_shadow.cpp",
43    "hwasan_dynamic_shadow.h",
44    "hwasan_exceptions.cpp",
45    "hwasan_flags.h",
46    "hwasan_fuchsia.cpp",
47    "hwasan_globals.cpp",
48    "hwasan_globals.h",
49    "hwasan_interceptors.cpp",
50    "hwasan_interceptors_vfork.S",
51    "hwasan_interface_internal.h",
52    "hwasan_linux.cpp",
53    "hwasan_malloc_bisect.h",
54    "hwasan_mapping.h",
55    "hwasan_memintrinsics.cpp",
56    "hwasan_poisoning.cpp",
57    "hwasan_poisoning.h",
58    "hwasan_report.cpp",
59    "hwasan_report.h",
60    "hwasan_setjmp_aarch64.S",
61    "hwasan_setjmp_riscv64.S",
62    "hwasan_setjmp_x86_64.S",
63    "hwasan_tag_mismatch_aarch64.S",
64    "hwasan_tag_mismatch_riscv64.S",
65    "hwasan_thread.cpp",
66    "hwasan_thread.h",
67    "hwasan_thread_list.cpp",
68    "hwasan_thread_list.h",
69    "hwasan_type_test.cpp",
70  ]
71}
72
73source_set("cxx_sources") {
74  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
75  configs += [ "//llvm/utils/gn/build:crt_code" ]
76  defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
77  deps = [ "//compiler-rt/lib/ubsan:cxx_sources" ]
78  sources = [ "hwasan_new_delete.cpp" ]
79}
80
81static_library("hwasan") {
82  output_dir = crt_current_out_dir
83  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
84  complete_static_lib = true
85  configs -= [
86    "//llvm/utils/gn/build:llvm_code",
87    "//llvm/utils/gn/build:thin_archive",
88  ]
89  configs += [ "//llvm/utils/gn/build:crt_code" ]
90  deps = [ ":sources" ]
91}
92
93static_library("hwasan_cxx") {
94  output_dir = crt_current_out_dir
95  output_name = "clang_rt.${hwasan_name}_cxx$crt_current_target_suffix"
96  complete_static_lib = true
97  configs -= [
98    "//llvm/utils/gn/build:llvm_code",
99    "//llvm/utils/gn/build:thin_archive",
100  ]
101  configs += [ "//llvm/utils/gn/build:crt_code" ]
102  deps = [ ":cxx_sources" ]
103}
104
105shared_library("hwasan_shared") {
106  output_dir = crt_current_out_dir
107  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
108  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
109  configs += [ "//llvm/utils/gn/build:crt_code" ]
110  deps = [
111    ":cxx_sources",
112    ":sources",
113    ":version_script",
114  ]
115  inputs = [ "$target_gen_dir/hwasan.vers" ]
116  ldflags = [
117    "-Wl,--version-script," + rebase_path(inputs[0], root_build_dir),
118    "-Wl,-z,global",
119  ]
120}
121
122static_library("hwasan_preinit") {
123  output_dir = crt_current_out_dir
124  output_name = "clang_rt.${hwasan_name}_preinit$crt_current_target_suffix"
125  complete_static_lib = true
126  configs -= [
127    "//llvm/utils/gn/build:llvm_code",
128    "//llvm/utils/gn/build:thin_archive",
129  ]
130  configs += [ "//llvm/utils/gn/build:crt_code" ]
131  sources = [ "hwasan_preinit.cpp" ]
132}
133