]> granicus.if.org Git - clang/commitdiff
[Driver] Include the Android multiarch includes.
authorDan Albert <danalbert@google.com>
Wed, 4 Apr 2018 21:28:34 +0000 (21:28 +0000)
committerDan Albert <danalbert@google.com>
Wed, 4 Apr 2018 21:28:34 +0000 (21:28 +0000)
Summary:
Most Android headers live in a single directory, but a small handful
live in multiarch directories.

Reviewers: srhines

Reviewed By: srhines

Subscribers: javed.absar, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329234 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
lib/Driver/ToolChains/Linux.cpp
test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/x86_64-linux-android/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtend.o [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/include/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/aarch64-linux-android/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/arm-linux-androideabi/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/i686-linux-android/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/x86_64-linux-android/.keep [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.bfd [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.gold [new file with mode: 0644]
test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/lib/.keep [new file with mode: 0644]
test/Driver/android-ndk-standalone.cpp

index aa9fefc5c75f2960481110220c5df44363acae6e..ca90b3dbd5b697935a0724069063cf7d1bba6271 100644 (file)
@@ -42,6 +42,7 @@ static std::string getMultiarchTriple(const Driver &D,
                                       StringRef SysRoot) {
   llvm::Triple::EnvironmentType TargetEnvironment =
       TargetTriple.getEnvironment();
+  bool IsAndroid = TargetTriple.isAndroid();
 
   // For most architectures, just use whatever we have rather than trying to be
   // clever.
@@ -55,7 +56,9 @@ static std::string getMultiarchTriple(const Driver &D,
   // regardless of what the actual target triple is.
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
-    if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
+    if (IsAndroid) {
+      return "arm-linux-androideabi";
+    } else if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
       if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
         return "arm-linux-gnueabihf";
     } else {
@@ -74,16 +77,22 @@ static std::string getMultiarchTriple(const Driver &D,
     }
     break;
   case llvm::Triple::x86:
+    if (IsAndroid)
+      return "i686-linux-android";
     if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
       return "i386-linux-gnu";
     break;
   case llvm::Triple::x86_64:
+    if (IsAndroid)
+      return "x86_64-linux-android";
     // We don't want this for x32, otherwise it will match x86_64 libs
     if (TargetEnvironment != llvm::Triple::GNUX32 &&
         D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
       return "x86_64-linux-gnu";
     break;
   case llvm::Triple::aarch64:
+    if (IsAndroid)
+      return "aarch64-linux-android";
     if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
       return "aarch64-linux-gnu";
     break;
@@ -96,6 +105,8 @@ static std::string getMultiarchTriple(const Driver &D,
       return "mips-linux-gnu";
     break;
   case llvm::Triple::mipsel:
+    if (IsAndroid)
+      return "mipsel-linux-android";
     if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu"))
       return "mipsel-linux-gnu";
     break;
@@ -106,6 +117,8 @@ static std::string getMultiarchTriple(const Driver &D,
       return "mips64-linux-gnuabi64";
     break;
   case llvm::Triple::mips64el:
+    if (IsAndroid)
+      return "mips64el-linux-android";
     if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
       return "mips64el-linux-gnu";
     if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64"))
@@ -717,6 +730,14 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
   default:
     break;
   }
+
+  const std::string AndroidMultiarchIncludeDir =
+      std::string("/usr/include/") +
+      getMultiarchTriple(D, getTriple(), SysRoot);
+  const StringRef AndroidMultiarchIncludeDirs[] = {AndroidMultiarchIncludeDir};
+  if (getTriple().isAndroid())
+    MultiarchIncludeDirs = AndroidMultiarchIncludeDirs;
+
   for (StringRef Dir : MultiarchIncludeDirs) {
     if (D.getVFS().exists(SysRoot + Dir)) {
       addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/x86_64-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/x86_64-linux-android/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtend.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/include/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/aarch64-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/aarch64-linux-android/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/arm-linux-androideabi/.keep b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/arm-linux-androideabi/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/i686-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/i686-linux-android/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/x86_64-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/x86_64-linux-android/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld b/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.bfd
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.gold
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/lib/.keep b/test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
index 86ab85269f761724db3cd73e8bde9c7f05684a68..7c2c81496725bf64c61d2bf54187009199669efb 100644 (file)
@@ -19,6 +19,7 @@
 // CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -56,6 +57,7 @@
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-AARCH64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARM64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4.9/i686-linux-android"
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-I686: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/i686-linux-android"
 // CHECK-I686: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-I686: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-I686: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-I686: "-L{{.*}}/lib/gcc/i686-linux-android/4.9"
 // CHECK-I686: "-L{{.*}}/lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/lib"
 // CHECK-I686: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target x86_64-linux-android \
+// RUN:     -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-X86_64 %s
+// CHECK-X86_64: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-X86_64: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-X86_64: "-internal-isystem" "{{.*}}/include/c++/4.9/x86_64-linux-android"
+// CHECK-X86_64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-X86_64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/x86_64-linux-android"
+// CHECK-X86_64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-X86_64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-X86_64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-X86_64: "-L{{.*}}/lib/gcc/x86_64-linux-android/4.9"
+// CHECK-X86_64: "-L{{.*}}/lib/gcc/x86_64-linux-android/4.9/../../../../x86_64-linux-android/lib"
+// CHECK-X86_64: "-L{{.*}}/sysroot/usr/lib"