Skip to content

Commit 198fbcb

Browse files
committed
Driver: Don't look for libc++ headers in the install directory on Android.
The NDK uses a separate set of libc++ headers in the sysroot. Any headers in the installation directory are not going to work on Android, not least because they use a different name for the inline namespace (std::__1 instead of std::__ndk1). This effectively makes it impossible to produce a single toolchain that is capable of targeting both Android and another platform that expects libc++ headers to be installed in the installation directory, such as Mac. In order to allow this scenario to work, stop looking for headers in the install directory on Android. Differential Revision: https://reviews.llvm.org/D71154
1 parent 7ac9662 commit 198fbcb

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -888,20 +888,25 @@ static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem &vfs,
888888
void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
889889
llvm::opt::ArgStringList &CC1Args) const {
890890
const std::string& SysRoot = computeSysRoot();
891-
const std::string LibCXXIncludePathCandidates[] = {
892-
DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
893-
// If this is a development, non-installed, clang, libcxx will
894-
// not be found at ../include/c++ but it likely to be found at
895-
// one of the following two locations:
896-
DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
897-
DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/include/c++") };
898-
for (const auto &IncludePath : LibCXXIncludePathCandidates) {
891+
auto AddIncludePath = [&](std::string Path) {
892+
std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
899893
if (IncludePath.empty() || !getVFS().exists(IncludePath))
900-
continue;
901-
// Use the first candidate that exists.
894+
return false;
902895
addSystemInclude(DriverArgs, CC1Args, IncludePath);
896+
return true;
897+
};
898+
// Android never uses the libc++ headers installed alongside the toolchain,
899+
// which are generally incompatible with the NDK libraries anyway.
900+
if (!getTriple().isAndroid())
901+
if (AddIncludePath(getDriver().Dir + "/../include/c++"))
902+
return;
903+
// If this is a development, non-installed, clang, libcxx will
904+
// not be found at ../include/c++ but it likely to be found at
905+
// one of the following two locations:
906+
if (AddIncludePath(SysRoot + "/usr/local/include/c++"))
907+
return;
908+
if (AddIncludePath(SysRoot + "/usr/include/c++"))
903909
return;
904-
}
905910
}
906911

907912
void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Check that we don't find the libc++ in the installation directory when
2+
// targeting Android.
3+
4+
// RUN: mkdir -p %t/bin
5+
// RUN: mkdir -p %t/include/c++/v1
6+
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
7+
// RUN: -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
8+
// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

clang/test/Driver/stdlibxx-isystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// By default, we should search for libc++ next to the driver.
77
// RUN: mkdir -p %t/bin
88
// RUN: mkdir -p %t/include/c++/v1
9-
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
9+
// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
1010
// RUN: -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
1111
// RUN: FileCheck -check-prefix=LIBCXX %s
1212
// RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
1616
// LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
1717

1818
// Passing -stdlib++-isystem should suppress the default search.
19-
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
19+
// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
2020
// RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
2121
// RUN: -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NODEFAULT %s
2222
// RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -26,7 +26,7 @@
2626
// NODEFAULT-NOT: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
2727

2828
// And we should add it as an -internal-isystem.
29-
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
29+
// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
3030
// RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
3131
// RUN: -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=INCPATH %s
3232
// RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -35,7 +35,7 @@
3535
// INCPATH: "-internal-isystem" "/tmp/foo" "-internal-isystem" "/tmp/bar"
3636

3737
// We shouldn't pass the -stdlib++-isystem to cc1.
38-
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
38+
// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
3939
// RUN: -stdlib++-isystem /tmp -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
4040
// RUN: FileCheck -check-prefix=NOCC1 %s
4141
// RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -44,7 +44,7 @@
4444
// NOCC1-NOT: "-stdlib++-isystem" "/tmp"
4545

4646
// It should respect -nostdinc++.
47-
// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
47+
// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
4848
// RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \
4949
// RUN: -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s
5050
// RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \

0 commit comments

Comments
 (0)