Index: lib/Driver/ToolChains/Linux.cpp =================================================================== --- lib/Driver/ToolChains/Linux.cpp +++ lib/Driver/ToolChains/Linux.cpp @@ -42,6 +42,7 @@ 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 @@ // 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,17 +77,23 @@ } break; case llvm::Triple::x86: - if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) + if (IsAndroid) + return "i686-linux-android"; + else 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 && + else 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 (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) + if (IsAndroid) + return "aarch64-linux-android"; + else if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) return "aarch64-linux-gnu"; break; case llvm::Triple::aarch64_be: @@ -96,6 +105,8 @@ 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 @@ 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,15 @@ 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); Index: test/Driver/android-ndk-standalone.cpp =================================================================== --- test/Driver/android-ndk-standalone.cpp +++ test/Driver/android-ndk-standalone.cpp @@ -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:[^"]+]]" @@ -115,6 +117,7 @@ // 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:[^"]+]]" @@ -154,6 +157,7 @@ // 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:[^"]+]]" @@ -203,6 +207,7 @@ // 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:[^"]+]]" @@ -219,6 +224,7 @@ // 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:[^"]+]]" @@ -321,9 +327,28 @@ // 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"