diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -448,7 +448,7 @@ # -Wl,-z,defs doesn't work with sanitizers. # https://clang.llvm.org/docs/AddressSanitizer.html if (current_os != "ios" && current_os != "mac" && current_os != "win" && - current_os != "android" && !(use_asan || use_tsan || use_ubsan)) { + !(use_asan || use_tsan || use_ubsan)) { ldflags = [ "-Wl,-z,defs" ] } } diff --git a/llvm/utils/gn/build/BUILDCONFIG.gn b/llvm/utils/gn/build/BUILDCONFIG.gn --- a/llvm/utils/gn/build/BUILDCONFIG.gn +++ b/llvm/utils/gn/build/BUILDCONFIG.gn @@ -49,3 +49,22 @@ } set_default_toolchain(host_toolchain) + +if (current_os == "android") { + foreach(target_type, + [ + "executable", + "loadable_module", + "shared_library", + ]) { + template(target_type) { + target(target_type, target_name) { + forward_variables_from(invoker, "*") + if (!defined(deps)) { + deps = [] + } + deps += [ "//llvm/utils/gn/build/libs/implicit" ] + } + } + } +} diff --git a/llvm/utils/gn/build/libs/implicit/BUILD.gn b/llvm/utils/gn/build/libs/implicit/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/build/libs/implicit/BUILD.gn @@ -0,0 +1,10 @@ +# This target represents the library dependencies that are implicitly linked by +# the compiler. +if (current_os == "android") { + group("implicit") { + deps = [ + "//compiler-rt/lib/builtins", + "//libunwind/src:unwind_static", + ] + } +} diff --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni --- a/llvm/utils/gn/build/toolchain/target_flags.gni +++ b/llvm/utils/gn/build/toolchain/target_flags.gni @@ -17,10 +17,7 @@ "--gcc-toolchain=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64", "-fno-emulated-tls", ] - target_ldflags += [ - "-static-libstdc++", - "--unwindlib=none", - ] + target_ldflags += [ "-static-libstdc++" ] if (current_cpu == "arm") { target_flags += [ "-march=armv7-a" ] } diff --git a/llvm/utils/gn/secondary/libunwind/src/BUILD.gn b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn --- a/llvm/utils/gn/secondary/libunwind/src/BUILD.gn +++ b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn @@ -57,7 +57,7 @@ } else if (current_cpu == "x64") { unwind_output_dir = "$crt_current_out_dir/x86_64" } else if (current_cpu == "x86") { - unwind_output_dir = "$crt_current_out_dir/i686" + unwind_output_dir = "$crt_current_out_dir/i386" } } else { unwind_output_dir = runtimes_dir