gn build: Upgrade to NDK r19.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 5 Feb 2019 05:10:19 +0000 (05:10 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 5 Feb 2019 05:10:19 +0000 (05:10 +0000)
NDK r19 includes a sysroot that can be used directly by the compiler
without creating a standalone toolchain, so we just need a handful
of flags to point Clang there.

Differential Revision: https://reviews.llvm.org/D57733

llvm-svn: 353139

compiler-rt/CMakeLists.txt
compiler-rt/test/hwasan/TestCases/sizes.cpp
compiler-rt/test/lit.common.cfg
compiler-rt/test/lit.common.configured.in
llvm/utils/gn/build/BUILD.gn
llvm/utils/gn/build/toolchain/compiler.gni
llvm/utils/gn/build/toolchain/target_flags.gni
llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
llvm/utils/gn/secondary/compiler-rt/test/test.gni

index bc0233c..3b2b514 100644 (file)
@@ -157,6 +157,9 @@ if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
 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 52217de..8effe3c 100644 (file)
@@ -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 6688c71..6965fa6 100644 (file)
@@ -60,7 +60,12 @@ if config.asan_shadow_scale != '':
 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 df326a6..e1884b4 100644 (file)
@@ -36,6 +36,7 @@ set_default("use_thinlto", False)
 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 e33cde2..e323f99 100644 (file)
@@ -10,7 +10,7 @@ config("compiler_defaults") {
     defines += [ "NDEBUG" ]
   }
 
-  cflags = target_flags + target_cflags
+  cflags = target_flags
   ldflags = target_flags + target_ldflags
 
   if (host_os == "mac" && clang_base_path != "") {
index 3c419fb..37ad1f5 100644 (file)
@@ -10,7 +10,7 @@ declare_args() {
   # 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 6b6373a..3ad02a9 100644 (file)
@@ -2,33 +2,13 @@ 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",
+    "--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 90a9201..a5fa1a3 100644 (file)
@@ -47,6 +47,7 @@ write_cmake_config("lit_common_configured") {
     "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 4144482..e233593 100644 (file)
@@ -7,8 +7,7 @@ declare_args() {
 
 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 += " "
   }