Index: llvm/trunk/utils/gn/build/toolchain/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/build/toolchain/BUILD.gn +++ llvm/trunk/utils/gn/build/toolchain/BUILD.gn @@ -150,8 +150,10 @@ } } -if (android_ndk_path != "") { - unix_toolchain("stage2_android_aarch64") { +template("stage2_unix_toolchain") { + unix_toolchain(target_name) { + forward_variables_from(invoker, "*") + cc = "bin/clang" cxx = "bin/clang++" ld = cxx @@ -162,7 +164,19 @@ "//:lld($host_toolchain)", "//:llvm-ar($host_toolchain)", ] + } +} + +stage2_unix_toolchain("stage2_unix") { + toolchain_args = { + current_os = host_os + current_cpu = host_cpu + use_lld = host_os != "mac" + } +} +if (android_ndk_path != "") { + stage2_unix_toolchain("stage2_android_aarch64") { toolchain_args = { current_os = "android" current_cpu = "arm64" Index: llvm/trunk/utils/gn/secondary/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/BUILD.gn +++ llvm/trunk/utils/gn/secondary/BUILD.gn @@ -9,9 +9,9 @@ "//llvm/test", ] + # FIXME: This should be a dependency of a test target instead of being + # depended on from here. if (android_ndk_path != "") { - # FIXME: This should be a dependency of a test target instead of being - # depended on from here. android_aarch64_toolchain = "//llvm/utils/gn/build/toolchain:stage2_android_aarch64" deps += [ @@ -19,6 +19,9 @@ "//llvm/tools/llvm-symbolizer($android_aarch64_toolchain)", ] } + if (host_cpu == "x64" && host_os == "linux") { + deps += [ "//compiler-rt/lib/hwasan:hwasan_shared(//llvm/utils/gn/build/toolchain:stage2_unix)" ] + } testonly = true } Index: llvm/trunk/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn +++ llvm/trunk/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn @@ -1,10 +1,4 @@ -import("//clang/resource_dir.gni") - -# FIXME: Make this support more platforms. -assert(current_os == "android") - -runtime_output_dir = "$clang_resource_dir/lib/linux" -runtime_target = "aarch64-android" +import("//compiler-rt/target.gni") action("version_script") { script = "//compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py" @@ -22,10 +16,11 @@ "--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", + rebase_path("$crt_current_out_dir/libclang_rt.hwasan-$crt_current_target.a", root_build_dir), + rebase_path( + "$crt_current_out_dir/libclang_rt.hwasan_cxx-$crt_current_target.a", + root_build_dir), "-o", rebase_path(outputs[0], root_build_dir), ] @@ -66,8 +61,8 @@ } static_library("hwasan") { - output_dir = runtime_output_dir - output_name = "clang_rt.hwasan-$runtime_target" + output_dir = crt_current_out_dir + output_name = "clang_rt.hwasan-$crt_current_target" complete_static_lib = true configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] @@ -77,8 +72,8 @@ } static_library("hwasan_cxx") { - output_dir = runtime_output_dir - output_name = "clang_rt.hwasan_cxx-$runtime_target" + output_dir = crt_current_out_dir + output_name = "clang_rt.hwasan_cxx-$crt_current_target" complete_static_lib = true configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] @@ -88,8 +83,8 @@ } shared_library("hwasan_shared") { - output_dir = runtime_output_dir - output_name = "clang_rt.hwasan-$runtime_target" + output_dir = crt_current_out_dir + output_name = "clang_rt.hwasan-$crt_current_target" configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] deps = [ Index: llvm/trunk/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn +++ llvm/trunk/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn @@ -1,6 +1,16 @@ source_set("sources") { configs -= [ "//llvm/utils/gn/build:llvm_code" ] configs += [ "//llvm/utils/gn/build:crt_code" ] + deps = [ + "//llvm/utils/gn/build/libs/pthread", + ] + libs = [] + if (current_os == "linux" || current_os == "android") { + libs += [ "dl" ] + } + if (current_os == "linux") { + libs += [ "rt" ] + } sources = [ "sancov_flags.cc", "sanitizer_allocator.cc", @@ -67,4 +77,7 @@ "sanitizer_unwind_win.cc", "sanitizer_win.cc", ] + if (current_cpu == "x64") { + sources += [ "sanitizer_linux_x86_64.S" ] + } } Index: llvm/trunk/utils/gn/secondary/compiler-rt/target.gni =================================================================== --- llvm/trunk/utils/gn/secondary/compiler-rt/target.gni +++ llvm/trunk/utils/gn/secondary/compiler-rt/target.gni @@ -0,0 +1,20 @@ +import("//clang/resource_dir.gni") + +if (current_os == "linux" || current_os == "android") { + crt_current_out_dir = "$clang_resource_dir/lib/linux" +} else { + assert(false, "unimplemented current_os " + current_os) +} + +if (current_cpu == "x64") { + crt_current_target_arch = "x86_64" +} else if (current_cpu == "arm64") { + crt_current_target_arch = "aarch64" +} else { + assert(false, "unimplemented current_cpu " + current_cpu) +} + +crt_current_target = crt_current_target_arch +if (current_os == "android") { + crt_current_target += "-android" +}