Index: llvm/trunk/utils/gn/build/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/build/BUILD.gn +++ llvm/trunk/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 @@ 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 @@ cflags += [ "-Wno-nonportable-include-path" ] } } + + if (use_lld) { + ldflags += [ "-fuse-ld=lld" ] + } } config("no_rtti") { 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 @@ -12,16 +12,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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" } } Index: llvm/trunk/utils/gn/build/toolchain/compiler.gni =================================================================== --- llvm/trunk/utils/gn/build/toolchain/compiler.gni +++ llvm/trunk/utils/gn/build/toolchain/compiler.gni @@ -19,4 +19,7 @@ # 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" } Index: llvm/trunk/utils/gn/build/toolchain/target_flags.gni =================================================================== --- llvm/trunk/utils/gn/build/toolchain/target_flags.gni +++ llvm/trunk/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", + ] +}