xref: /llvm-project/llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn (revision 09fb01a5e564a0cb7c121e1cc529e9aa30d95108)
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_static",
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_thread.cpp",
61    "hwasan_thread.h",
62    "hwasan_thread_list.cpp",
63    "hwasan_thread_list.h",
64    "hwasan_type_test.cpp",
65  ]
66  if (current_cpu == "arm64") {
67    sources += [
68      "hwasan_setjmp_aarch64.S",
69      "hwasan_tag_mismatch_aarch64.S",
70    ]
71  }
72  if (current_cpu == "riscv64") {
73    sources += [
74      "hwasan_setjmp_riscv64.S",
75      "hwasan_tag_mismatch_riscv64.S",
76    ]
77  }
78  if (current_cpu == "x64") {
79    sources += [ "hwasan_setjmp_x86_64.S" ]
80  }
81}
82
83source_set("cxx_sources") {
84  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
85  configs += [ "//llvm/utils/gn/build:crt_code" ]
86  defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
87  deps = [ "//compiler-rt/lib/ubsan:cxx_sources" ]
88  sources = [ "hwasan_new_delete.cpp" ]
89}
90
91static_library("hwasan_static") {
92  output_dir = crt_current_out_dir
93  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
94  complete_static_lib = true
95  configs -= [
96    "//llvm/utils/gn/build:llvm_code",
97    "//llvm/utils/gn/build:thin_archive",
98  ]
99  configs += [ "//llvm/utils/gn/build:crt_code" ]
100  deps = [ ":sources" ]
101}
102
103static_library("hwasan_cxx") {
104  output_dir = crt_current_out_dir
105  output_name = "clang_rt.${hwasan_name}_cxx$crt_current_target_suffix"
106  complete_static_lib = true
107  configs -= [
108    "//llvm/utils/gn/build:llvm_code",
109    "//llvm/utils/gn/build:thin_archive",
110  ]
111  configs += [ "//llvm/utils/gn/build:crt_code" ]
112  deps = [ ":cxx_sources" ]
113}
114
115shared_library("hwasan_shared") {
116  output_dir = crt_current_out_dir
117  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
118  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
119  configs += [ "//llvm/utils/gn/build:crt_code" ]
120  deps = [
121    ":cxx_sources",
122    ":sources",
123    ":version_script",
124  ]
125  inputs = [ "$target_gen_dir/hwasan.vers" ]
126  ldflags = [
127    "-Wl,--version-script," + rebase_path(inputs[0], root_build_dir),
128    "-Wl,-z,global",
129  ]
130}
131
132static_library("hwasan_preinit") {
133  output_dir = crt_current_out_dir
134  output_name = "clang_rt.${hwasan_name}-preinit$crt_current_target_suffix"
135  complete_static_lib = true
136  configs -= [
137    "//llvm/utils/gn/build:llvm_code",
138    "//llvm/utils/gn/build:thin_archive",
139  ]
140  configs += [ "//llvm/utils/gn/build:crt_code" ]
141  sources = [ "hwasan_preinit.cpp" ]
142}
143
144group("hwasan") {
145  deps = [
146    ":hwasan_preinit",
147    ":hwasan_shared",
148    ":hwasan_static",
149    ":hwasan_cxx",
150    ":version_script",
151  ]
152}
153