| 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 (target_os != "mac" && target_os != "win") { |
| 64 |
asan_sources += [ "asan_interceptors_vfork.S" ] |
| 65 |
} |
| 66 |
config("asan_config") { |
| 67 |
cflags = [] |
| 68 |
if (target_os != "win") { |
| 69 |
cflags += [ "-ftls-model=initial-exec" ] |
| 70 |
} |
| 71 |
|
| 72 |
# FIXME: link rt dl m pthread log |
| 73 |
# FIXME: dep on libcxx-headers? |
| 74 |
# FIXME: add_sanitizer_rt_version_list (cf hwasan) |
| 75 |
# FIXME: need libclang_rt.asan*.a.syms? |
| 76 |
|
| 77 |
if (target_os == "android") { |
| 78 |
ldflags = [ "-Wl,-z,global" ] |
| 79 |
} |
| 80 |
|
| 81 |
if (target_os == "mac") { |
| 82 |
# The -U flags below correspond to the add_weak_symbols() calls in CMake. |
| 83 |
ldflags = [ |
| 84 |
"-lc++", |
| 85 |
"-lc++abi", |
| 86 |
|
| 87 |
# asan |
| 88 |
"-Wl,-U,___asan_default_options", |
| 89 |
"-Wl,-U,___asan_default_suppressions", |
| 90 |
"-Wl,-U,___asan_on_error", |
| 91 |
"-Wl,-U,___asan_set_shadow_00", |
| 92 |
"-Wl,-U,___asan_set_shadow_f1", |
| 93 |
"-Wl,-U,___asan_set_shadow_f2", |
| 94 |
"-Wl,-U,___asan_set_shadow_f3", |
| 95 |
"-Wl,-U,___asan_set_shadow_f4", |
| 96 |
"-Wl,-U,___asan_set_shadow_f5", |
| 97 |
"-Wl,-U,___asan_set_shadow_f6", |
| 98 |
"-Wl,-U,___asan_set_shadow_f7", |
| 99 |
"-Wl,-U,___asan_set_shadow_f8", |
| 100 |
|
| 101 |
# lsan |
| 102 |
"-Wl,-U,___lsan_default_options", |
| 103 |
"-Wl,-U,___lsan_default_suppressions", |
| 104 |
"-Wl,-U,___lsan_is_turned_off", |
| 105 |
|
| 106 |
# ubsan |
| 107 |
"-Wl,-U,___ubsan_default_options", |
| 108 |
|
| 109 |
# sanitizer_common |
| 110 |
"-Wl,-U,___sanitizer_free_hook", |
| 111 |
"-Wl,-U,___sanitizer_malloc_hook", |
| 112 |
"-Wl,-U,___sanitizer_report_error_summary", |
| 113 |
"-Wl,-U,___sanitizer_sandbox_on_notify", |
| 114 |
"-Wl,-U,___sanitizer_symbolize_code", |
| 115 |
"-Wl,-U,___sanitizer_symbolize_data", |
| 116 |
"-Wl,-U,___sanitizer_symbolize_frame", |
| 117 |
"-Wl,-U,___sanitizer_symbolize_demangle", |
| 118 |
"-Wl,-U,___sanitizer_symbolize_flush", |
| 119 |
"-Wl,-U,___sanitizer_symbolize_set_demangle", |
| 120 |
"-Wl,-U,___sanitizer_symbolize_set_inline_frames", |
| 121 |
|
| 122 |
# xray |
| 123 |
"-Wl,-U,___start_xray_fn_idx", |
| 124 |
"-Wl,-U,___start_xray_instr_map", |
| 125 |
"-Wl,-U,___stop_xray_fn_idx", |
| 126 |
"-Wl,-U,___stop_xray_instr_map", |
| 127 |
|
| 128 |
# FIXME: better |
| 129 |
"-Wl,-install_name,@rpath/libclang_rt.asan_osx_dynamic.dylib", |
| 130 |
] |
| 131 |
# FIXME: -Wl,-rpath |
| 132 |
# FIXME: codesign (??) |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
source_set("cxx_sources") { |
| 137 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 138 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 139 |
sources = [ "asan_new_delete.cpp" ] |
| 140 |
} |
| 141 |
|
| 142 |
source_set("static_sources") { |
| 143 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 144 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 145 |
sources = [ "asan_rtl_static.cpp" ] |
| 146 |
if (target_os != "mac" && target_os != "win") { |
| 147 |
sources += [ "asan_rtl_x86_64.S" ] |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
source_set("preinit_sources") { |
| 152 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 153 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 154 |
sources = [ "asan_preinit.cpp" ] |
| 155 |
} |
| 156 |
|
| 157 |
source_set("weak_interception") { |
| 158 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 159 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 160 |
sources = [ "asan_win_weak_interception.cpp" ] |
| 161 |
defines = [ "SANITIZER_DYNAMIC" ] |
| 162 |
} |
| 163 |
|
| 164 |
shared_library("asan_shared_library") { |
| 165 |
output_dir = crt_current_out_dir |
| 166 |
if (current_os == "mac") { |
| 167 |
output_name = "clang_rt.asan_osx_dynamic" |
| 168 |
} else if (current_os == "win") { |
| 169 |
output_name = "clang_rt.asan_dynamic$crt_current_target_suffix" |
| 170 |
} else { |
| 171 |
output_name = "clang_rt.asan$crt_current_target_suffix" |
| 172 |
} |
| 173 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 174 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 175 |
configs += [ ":asan_config" ] |
| 176 |
sources = asan_sources |
| 177 |
deps = [ |
| 178 |
":cxx_sources", |
| 179 |
"//compiler-rt/lib/interception:sources", |
| 180 |
"//compiler-rt/lib/lsan:common_sources", |
| 181 |
"//compiler-rt/lib/sanitizer_common:sources", |
| 182 |
"//compiler-rt/lib/ubsan:cxx_sources", |
| 183 |
"//compiler-rt/lib/ubsan:sources", |
| 184 |
] |
| 185 |
if (current_os == "win") { |
| 186 |
deps += [ |
| 187 |
":weak_interception", |
| 188 |
"//compiler-rt/lib/sanitizer_common:weak_interception", |
| 189 |
"//compiler-rt/lib/ubsan:weak_interception", |
| 190 |
] |
| 191 |
} |
| 192 |
defines = [ "ASAN_DYNAMIC" ] |
| 193 |
if (current_os == "win") { |
| 194 |
defines += [ "INTERCEPTION_DYNAMIC_CRT" ] |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if (current_os != "mac") { |
| 199 |
static_library("asan_static_library") { |
| 200 |
output_dir = crt_current_out_dir |
| 201 |
output_name = "clang_rt.asan$crt_current_target_suffix" |
| 202 |
complete_static_lib = true |
| 203 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 204 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 205 |
configs += [ ":asan_config" ] |
| 206 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 207 |
sources = asan_sources |
| 208 |
deps = [ |
| 209 |
":preinit_sources", |
| 210 |
"//compiler-rt/lib/interception:sources", |
| 211 |
"//compiler-rt/lib/lsan:common_sources", |
| 212 |
"//compiler-rt/lib/sanitizer_common:sources", |
| 213 |
"//compiler-rt/lib/ubsan:sources", |
| 214 |
] |
| 215 |
} |
| 216 |
|
| 217 |
static_library("asan_cxx") { |
| 218 |
output_dir = crt_current_out_dir |
| 219 |
output_name = "clang_rt.asan_cxx$crt_current_target_suffix" |
| 220 |
complete_static_lib = true |
| 221 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 222 |
deps = [ |
| 223 |
":cxx_sources", |
| 224 |
"//compiler-rt/lib/ubsan:cxx_sources", |
| 225 |
] |
| 226 |
} |
| 227 |
|
| 228 |
static_library("asan_static") { |
| 229 |
output_dir = crt_current_out_dir |
| 230 |
output_name = "clang_rt.asan_static$crt_current_target_suffix" |
| 231 |
complete_static_lib = true |
| 232 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 233 |
deps = [ ":static_sources" ] |
| 234 |
} |
| 235 |
|
| 236 |
static_library("asan_preinit") { |
| 237 |
output_dir = crt_current_out_dir |
| 238 |
output_name = "clang_rt.asan-preinit$crt_current_target_suffix" |
| 239 |
complete_static_lib = true |
| 240 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 241 |
deps = [ ":preinit_sources" ] |
| 242 |
} |
| 243 |
} |
| 244 |
if (current_os == "win") { |
| 245 |
static_library("asan_dll_thunk") { |
| 246 |
output_dir = crt_current_out_dir |
| 247 |
output_name = "clang_rt.asan_dll_thunk$crt_current_target_suffix" |
| 248 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 249 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 250 |
complete_static_lib = true |
| 251 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 252 |
sources = [ |
| 253 |
"asan_globals_win.cpp", |
| 254 |
"asan_win_dll_thunk.cpp", |
| 255 |
] |
| 256 |
defines = [ "SANITIZER_DLL_THUNK" ] |
| 257 |
deps = [ |
| 258 |
"//compiler-rt/lib/interception:sources", |
| 259 |
"//compiler-rt/lib/sanitizer_common:dll_thunk", |
| 260 |
"//compiler-rt/lib/ubsan:dll_thunk", |
| 261 |
] |
| 262 |
} |
| 263 |
static_library("asan_dynamic_runtime_thunk") { |
| 264 |
output_dir = crt_current_out_dir |
| 265 |
output_name = |
| 266 |
"clang_rt.asan_dynamic_runtime_thunk$crt_current_target_suffix" |
| 267 |
configs -= [ "//llvm/utils/gn/build:llvm_code" ] |
| 268 |
configs += [ "//llvm/utils/gn/build:crt_code" ] |
| 269 |
complete_static_lib = true |
| 270 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 271 |
sources = [ |
| 272 |
"asan_globals_win.cpp", |
| 273 |
"asan_win_dynamic_runtime_thunk.cpp", |
| 274 |
] |
| 275 |
defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ] |
| 276 |
deps = [ |
| 277 |
"//compiler-rt/lib/sanitizer_common:dynamic_runtime_thunk", |
| 278 |
"//compiler-rt/lib/ubsan:dynamic_runtime_thunk", |
| 279 |
] |
| 280 |
cflags = [ "-Zl" ] |
| 281 |
} |
| 282 |
} |
| 283 |
group("asan") { |
| 284 |
deps = [ ":asan_shared_library" ] |
| 285 |
if (current_os == "win") { |
| 286 |
deps += [ |
| 287 |
":asan_dll_thunk", |
| 288 |
":asan_dynamic_runtime_thunk", |
| 289 |
] |
| 290 |
} |
| 291 |
if (current_os != "mac") { |
| 292 |
deps += [ |
| 293 |
":asan_cxx", |
| 294 |
":asan_preinit", |
| 295 |
":asan_static", |
| 296 |
":asan_static_library", |
| 297 |
] |
| 298 |
} |
| 299 |
} |
| 300 |
} |