[llvm-branch-commits] [clang] release/23.x: [clang][Driver] Fix libc++ include path on NetBSD (#212716) (PR #213535)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Aug 2 05:30:53 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/213535
Backport 9a19c7750f949c979372ba1d2eec8a7a40061aef
Requested by: @rorth
>From 134a37f779828c274d04ec63f7e8e49881a4314b Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Sun, 2 Aug 2026 14:22:03 +0200
Subject: [PATCH] [clang][Driver] Fix libc++ include path on NetBSD (#212716)
`clang++` defaults to `-stdlib=libc++` on NetBSD. When building with
both `clang` and `libcxx` included, the freshly built `clang++` fails to
find `<__config_site>`:
```
In file included from /usr/include/strings.h:68:
In file included from bin/../include/c++/v1/string.h:57:
bin/../include/c++/v1/__config:13:10: fatal
error: '__config_site' file not found
13 | #include <__config_site>
| ^~~~~~~~~~~~~~~
```
The file is present in `include/<triplet>/c++/v1`, but that isn't
searched by default. NetBSD has its own version of addLibCxxIncludePaths
which misses that directory.
This patch removes `NetBSD::addLibCxxIncludePaths` in favour of the
generic version in `Gnu.cpp`. The current code also adds
`/usr/include/c++`, although this directory only contains empty
directories in a default installation. It is only used when a bundled
version of LLVM is installed, which is not usually the case, and even
then contains a static version of `__config_site` that only applies to
`libcxxrt`.
Tested on `amd64-pc-netbsd10.1`, `x86_64-pc-solaris2.11`,
`x86_64-pc-linux-gnu`, and `x86_64-pc-freebsd15.1`.
(cherry picked from commit 9a19c7750f949c979372ba1d2eec8a7a40061aef)
---
clang/lib/Driver/ToolChains/NetBSD.cpp | 21 -------------------
clang/lib/Driver/ToolChains/NetBSD.h | 3 ---
.../Inputs/install_tree_with_libcxx/bin/.keep | 0
.../include/c++/v1/.keep | 0
.../Inputs/install_tree_with_libcxx/lib/.keep | 0
clang/test/Driver/netbsd.cpp | 8 +++++++
6 files changed, 8 insertions(+), 24 deletions(-)
create mode 100644 clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep
create mode 100644 clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep
create mode 100644 clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 31a5723c17c2f..f03114b53bb61 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -495,27 +495,6 @@ void NetBSD::AddClangSystemIncludeArgs(
concat(D.SysRoot, "/usr/include"));
}
-void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const {
- const std::string Candidates[] = {
- // directory relative to build tree
- concat(getDriver().Dir, "/../include/c++/v1"),
- // system install with full upstream path
- concat(getDriver().SysRoot, "/usr/include/c++/v1"),
- // system install from src
- concat(getDriver().SysRoot, "/usr/include/c++"),
- };
-
- for (const auto &IncludePath : Candidates) {
- if (!getVFS().exists(IncludePath + "/__config"))
- continue;
-
- // Use the first candidate that looks valid.
- addSystemInclude(DriverArgs, CC1Args, IncludePath);
- return;
- }
-}
-
void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/g++"), "", "",
diff --git a/clang/lib/Driver/ToolChains/NetBSD.h b/clang/lib/Driver/ToolChains/NetBSD.h
index c6a40ff34036c..bb0953c02e62e 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.h
+++ b/clang/lib/Driver/ToolChains/NetBSD.h
@@ -61,9 +61,6 @@ class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
- void addLibCxxIncludePaths(
- const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const override;
void addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
diff --git a/clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep b/clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep b/clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep b/clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index 6b8a86d6ee532..97ed44b841ed8 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/test/Driver/netbsd.cpp
@@ -191,6 +191,14 @@
// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include"
// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "{{.*}}/usr/include"
+// Test that NetBSD prefers install tree libc++ headers over system ones.
+// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
+// RUN: -ccc-install-dir %S/Inputs/install_tree_with_libcxx/bin \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN: | FileCheck %s --check-prefix=DRIVER-INSTALL-INCLUDES
+// DRIVER-INSTALL-INCLUDES: "-internal-isystem" "{{.*}}bin[[SEP:/|\\\\]]..[[SEP]]include[[SEP]]c++[[SEP]]v1"
+// DRIVER-INSTALL-INCLUDES-NOT: "-internal-isystem" "{{.*}}usr[[SEP]]include[[SEP]]c++[[SEP]]v1"
+
// Test NetBSD with libstdc++ when the sysroot path ends with `/`.
// RUN: %clangxx -### %s 2>&1 \
// RUN: --target=x86_64-unknown-netbsd \
More information about the llvm-branch-commits
mailing list