Index: llvm/utils/gn/build/BUILD.gn =================================================================== --- llvm/utils/gn/build/BUILD.gn +++ llvm/utils/gn/build/BUILD.gn @@ -135,6 +135,15 @@ ] } +config("crt_code") { + include_dirs = [ "//compiler-rt/lib" ] + cflags = [ + "-fPIC", + "-funwind-tables", + "-gline-tables-only", + ] +} + config("warn_covered_switch_default") { if (is_clang) { cflags = [ "-Wcovered-switch-default" ] Index: llvm/utils/gn/secondary/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/BUILD.gn +++ llvm/utils/gn/secondary/BUILD.gn @@ -12,7 +12,12 @@ if (android_ndk_path != "") { # FIXME: This should be a dependency of a test target instead of being # depended on from here. - deps += [ "//llvm/tools/llvm-symbolizer(//llvm/utils/gn/build/toolchain:stage2_android_aarch64)" ] + android_aarch64_toolchain = + "//llvm/utils/gn/build/toolchain:stage2_android_aarch64" + deps += [ + "//compiler-rt/lib/hwasan:hwasan_shared($android_aarch64_toolchain)", + "//llvm/tools/llvm-symbolizer($android_aarch64_toolchain)", + ] } testonly = true Index: llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn @@ -0,0 +1,107 @@ +import("//llvm/version.gni") + +# FIXME: Make this support more platforms. +assert(current_os == "android") + +runtime_output_dir = "$root_build_dir/lib/clang/$llvm_version/lib/linux" +runtime_target = "aarch64-android" + +action("version_script") { + script = "//compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py" + sources = [ + "hwasan.syms.extra", + ] + deps = [ + ":hwasan", + ":hwasan_cxx", + ] + outputs = [ + "$target_gen_dir/hwasan.vers", + ] + args = [ + "--version-list", + "--extra", + rebase_path(sources[0], root_build_dir), + rebase_path("$runtime_output_dir/libclang_rt.hwasan-$runtime_target.a", + root_build_dir), + rebase_path("$runtime_output_dir/libclang_rt.hwasan_cxx-$runtime_target.a", + root_build_dir), + "-o", + rebase_path(outputs[0], root_build_dir), + ] +} + +source_set("sources") { + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + defines = [ "HWASAN_WITH_INTERCEPTORS=1" ] + deps = [ + "//compiler-rt/lib/interception:sources", + "//compiler-rt/lib/sanitizer_common:sources", + "//compiler-rt/lib/ubsan:sources", + ] + sources = [ + "hwasan.cc", + "hwasan_allocator.cc", + "hwasan_dynamic_shadow.cc", + "hwasan_interceptors.cc", + "hwasan_linux.cc", + "hwasan_memintrinsics.cc", + "hwasan_poisoning.cc", + "hwasan_report.cc", + "hwasan_thread.cc", + "hwasan_thread_list.cc", + ] +} + +source_set("cxx_sources") { + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + deps = [ + "//compiler-rt/lib/ubsan:cxx_sources", + ] + sources = [ + "hwasan_new_delete.cc", + ] +} + +static_library("hwasan") { + output_dir = runtime_output_dir + output_name = "clang_rt.hwasan-$runtime_target" + complete_static_lib = true + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + deps = [ + ":sources", + ] +} + +static_library("hwasan_cxx") { + output_dir = runtime_output_dir + output_name = "clang_rt.hwasan_cxx-$runtime_target" + complete_static_lib = true + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + deps = [ + ":cxx_sources", + ] +} + +shared_library("hwasan_shared") { + output_dir = runtime_output_dir + output_name = "clang_rt.hwasan-$runtime_target" + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + deps = [ + ":cxx_sources", + ":sources", + ":version_script", + ] + inputs = [ + "$target_gen_dir/hwasan.vers", + ] + ldflags = [ + "-Wl,--version-script," + rebase_path(inputs[0], root_build_dir), + "-Wl,-z,global", + ] +} Index: llvm/utils/gn/secondary/compiler-rt/lib/interception/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/compiler-rt/lib/interception/BUILD.gn @@ -0,0 +1,15 @@ +source_set("sources") { + sources = [ + "interception_linux.cc", + "interception_mac.cc", + "interception_type_test.cc", + "interception_win.cc", + ] + + deps = [ + "//compiler-rt/lib/sanitizer_common:sources", + ] + + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] +} Index: llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn @@ -0,0 +1,71 @@ +source_set("sources") { + sources = [ + "sancov_flags.cc", + "sanitizer_allocator.cc", + "sanitizer_allocator_checks.cc", + "sanitizer_allocator_report.cc", + "sanitizer_common.cc", + "sanitizer_common_libcdep.cc", + "sanitizer_coverage_fuchsia.cc", + "sanitizer_coverage_libcdep_new.cc", + "sanitizer_coverage_win_sections.cc", + "sanitizer_deadlock_detector1.cc", + "sanitizer_deadlock_detector2.cc", + "sanitizer_errno.cc", + "sanitizer_file.cc", + "sanitizer_flag_parser.cc", + "sanitizer_flags.cc", + "sanitizer_fuchsia.cc", + "sanitizer_libc.cc", + "sanitizer_libignore.cc", + "sanitizer_linux.cc", + "sanitizer_linux_libcdep.cc", + "sanitizer_linux_s390.cc", + "sanitizer_mac.cc", + "sanitizer_mac_libcdep.cc", + "sanitizer_netbsd.cc", + "sanitizer_openbsd.cc", + "sanitizer_persistent_allocator.cc", + "sanitizer_platform_limits_freebsd.cc", + "sanitizer_platform_limits_linux.cc", + "sanitizer_platform_limits_netbsd.cc", + "sanitizer_platform_limits_openbsd.cc", + "sanitizer_platform_limits_posix.cc", + "sanitizer_platform_limits_solaris.cc", + "sanitizer_posix.cc", + "sanitizer_posix_libcdep.cc", + "sanitizer_printf.cc", + "sanitizer_procmaps_bsd.cc", + "sanitizer_procmaps_common.cc", + "sanitizer_procmaps_linux.cc", + "sanitizer_procmaps_mac.cc", + "sanitizer_procmaps_solaris.cc", + "sanitizer_rtems.cc", + "sanitizer_solaris.cc", + "sanitizer_stackdepot.cc", + "sanitizer_stacktrace.cc", + "sanitizer_stacktrace_libcdep.cc", + "sanitizer_stacktrace_printer.cc", + "sanitizer_stacktrace_sparc.cc", + "sanitizer_stoptheworld_linux_libcdep.cc", + "sanitizer_stoptheworld_mac.cc", + "sanitizer_suppressions.cc", + "sanitizer_symbolizer.cc", + "sanitizer_symbolizer_libbacktrace.cc", + "sanitizer_symbolizer_libcdep.cc", + "sanitizer_symbolizer_mac.cc", + "sanitizer_symbolizer_markup.cc", + "sanitizer_symbolizer_posix_libcdep.cc", + "sanitizer_symbolizer_report.cc", + "sanitizer_symbolizer_win.cc", + "sanitizer_termination.cc", + "sanitizer_thread_registry.cc", + "sanitizer_tls_get_addr.cc", + "sanitizer_unwind_linux_libcdep.cc", + "sanitizer_unwind_win.cc", + "sanitizer_win.cc", + ] + + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] +} Index: llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn @@ -0,0 +1,36 @@ +source_set("sources") { + sources = [ + "ubsan_diag.cc", + "ubsan_flags.cc", + "ubsan_handlers.cc", + "ubsan_init.cc", + "ubsan_monitor.cc", + "ubsan_value.cc", + ] + + deps = [ + "//compiler-rt/lib/interception:sources", + "//compiler-rt/lib/sanitizer_common:sources", + ] + + defines = [ "UBSAN_CAN_USE_CXXABI" ] + + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] +} + +source_set("cxx_sources") { + sources = [ + "ubsan_handlers_cxx.cc", + "ubsan_type_hash.cc", + "ubsan_type_hash_itanium.cc", + "ubsan_type_hash_win.cc", + ] + + defines = [ "UBSAN_CAN_USE_CXXABI" ] + + configs -= [ "//llvm/utils/gn/build:llvm_code" ] + configs += [ "//llvm/utils/gn/build:crt_code" ] + + configs -= [ "//llvm/utils/gn/build:no_rtti" ] +}