https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/175593

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.


>From ba35f1e769d1e1ca06788ceee69a6cebc1a9bbe9 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Mon, 12 Jan 2026 11:43:19 -0600
Subject: [PATCH] [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 cdbf21fb90263..da4aaa907dafb 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -747,6 +747,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"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to