summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-01-15 21:24:00 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2019-01-15 21:24:00 +0000
commitc5de26014dea8368954be3989f13ed176cd9a2bb (patch)
tree0afc946024defae6cc2786de94f30d842870d66d
parentabd139f2e6439f59c511afbbe3ce27d80025db0f (diff)
gn build: Move target flags from toolchain to a .gni file.
While here, add a use_lld flag and default it to true when using clang on non-mac. Differential Revision: https://reviews.llvm.org/D56710
-rw-r--r--llvm/utils/gn/build/BUILD.gn8
-rw-r--r--llvm/utils/gn/build/toolchain/BUILD.gn38
-rw-r--r--llvm/utils/gn/build/toolchain/compiler.gni3
-rw-r--r--llvm/utils/gn/build/toolchain/target_flags.gni34
4 files changed, 54 insertions, 29 deletions
diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index cd9d6191322..e5c8d2a6209 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -1,6 +1,7 @@
import("//llvm/utils/gn/build/buildflags.gni")
import("//llvm/utils/gn/build/mac_sdk.gni")
import("//llvm/utils/gn/build/toolchain/compiler.gni")
+import("//llvm/utils/gn/build/toolchain/target_flags.gni")
config("compiler_defaults") {
defines = []
@@ -9,7 +10,8 @@ config("compiler_defaults") {
defines += [ "NDEBUG" ]
}
- cflags = []
+ cflags = target_flags + target_cflags
+ ldflags = target_flags + target_ldflags
if (host_os == "mac" && clang_base_path != "") {
cflags += [
@@ -104,6 +106,10 @@ config("compiler_defaults") {
cflags += [ "-Wno-nonportable-include-path" ]
}
}
+
+ if (use_lld) {
+ ldflags += [ "-fuse-ld=lld" ]
+ }
}
config("no_rtti") {
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index dd4d0f9ee83..31140ec081e 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -12,16 +12,10 @@ declare_args() {
template("unix_toolchain") {
toolchain(target_name) {
forward_variables_from(invoker, "*")
- if (!defined(target_cflags)) {
- target_cflags = ""
- }
- if (!defined(target_ldflags)) {
- target_ldflags = ""
- }
tool("cc") {
depfile = "{{output}}.d"
- command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $target_cflags"
+ command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs = [
@@ -31,7 +25,7 @@ template("unix_toolchain") {
tool("cxx") {
depfile = "{{output}}.d"
- command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $target_cflags"
+ command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs = [
@@ -41,7 +35,7 @@ template("unix_toolchain") {
tool("asm") {
depfile = "{{output}}.d"
- command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}} $target_cflags"
+ command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs = [
@@ -69,10 +63,10 @@ template("unix_toolchain") {
tool("solink") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (current_os == "mac") {
- command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib"
} else {
- command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".so"
}
description = "SOLINK $outfile"
@@ -87,10 +81,10 @@ template("unix_toolchain") {
tool("solink_module") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (current_os == "mac") {
- command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib"
} else {
- command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".so"
}
description = "SOLINK $outfile"
@@ -104,10 +98,9 @@ template("unix_toolchain") {
tool("link") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (current_os == "mac") {
- command =
- "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
} else {
- command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group $target_ldflags"
+ command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
}
description = "LINK $outfile"
outputs = [
@@ -173,19 +166,8 @@ if (android_ndk_path != "") {
toolchain_args = {
current_os = "android"
current_cpu = "arm64"
+ use_lld = true
}
-
- libcxx_path = "$android_ndk_path/sources/cxx-stl/llvm-libc++"
- platform_lib_path =
- "$android_ndk_path/platforms/android-21/arch-arm64/usr/lib"
- libgcc_path = "$android_ndk_path/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x"
-
- target_flags =
- "--target=aarch64-linux-android21 --sysroot=$android_ndk_path/sysroot"
- target_cflags = "$target_flags -isystem $libcxx_path/include"
- target_ldflags = "$target_flags -fuse-ld=lld -B$platform_lib_path -L$platform_lib_path -L$libgcc_path"
- target_ldflags +=
- " -nostdlib++ -L$libcxx_path/libs/arm64-v8a -l:libc++.a.21"
}
}
diff --git a/llvm/utils/gn/build/toolchain/compiler.gni b/llvm/utils/gn/build/toolchain/compiler.gni
index c7e89b32a74..3c419fb29a1 100644
--- a/llvm/utils/gn/build/toolchain/compiler.gni
+++ b/llvm/utils/gn/build/toolchain/compiler.gni
@@ -19,4 +19,7 @@ declare_args() {
# Set if the host compiler is clang. On by default on Mac or if
# clang_base_path is set.
is_clang = host_os == "mac" || clang_base_path != ""
+
+ # Set this to true to link with LLD instead of the default linker.
+ use_lld = clang_base_path != "" && host_os != "mac"
}
diff --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni
new file mode 100644
index 00000000000..6b6373a0093
--- /dev/null
+++ b/llvm/utils/gn/build/toolchain/target_flags.gni
@@ -0,0 +1,34 @@
+import("//llvm/triples.gni")
+import("//llvm/utils/gn/build/toolchain/compiler.gni")
+
+target_flags = []
+target_cflags = []
+target_ldflags = []
+
+if (current_os == "android") {
+ assert(current_cpu == "arm64", "current_cpu not supported")
+
+ libcxx_path = "$android_ndk_path/sources/cxx-stl/llvm-libc++"
+ platform_lib_path =
+ "$android_ndk_path/platforms/android-21/arch-arm64/usr/lib"
+ libgcc_path = "$android_ndk_path/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x"
+
+ target_flags += [
+ "--target=$llvm_current_triple",
+ "--sysroot=$android_ndk_path/sysroot",
+ ]
+ target_cflags += [
+ "-isystem",
+ "$libcxx_path/include",
+ ]
+ target_ldflags += [
+ "-B$platform_lib_path",
+ "-L$platform_lib_path",
+ "-L$libgcc_path",
+ ]
+ target_ldflags += [
+ "-nostdlib++",
+ "-L$libcxx_path/libs/arm64-v8a",
+ "-l:libc++.a.21",
+ ]
+}