-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] Include Linux kernel headers in the full build #97486
Conversation
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
@llvm/pr-subscribers-libc Author: Petr Hosek (petrhosek) ChangesWhen doing a full build for Linux, as of #97461 we no longer include system headers, but we need to include Linux kernel headers. Full diff: https://github.com/llvm/llvm-project/pull/97486.diff 2 Files Affected:
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)
|
@@ -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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It merits a comment about why we want to use -idirafter
, which is in case it's a directory like /usr/include
that might contain other headers that we don't want to risk preempting libc's own headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested and works on my machine, LGTM
@frobtech Should we add this flag this unconditionally or only when |
I'm going to merge this to fix the buildbots for now. Feel free to create followup patches. |
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
When crosscompiling, we need to search for the linux kernel headers in the sysroot but since llvm#97486 the linux kernel headers were always searched in /usr/include. This patch fixes this behaviour by prepending a '=' to where we search for the kernel headers. As per the gcc/clang's documentation a '=' before the path is replaced by the sysroot.
#99588) When crosscompiling, we need to search for the linux kernel headers in the sysroot but since #97486 the linux kernel headers were always searched in /usr/include. This patch fixes this behaviour by prepending a '=' to where we search for the kernel headers. As per the gcc/clang's documentation a '=' before the path is replaced by the sysroot. This patch also includes a fix for rv32, that fails to compile due to a missing definition of CLOCK_REALTIME after this change.
llvm#99588) When crosscompiling, we need to search for the linux kernel headers in the sysroot but since llvm#97486 the linux kernel headers were always searched in /usr/include. This patch fixes this behaviour by prepending a '=' to where we search for the kernel headers. As per the gcc/clang's documentation a '=' before the path is replaced by the sysroot. This patch also includes a fix for rv32, that fails to compile due to a missing definition of CLOCK_REALTIME after this change.
#99588) Summary: When crosscompiling, we need to search for the linux kernel headers in the sysroot but since #97486 the linux kernel headers were always searched in /usr/include. This patch fixes this behaviour by prepending a '=' to where we search for the kernel headers. As per the gcc/clang's documentation a '=' before the path is replaced by the sysroot. This patch also includes a fix for rv32, that fails to compile due to a missing definition of CLOCK_REALTIME after this change. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251638
So to be more hermetic, I'd like to get to the point where we encourage the user to build the kernel headers from source BEFORE building llvm-libc, then provide those headers. That way we don't look in /usr/include AT ALL. For example, I'm not sure that the kernel headers on the host are ok to use when cross compiling. |
When doing a full build for Linux, as of #97461 we no longer include system headers, but we need to include Linux kernel headers.