summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-01-15 22:02:12 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2019-01-15 22:02:12 +0000
commit9cb102567ed215e79b0ff08ee8a5d5042285ad73 (patch)
tree08fd567c2b5dd693b115b542423d68151976a1a1
parent5f435274a48b6ff0500cd28566fde5b10500fc60 (diff)
gn build: Add a stage2 host toolchain and make the hwasan runtime buildable on x86_64 Linux.
Differential Revision: https://reviews.llvm.org/D56711
-rw-r--r--llvm/utils/gn/build/toolchain/BUILD.gn18
-rw-r--r--llvm/utils/gn/secondary/BUILD.gn7
-rw-r--r--llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn27
-rw-r--r--llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn13
-rw-r--r--llvm/utils/gn/secondary/compiler-rt/target.gni20
5 files changed, 65 insertions, 20 deletions
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index 31140ec081e..97c64ffdf2d 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -150,8 +150,10 @@ unix_toolchain("unix") {
}
}
-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 @@ if (android_ndk_path != "") {
"//: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"
diff --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn
index 229775953a4..a696e3645d0 100644
--- a/llvm/utils/gn/secondary/BUILD.gn
+++ b/llvm/utils/gn/secondary/BUILD.gn
@@ -9,9 +9,9 @@ group("default") {
"//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 @@ group("default") {
"//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
}
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn
index 9f4c697cc01..81b6f60d3d1 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn
+++ b/llvm/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 @@ action("version_script") {
"--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 @@ source_set("cxx_sources") {
}
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") {
}
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 @@ static_library("hwasan_cxx") {
}
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 = [
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
index af0f2903e51..7d280bd060e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
+++ b/llvm/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 @@ source_set("sources") {
"sanitizer_unwind_win.cc",
"sanitizer_win.cc",
]
+ if (current_cpu == "x64") {
+ sources += [ "sanitizer_linux_x86_64.S" ]
+ }
}
diff --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni
new file mode 100644
index 00000000000..7ea73b12ea1
--- /dev/null
+++ b/llvm/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"
+}