Author: Rainer Orth Date: 2026-08-02T14:22:03+02:00 New Revision: 9a19c7750f949c979372ba1d2eec8a7a40061aef
URL: https://github.com/llvm/llvm-project/commit/9a19c7750f949c979372ba1d2eec8a7a40061aef DIFF: https://github.com/llvm/llvm-project/commit/9a19c7750f949c979372ba1d2eec8a7a40061aef.diff LOG: [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`. Added: clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep Modified: clang/lib/Driver/ToolChains/NetBSD.cpp clang/lib/Driver/ToolChains/NetBSD.h clang/test/Driver/netbsd.cpp Removed: ################################################################################ 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 \ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
