https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/175593
>From bae69a88b2d6530d582daf208deef98424b0bcbd Mon Sep 17 00:00:00 2001 From: Joseph Huber <[email protected]> Date: Mon, 12 Jan 2026 11:43:19 -0600 Subject: [PATCH 1/2] [Clang] Include LLVM libc header directory from Linux Summary: The LLVM-libc stores its headers in the target-specific include directory. This PR makes the Linux toolchain include this directory when the environment is LLVM. This should allow the following to work correctly when building the LLVM libc ```shell $> clang --target=x86_64-unknown-linux-llvm -static foo.c ``` In the future we might want to consider making a separate toolchain, but considering that the LLVM-libc intentionally shares a lot of compatibility with GCC I thnk it's easier to just to do conditional operations like this. --- clang/lib/Driver/ToolChains/Linux.cpp | 7 +++++++ clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep | 0 .../Inputs/basic_llvm_linux_tree/include/c++/v1/.keep | 0 .../include/x86_64-unknown-linux-llvm/.keep | 0 .../include/x86_64-unknown-linux-llvm/c++/v1/.keep | 0 .../lib/x86_64-unknown-linux-llvm/.keep | 0 .../lib/x86_64-unknown-linux-llvm/crt0.o | 0 clang/test/Driver/linux-llvm-toolchain.c | 3 +++ 8 files changed, 10 insertions(+) create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep create mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o create mode 100644 clang/test/Driver/linux-llvm-toolchain.c diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index cd2c4deb63d14..9e78f0acf6bed 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -760,6 +760,13 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; + // The LLVM-libc environment stores its C headers in the Clang include + // directory. + if (getTriple().getEnvironment() == llvm::Triple::LLVM) { + if (std::optional<std::string> Path = getStdlibIncludePath()) + addSystemInclude(DriverArgs, CC1Args, *Path); + } + // LOCAL_INCLUDE_DIR addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include")); // TOOL_INCLUDE_DIR diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/linux-llvm-toolchain.c b/clang/test/Driver/linux-llvm-toolchain.c new file mode 100644 index 0000000000000..46632de779f25 --- /dev/null +++ b/clang/test/Driver/linux-llvm-toolchain.c @@ -0,0 +1,3 @@ +// RUN: %clang -### --target=x86_64-unknown-linux-llvm --sysroot=%S/Inputs/basic_llvm_linux_tree \ +// RUN: -ccc-install-dir %S/Inputs/basic_llvm_linux_tree/bin %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS +// CHECK-HEADERS: "-cc1"{{.*}}"-isysroot"{{.*}}"-internal-isystem" "{{.*}}include/x86_64-unknown-linux-llvm" >From 7746d1825b589d284c524ac56a0b91f246337ea4 Mon Sep 17 00:00:00 2001 From: Joseph Huber <[email protected]> Date: Tue, 27 Jan 2026 12:07:54 -0600 Subject: [PATCH 2/2] Redo to all Linux --- clang/lib/Driver/ToolChains/Linux.cpp | 8 +++----- .../usr}/bin/.keep | 0 .../usr/include/x86_64-unknown-linux-gnu}/.keep | 0 .../include/x86_64-unknown-linux-llvm/.keep | 0 .../include/x86_64-unknown-linux-llvm/c++/v1/.keep | 0 .../lib/x86_64-unknown-linux-llvm/.keep | 0 .../lib/x86_64-unknown-linux-llvm/crt0.o | 0 clang/test/Driver/linux-header-search.cpp | 13 +++++++++++++ clang/test/Driver/linux-llvm-toolchain.c | 3 --- 9 files changed, 16 insertions(+), 8 deletions(-) rename clang/test/Driver/Inputs/{basic_llvm_linux_tree => basic_linux_tree/usr}/bin/.keep (100%) rename clang/test/Driver/Inputs/{basic_llvm_linux_tree/include/c++/v1 => basic_linux_tree/usr/include/x86_64-unknown-linux-gnu}/.keep (100%) delete mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep delete mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep delete mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep delete mode 100644 clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o delete mode 100644 clang/test/Driver/linux-llvm-toolchain.c diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 9e78f0acf6bed..7631781310d60 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -760,12 +760,10 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; - // The LLVM-libc environment stores its C headers in the Clang include + // After the resource directory, we prioritize the standard clang include // directory. - if (getTriple().getEnvironment() == llvm::Triple::LLVM) { - if (std::optional<std::string> Path = getStdlibIncludePath()) - addSystemInclude(DriverArgs, CC1Args, *Path); - } + if (std::optional<std::string> Path = getStdlibIncludePath()) + addSystemInclude(DriverArgs, CC1Args, *Path); // LOCAL_INCLUDE_DIR addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include")); diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep b/clang/test/Driver/Inputs/basic_linux_tree/usr/bin/.keep similarity index 100% rename from clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep rename to clang/test/Driver/Inputs/basic_linux_tree/usr/bin/.keep diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep b/clang/test/Driver/Inputs/basic_linux_tree/usr/include/x86_64-unknown-linux-gnu/.keep similarity index 100% rename from clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep rename to clang/test/Driver/Inputs/basic_linux_tree/usr/include/x86_64-unknown-linux-gnu/.keep diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/clang/test/Driver/linux-header-search.cpp b/clang/test/Driver/linux-header-search.cpp index 70a85deac89e4..d0e72607b36b2 100644 --- a/clang/test/Driver/linux-header-search.cpp +++ b/clang/test/Driver/linux-header-search.cpp @@ -1,6 +1,19 @@ // General tests that the header search paths detected by the driver and passed // to CC1 are sane. // +// Test to see that the compiler include directory is present. +// RUN: %clang -### %s -fsyntax-only 2>&1 \ +// RUN: --target=x86_64-unknown-linux-gnu \ +// RUN: -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree/ \ +// RUN: | FileCheck --check-prefix=CHECK-BASIC-CLANG-SYSROOT-SLASH %s +// CHECK-BASIC-CLANG-SYSROOT-SLASH: "-cc1" +// CHECK-BASIC-CLANG-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]" +// CHECK-BASIC-CLANG-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr[[SEP:/|\\\\]]bin[[SEP]]..[[SEP]]include[[SEP]]x86_64-unknown-linux-gnu" +// CHECK-BASIC-CLANG-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/local/include" +// // Test a simulated installation of libc++ on Linux, both through sysroot and // the installation path of Clang. // RUN: %clang -### %s -fsyntax-only 2>&1 \ diff --git a/clang/test/Driver/linux-llvm-toolchain.c b/clang/test/Driver/linux-llvm-toolchain.c deleted file mode 100644 index 46632de779f25..0000000000000 --- a/clang/test/Driver/linux-llvm-toolchain.c +++ /dev/null @@ -1,3 +0,0 @@ -// RUN: %clang -### --target=x86_64-unknown-linux-llvm --sysroot=%S/Inputs/basic_llvm_linux_tree \ -// RUN: -ccc-install-dir %S/Inputs/basic_llvm_linux_tree/bin %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS -// CHECK-HEADERS: "-cc1"{{.*}}"-isysroot"{{.*}}"-internal-isystem" "{{.*}}include/x86_64-unknown-linux-llvm" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
