[libc-commits] [libc] [libc] Include Linux kernel headers in the full build (PR #97486)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Tue Jul 2 14:59:35 PDT 2024
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/97486
>From 6edadbc47ad6307ec05e7159ad33b2a3a93b2d42 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 2 Jul 2024 14:50:55 -0700
Subject: [PATCH 1/2] [libc] Include Linux kernel headers in the full build
When doing a full build for Linux, as of #97461 we no longer include
system headers, but we need to include Linux kernel headers.
---
libc/CMakeLists.txt | 2 ++
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 3 +++
2 files changed, 5 insertions(+)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 4ffcd55ba9500..013b17b03f570 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -39,6 +39,8 @@ set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBC_ENABLE_USE_BY_CLANG OFF CACHE BOOL "Whether or not to place libc in a build directory findable by a just built clang")
+set(LIBC_KERNEL_HEADERS "/usr/include" CACHE STRING "Path to Linux kernel headers")
+
# Defining a global namespace to enclose all libc functions.
set(default_namespace "__llvm_libc")
if(LLVM_VERSION_MAJOR)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 28379213029a3..d6a8764c3de16 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -54,6 +54,9 @@ function(_get_common_compile_options output_var flags)
list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
list(APPEND compile_options "-nostdinc")
endif()
+ if(LIBC_TARGET_OS_IS_LINUX)
+ list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
+ endif()
endif()
if(LIBC_COMPILER_HAS_FIXED_POINT)
>From db7380ae5aa5cf0373d55af1d53aae8e20071ad5 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 2 Jul 2024 14:59:12 -0700
Subject: [PATCH 2/2] Add a comment explaining the use of -idirafter
---
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index d6a8764c3de16..dd5319be0f9d9 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -55,6 +55,8 @@ function(_get_common_compile_options output_var flags)
list(APPEND compile_options "-nostdinc")
endif()
if(LIBC_TARGET_OS_IS_LINUX)
+ # We use -idirafter to avoid preempting libc's own headers in case the
+ # directory (e.g. /usr/include) contains other headers.
list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
endif()
endif()
More information about the libc-commits
mailing list