Index: compiler-rt/trunk/CMakeLists.txt =================================================================== --- compiler-rt/trunk/CMakeLists.txt +++ compiler-rt/trunk/CMakeLists.txt @@ -157,6 +157,9 @@ endif() pythonize_bool(ANDROID) +set(ANDROID_NDK_VERSION 18 + CACHE STRING "Set this to the Android NDK version that you are using") + set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) Index: compiler-rt/trunk/test/hwasan/TestCases/sizes.cpp =================================================================== --- compiler-rt/trunk/test/hwasan/TestCases/sizes.cpp +++ compiler-rt/trunk/test/hwasan/TestCases/sizes.cpp @@ -1,4 +1,6 @@ -// RUN: %clangxx_hwasan %s -lstdc++ -o %t +// This test requires operator new to be intercepted by the hwasan runtime, +// so we need to avoid linking against libc++. +// RUN: %clangxx_hwasan %s -nostdlib++ -lstdc++ -o %t // RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-max // RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t malloc 2>&1 // RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t malloc max 2>&1 | FileCheck %s --check-prefix=CHECK-max Index: compiler-rt/trunk/test/lit.common.cfg =================================================================== --- compiler-rt/trunk/test/lit.common.cfg +++ compiler-rt/trunk/test/lit.common.cfg @@ -60,7 +60,12 @@ if config.android: # Prepend the flag so that it can be overridden. config.target_cflags = "-pie -fuse-ld=gold " + config.target_cflags - config.cxx_mode_flags.append('-stdlib=libstdc++') + if config.android_ndk_version < 19: + # With a new compiler and NDK < r19 this flag ends up meaning "link against + # libc++", but NDK r19 makes this mean "link against the stub libstdc++ that + # just contains a handful of ABI functions", which makes most C++ code fail + # to link. In r19 and later we just use the default which is libc++. + config.cxx_mode_flags.append('-stdlib=libstdc++') # Clear some environment variables that might affect Clang. possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', Index: compiler-rt/trunk/test/lit.common.configured.in =================================================================== --- compiler-rt/trunk/test/lit.common.configured.in +++ compiler-rt/trunk/test/lit.common.configured.in @@ -36,6 +36,7 @@ set_default("use_lto", config.use_thinlto) set_default("use_newpm", False) set_default("android", @ANDROID_PYBOOL@) +set_default("android_ndk_version", @ANDROID_NDK_VERSION@) set_default("android_serial", "@ANDROID_SERIAL_FOR_TESTING@") set_default("android_files_to_push", []) set_default("have_rpc_xdr_h", @HAVE_RPC_XDR_H@) Index: llvm/trunk/utils/gn/build/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/build/BUILD.gn +++ llvm/trunk/utils/gn/build/BUILD.gn @@ -10,7 +10,7 @@ defines += [ "NDEBUG" ] } - cflags = target_flags + target_cflags + cflags = target_flags ldflags = target_flags + target_ldflags if (host_os == "mac" && clang_base_path != "") { 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 @@ -10,7 +10,7 @@ # Example value: getenv("HOME") + "/src/llvm-build/Release+Asserts" clang_base_path = "" - # Set this to the path to Android NDK r18b. If set, cross compilation targeting + # Set this to the path to Android NDK r19. If set, cross compilation targeting # Android will be enabled. android_ndk_path = "" } 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 @@ -2,33 +2,13 @@ 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", + "--sysroot=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64/sysroot", + "-B$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64", ] + target_ldflags += [ "-static-libstdc++" ] } Index: llvm/trunk/utils/gn/secondary/compiler-rt/test/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/compiler-rt/test/BUILD.gn +++ llvm/trunk/utils/gn/secondary/compiler-rt/test/BUILD.gn @@ -47,6 +47,7 @@ "SANITIZER_CAN_USE_CXXABI_PYBOOL=True", "COMPILER_RT_HAS_LLD_PYBOOL=True", "HAVE_RPC_XDR_H=0", + "ANDROID_NDK_VERSION=19", "ANDROID_SERIAL_FOR_TESTING=$android_serial_for_testing", ] Index: llvm/trunk/utils/gn/secondary/compiler-rt/test/test.gni =================================================================== --- llvm/trunk/utils/gn/secondary/compiler-rt/test/test.gni +++ llvm/trunk/utils/gn/secondary/compiler-rt/test/test.gni @@ -7,8 +7,7 @@ target_flags_string = "" -foreach(flag, - target_flags + target_cflags + target_ldflags + [ "-fuse-ld=lld" ]) { +foreach(flag, target_flags + target_ldflags + [ "-fuse-ld=lld" ]) { if (target_flags_string != "") { target_flags_string += " " }