Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -2343,7 +2343,15 @@ const char *Tool, const ToolChain &TC, SmallVectorImpl &Names) const { // FIXME: Needs a better variable than DefaultTargetTriple - Names.emplace_back(DefaultTargetTriple + "-" + Tool); + StringRef Triple = DefaultTargetTriple; + + // On Android, the target triple can include a version number that needs to + // be stripped. + if (TC.getTriple().isAndroid()) { + Triple = Triple.rtrim("0123456789"); + } + + Names.emplace_back((Triple + "-" + Tool).str()); Names.emplace_back(Tool); // Allow the discovery of tools prefixed with LLVM's default target triple. Index: test/Driver/android-triple-version.c =================================================================== --- /dev/null +++ test/Driver/android-triple-version.c @@ -0,0 +1,10 @@ +// Android's target triples can contain a version number in the environment +// field (e.g. arm-linux-androideabi9). +// Make sure that any version is stripped when finding toolchain binaries. + +// RUN: env "PATH=%S/Inputs/android_triple_version/bin" \ +// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 | FileCheck %s +// RUN: env "PATH=%S/Inputs/android_triple_version/bin" \ +// RUN: %clang -### -target arm-linux-androideabi9 %s 2>&1 | FileCheck %s + +// CHECK: arm-linux-androideabi-ld