From d6c6df822307d61791cd5973908a6966571190b9 Mon Sep 17 00:00:00 2001
From: Chih-Hung Hsieh <chh@google.com>
Date: Wed, 1 Jun 2016 20:48:46 +0000
Subject: [PATCH] [driver][arm] add armv7 and thumb include and lib paths

Add a new test android-ndk-standalone.cpp
with new Android NDK release tree structure.
Detect armv7 sub architecture and thumb mode,
to add system include and link search paths.

Differential Revision: http://reviews.llvm.org/D20600



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271427 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Driver/ToolChains.cpp                     |  52 +++-
 .../aarch64-linux-android/bin/ld              |   0
 .../aarch64-linux-android/bin/ld.bfd          |   0
 .../aarch64-linux-android/bin/ld.gold         |   0
 .../aarch64-linux-android/lib/.keep           |   0
 .../arm-linux-androideabi/bin/ld              |   0
 .../arm-linux-androideabi/bin/ld.bfd          |   0
 .../arm-linux-androideabi/bin/ld.gold         |   0
 .../lib/armv7-a/thumb/.keep                   |   0
 .../arm-linux-androideabi/lib/thumb/.keep     |   0
 .../bin/aarch64-linux-android-ld              |   0
 .../bin/aarch64-linux-android-ld.bfd          |   0
 .../bin/aarch64-linux-android-ld.gold         |   0
 .../bin/arm-linux-androideabi-ld              |   0
 .../bin/arm-linux-androideabi-ld.bfd          |   0
 .../bin/arm-linux-androideabi-ld.gold         |   0
 .../bin/i686-linux-android-ld                 |   0
 .../bin/i686-linux-android-ld.bfd             |   0
 .../bin/i686-linux-android-ld.gold            |   0
 .../bin/mipsel-linux-android-ld               |   0
 .../bin/mipsel-linux-android-ld.bfd           |   0
 .../bin/mipsel-linux-android-ld.gold          |   0
 .../i686-linux-android/bin/ld                 |   0
 .../i686-linux-android/bin/ld.bfd             |   0
 .../i686-linux-android/bin/ld.gold            |   0
 .../i686-linux-android/lib/.keep              |   0
 .../c++/4.9/aarch64-linux-android/.keep       |   0
 .../arm-linux-androideabi/armv7-a/thumb/.keep |   0
 .../c++/4.9/arm-linux-androideabi/thumb/.keep |   0
 .../include/c++/4.9/backward/.keep            |   0
 .../include/c++/4.9/i686-linux-android/.keep  |   0
 .../4.9/mipsel-linux-android/mips-r2/.keep    |   0
 .../4.9/mipsel-linux-android/mips-r6/.keep    |   0
 .../gcc/aarch64-linux-android/4.9/crtbegin.o  |   0
 .../gcc/aarch64-linux-android/4.9/crtend.o    |   0
 .../aarch64-linux-android/4.9/include/.keep   |   0
 .../4.9/armv7-a/crtbegin.o                    |   0
 .../4.9/armv7-a/crtend.o                      |   0
 .../4.9/armv7-a/thumb/crtbegin.o              |   0
 .../4.9/armv7-a/thumb/crtend.o                |   0
 .../gcc/arm-linux-androideabi/4.9/crtbegin.o  |   0
 .../gcc/arm-linux-androideabi/4.9/crtend.o    |   0
 .../arm-linux-androideabi/4.9/include/.keep   |   0
 .../4.9/thumb/crtbegin.o                      |   0
 .../arm-linux-androideabi/4.9/thumb/crtend.o  |   0
 .../lib/gcc/i686-linux-android/4.9/crtbegin.o |   0
 .../lib/gcc/i686-linux-android/4.9/crtend.o   |   0
 .../gcc/i686-linux-android/4.9/include/.keep  |   0
 .../gcc/mipsel-linux-android/4.9/crtbegin.o   |   0
 .../lib/gcc/mipsel-linux-android/4.9/crtend.o |   0
 .../mipsel-linux-android/4.9/include/.keep    |   0
 .../4.9/mips-r2/crtbegin.o                    |   0
 .../mipsel-linux-android/4.9/mips-r2/crtend.o |   0
 .../4.9/mips-r6/crtbegin.o                    |   0
 .../mipsel-linux-android/4.9/mips-r6/crtend.o |   0
 .../mipsel-linux-android/bin/ld               |   0
 .../mipsel-linux-android/bin/ld.bfd           |   0
 .../mipsel-linux-android/bin/ld.gold          |   0
 .../mipsel-linux-android/lib/.keep            |   0
 .../sysroot/usr/include/.keep                 |   0
 .../sysroot/usr/lib/crtbegin_dynamic.o        |   0
 .../sysroot/usr/lib/crtbegin_so.o             |   0
 .../sysroot/usr/lib/crtbegin_static.o         |   0
 .../sysroot/usr/lib/crtend_android.o          |   0
 .../sysroot/usr/lib/crtend_so.o               |   0
 test/Driver/android-ndk-standalone.cpp        | 279 ++++++++++++++++++
 66 files changed, 330 insertions(+), 1 deletion(-)
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/lib/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/armv7-a/thumb/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/thumb/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/lib/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/aarch64-linux-android/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/thumb/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/backward/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/i686-linux-android/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r2/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r6/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/include/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/include/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/include/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/include/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtbegin.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtend.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.bfd
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.gold
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/lib/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/.keep
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_dynamic.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_so.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_static.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_android.o
 create mode 100644 test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_so.o
 create mode 100644 test/Driver/android-ndk-standalone.cpp

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index a26ca087ca6..8242b969876 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1790,6 +1790,10 @@ static void addMultilibFlag(bool Enabled, const char *const Flag,
     Flags.push_back(std::string("-") + Flag);
 }
 
+static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) {
+  return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb;
+}
+
 static bool isMipsArch(llvm::Triple::ArchType Arch) {
   return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel ||
          Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el;
@@ -2313,6 +2317,48 @@ static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple,
   return false;
 }
 
+static void findAndroidArmMultilibs(const Driver &D,
+                                    const llvm::Triple &TargetTriple,
+                                    StringRef Path, const ArgList &Args,
+                                    DetectedMultilibs &Result) {
+  // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb.
+  FilterNonExistent NonExistent(Path, D.getVFS());
+  Multilib ArmV7Multilib = makeMultilib("/armv7-a")
+                               .flag("+armv7")
+                               .flag("-thumb");
+  Multilib ThumbMultilib = makeMultilib("/thumb")
+                               .flag("-armv7")
+                               .flag("+thumb");
+  Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb")
+                               .flag("+armv7")
+                               .flag("+thumb");
+  Multilib DefaultMultilib = makeMultilib("")
+                               .flag("-armv7")
+                               .flag("-thumb");
+  MultilibSet AndroidArmMultilibs =
+      MultilibSet()
+          .Either(ThumbMultilib, ArmV7Multilib,
+                  ArmV7ThumbMultilib, DefaultMultilib)
+          .FilterOut(NonExistent);
+
+  Multilib::flags_list Flags;
+  llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ);
+  bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm;
+  bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb;
+  bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7;
+  bool IsThumbMode = IsThumbArch ||
+      Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) ||
+      (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::IK_THUMB);
+  bool IsArmV7Mode = (IsArmArch || IsThumbArch) &&
+      (llvm::ARM::parseArchVersion(Arch) == 7 ||
+       (IsArmArch && Arch == "" && IsV7SubArch));
+  addMultilibFlag(IsArmV7Mode, "armv7", Flags);
+  addMultilibFlag(IsThumbMode, "thumb", Flags);
+
+  if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib))
+    Result.Multilibs = AndroidArmMultilibs;
+}
+
 static bool findBiarchMultilibs(const Driver &D,
                                 const llvm::Triple &TargetTriple,
                                 StringRef Path, const ArgList &Args,
@@ -2504,9 +2550,13 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
 
       DetectedMultilibs Detected;
 
+      // Android standalone toolchain could have multilibs for ARM and Thumb.
       // Debian mips multilibs behave more like the rest of the biarch ones,
       // so handle them there
-      if (isMipsArch(TargetArch)) {
+      if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) {
+        // It should also work without multilibs in a simplified toolchain.
+        findAndroidArmMultilibs(D, TargetTriple, LI->getName(), Args, Detected);
+      } else if (isMipsArch(TargetArch)) {
         if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected))
           continue;
       } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args,
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld b/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/lib/.keep b/test/Driver/Inputs/basic_android_ndk_tree/aarch64-linux-android/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld b/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/armv7-a/thumb/.keep b/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/armv7-a/thumb/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/thumb/.keep b/test/Driver/Inputs/basic_android_ndk_tree/arm-linux-androideabi/lib/thumb/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld b/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld b/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld b/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld b/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld b/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/lib/.keep b/test/Driver/Inputs/basic_android_ndk_tree/i686-linux-android/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/aarch64-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/aarch64-linux-android/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/thumb/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/arm-linux-androideabi/thumb/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/backward/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/backward/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/i686-linux-android/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/i686-linux-android/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r2/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r2/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r6/.keep b/test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/mipsel-linux-android/mips-r6/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/aarch64-linux-android/4.9/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/arm-linux-androideabi/4.9/thumb/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/i686-linux-android/4.9/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r2/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtbegin.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtbegin.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtend.o b/test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/mipsel-linux-android/4.9/mips-r6/crtend.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld b/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.bfd b/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.bfd
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.gold b/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld.gold
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/lib/.keep b/test/Driver/Inputs/basic_android_ndk_tree/mipsel-linux-android/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/.keep b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_dynamic.o b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_dynamic.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_so.o b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_so.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_static.o b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtbegin_static.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_android.o b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_android.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_so.o b/test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/lib/crtend_so.o
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/Driver/android-ndk-standalone.cpp b/test/Driver/android-ndk-standalone.cpp
new file mode 100644
index 00000000000..c7042be42f8
--- /dev/null
+++ b/test/Driver/android-ndk-standalone.cpp
@@ -0,0 +1,279 @@
+// Test header and library paths when Clang is used with Android standalone
+// toolchain.
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  %s
+// CHECK: {{.*}}clang{{.*}}" "-cc1"
+// CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a"
+// CHECK-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
+// CHECK: "-internal-isystem" "{{.*}}/lib/clang/{{[^/]*}}/include"
+// CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a/thumb"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/arm-linux-androideabi/lib"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a/thumb"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a"
+// CHECK-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target armv7a-none-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7 %s
+// CHECK-ARMV7: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK-ARMV7-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-ARMV7: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
+// CHECK-ARMV7: "-internal-isystem" "{{.*}}/lib/clang/{{[^/]*}}/include"
+// CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-ARMV7: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-ARMV7: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-ARMV7: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a/thumb"
+// CHECK-ARMV7-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-ARMV7: "-L{{.*}}/sysroot/usr/lib"
+//
+// Other flags that can trigger armv7 mode.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -march=armv7 \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7 %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -march=armv7a \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7 %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -march=armv7-a \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7 %s
+//
+// ARM thumb mode.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -mthumb \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-THUMB %s
+// CHECK-THUMB: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7/thumb"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7/thumb"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7"
+// CHECK-THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
+// CHECK-THUMB: "-internal-isystem" "{{.*}}/lib/clang/{{[^/]*}}/include"
+// CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-THUMB: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-THUMB: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7/thumb"
+// CHECK-THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-THUMB: "-L{{.*}}/sysroot/usr/lib"
+//
+// ARM V7 thumb mode.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -march=armv7-a -mthumb \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7THUMB %s
+// CHECK-ARMV7THUMB: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a/thumb"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi/thumb"
+// CHECK-ARMV7THUMB-NOT: "-internal-isystem" "{{.*}}/include/c++/4.9/arm-linux-androideabi"
+// CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
+// CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/lib/clang/{{[^/]*}}/include"
+// CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-ARMV7THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-ARMV7THUMB: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-ARMV7THUMB: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/thumb"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib/armv7-a"
+// CHECK-ARMV7THUMB-NOT: "-L{{.*}}/lib/gcc/arm-linux-androideabi/4.9/../{{[^ ]*}}/lib"
+// CHECK-ARMV7THUMB: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target armv7a-none-linux-androideabi -stdlib=libstdc++ \
+// RUN:     -mthumb \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck  --check-prefix=CHECK-ARMV7THUMB %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target aarch64-linux-android -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64 %s
+// CHECK-AARCH64: {{.*}}clang{{.*}}" "-cc1"
+// 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/include"
+// CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-AARCH64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-AARCH64: "-L{{.*}}/lib/gcc/aarch64-linux-android/4.9"
+// CHECK-AARCH64: "-L{{.*}}/lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/lib"
+// CHECK-AARCH64: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target arm64-linux-android -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ARM64 %s
+// CHECK-ARM64: {{.*}}clang{{.*}}" "-cc1"
+// 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/include"
+// CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-ARM64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ARM64: "-L{{.*}}/lib/gcc/aarch64-linux-android/4.9"
+// CHECK-ARM64: "-L{{.*}}/lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/lib"
+// CHECK-ARM64: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target mipsel-linux-android \
+// RUN:     -mips32 -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS %s
+// CHECK-MIPS: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MIPS: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// CHECK-MIPS: "-internal-isystem" "{{.*}}/include/c++/4.9/mipsel-linux-android"
+// CHECK-MIPS: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-MIPS: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-MIPS: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-MIPS: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-MIPS: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9"
+// CHECK-MIPS: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9/../../../../mipsel-linux-android/lib"
+// CHECK-MIPS: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target mipsel-linux-android \
+// RUN:     -march=mips32 -mips32r2 -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPSR2 %s
+// CHECK-MIPSR2: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MIPSR2: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// NOT-YET-CHECK-MIPSR2: "-internal-isystem" "{{.*}}/include/c++/4.9/mipsel-linux-android/mips-r2"
+// CHECK-MIPSR2: "-internal-isystem" "{{.*}}/include/c++/4.9/mipsel-linux-android"
+// CHECK-MIPSR2: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-MIPSR2: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-MIPSR2: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-MIPSR2: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-MIPSR2: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9/mips-r2"
+// CHECK-MIPSR2: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9/../../../../mipsel-linux-android/lib"
+// CHECK-MIPSR2: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target mipsel-linux-android \
+// RUN:     -mips32r6 -stdlib=libstdc++ \
+// RUN:     -B%S/Inputs/basic_android_ndk_tree \
+// RUN:     --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPSR6 %s
+// CHECK-MIPSR6: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MIPSR6: "-internal-isystem" "{{.*}}/include/c++/4.9"
+// NOT-YET-CHECK-MIPSR6: "-internal-isystem" "{{.*}}/include/c++/4.9/mipsel-linux-android/mips-r6"
+// CHECK-MIPSR6: "-internal-isystem" "{{.*}}/include/c++/4.9/mipsel-linux-android"
+// CHECK-MIPSR6: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-MIPSR6: "-internal-externc-isystem" "{{.*}}/sysroot/include"
+// CHECK-MIPSR6: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
+// CHECK-MIPSR6: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-MIPSR6: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9/mips-r6"
+// CHECK-MIPSR6: "-L{{.*}}/lib/gcc/mipsel-linux-android/4.9/../../../../mipsel-linux-android/lib"
+// CHECK-MIPSR6: "-L{{.*}}/sysroot/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target i686-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-I686 %s
+// CHECK-I686: {{.*}}clang{{.*}}" "-cc1"
+// 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/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"
-- 
GitLab