1import("//compiler-rt/target.gni")
2
3action("version_script") {
4  script = "//compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py"
5  sources = [ "hwasan.syms.extra" ]
6  deps = [
7    ":hwasan",
8    ":hwasan_cxx",
9  ]
10  outputs = [ "$target_gen_dir/hwasan.vers" ]
11  args = [
12    "--version-list",
13    "--extra",
14    rebase_path(sources[0], root_build_dir),
15    rebase_path(
16        "$crt_current_out_dir/libclang_rt.hwasan$crt_current_target_suffix.a",
17        root_build_dir),
18    rebase_path(
19        "$crt_current_out_dir/libclang_rt.hwasan_cxx$crt_current_target_suffix.a",
20        root_build_dir),
21    "--nm-executable",
22    "nm",
23    "-o",
24    rebase_path(outputs[0], root_build_dir),
25  ]
26}
27
28source_set("sources") {
29  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
30  configs += [ "//llvm/utils/gn/build:crt_code" ]
31  defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
32  deps = [
33    "//compiler-rt/lib/interception:sources",
34    "//compiler-rt/lib/sanitizer_common:sources",
35    "//compiler-rt/lib/ubsan:sources",
36  ]
37  sources = [
38    "hwasan.cpp",
39    "hwasan.h",
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_globals.cpp",
47    "hwasan_globals.h",
48    "hwasan_interceptors.cpp",
49    "hwasan_interceptors_vfork.S",
50    "hwasan_interface_internal.h",
51    "hwasan_linux.cpp",
52    "hwasan_malloc_bisect.h",
53    "hwasan_mapping.h",
54    "hwasan_memintrinsics.cpp",
55    "hwasan_poisoning.cpp",
56    "hwasan_poisoning.h",
57    "hwasan_report.cpp",
58    "hwasan_report.h",
59    "hwasan_setjmp.S",
60    "hwasan_tag_mismatch_aarch64.S",
61    "hwasan_thread.cpp",
62    "hwasan_thread.h",
63    "hwasan_thread_list.cpp",
64    "hwasan_thread_list.h",
65    "hwasan_type_test.cpp",
66  ]
67}
68
69source_set("cxx_sources") {
70  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
71  configs += [ "//llvm/utils/gn/build:crt_code" ]
72  defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
73  deps = [ "//compiler-rt/lib/ubsan:cxx_sources" ]
74  sources = [ "hwasan_new_delete.cpp" ]
75}
76
77static_library("hwasan") {
78  output_dir = crt_current_out_dir
79  output_name = "clang_rt.hwasan$crt_current_target_suffix"
80  complete_static_lib = true
81  configs -= [
82    "//llvm/utils/gn/build:llvm_code",
83    "//llvm/utils/gn/build:thin_archive",
84  ]
85  configs += [ "//llvm/utils/gn/build:crt_code" ]
86  deps = [ ":sources" ]
87}
88
89static_library("hwasan_cxx") {
90  output_dir = crt_current_out_dir
91  output_name = "clang_rt.hwasan_cxx$crt_current_target_suffix"
92  complete_static_lib = true
93  configs -= [
94    "//llvm/utils/gn/build:llvm_code",
95    "//llvm/utils/gn/build:thin_archive",
96  ]
97  configs += [ "//llvm/utils/gn/build:crt_code" ]
98  deps = [ ":cxx_sources" ]
99}
100
101shared_library("hwasan_shared") {
102  output_dir = crt_current_out_dir
103  output_name = "clang_rt.hwasan$crt_current_target_suffix"
104  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
105  configs += [ "//llvm/utils/gn/build:crt_code" ]
106  deps = [
107    ":cxx_sources",
108    ":sources",
109    ":version_script",
110  ]
111  inputs = [ "$target_gen_dir/hwasan.vers" ]
112  ldflags = [
113    "-Wl,--version-script," + rebase_path(inputs[0], root_build_dir),
114    "-Wl,-z,global",
115  ]
116}
117