[libc-commits] [libc] a1c4926 - [libc] Include Linux kernel headers in the full build (#97486)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 2 16:55:19 PDT 2024


Author: Petr Hosek
Date: 2024-07-02T16:55:15-07:00
New Revision: a1c4926dd0ffbc3be8b27b159d8b1978b2ee9411

URL: https://github.com/llvm/llvm-project/commit/a1c4926dd0ffbc3be8b27b159d8b1978b2ee9411
DIFF: https://github.com/llvm/llvm-project/commit/a1c4926dd0ffbc3be8b27b159d8b1978b2ee9411.diff

LOG: [libc] Include Linux kernel headers in the full build (#97486)

When doing a full build for Linux, as of #97461 we no longer include
system headers, but we need to include Linux kernel headers.

Added: 
    

Modified: 
    libc/CMakeLists.txt
    libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Removed: 
    


################################################################################
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..6d38bb491044e 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -51,9 +51,17 @@ function(_get_common_compile_options output_var flags)
       if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
         list(APPEND compile_options "-nostdlibinc")
       elseif(COMPILER_RESOURCE_DIR)
+        # TODO: We should require COMPILER_RESOURCE_DIR to be set.
         list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
         list(APPEND compile_options "-nostdinc")
       endif()
+      # TODO: We should set this unconditionally on Linux.
+      if(LIBC_TARGET_OS_IS_LINUX AND
+         (LIBC_CC_SUPPORTS_NOSTDLIBINC OR COMPILER_RESOURCE_DIR))
+        # 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()
 
     if(LIBC_COMPILER_HAS_FIXED_POINT)


        


More information about the libc-commits mailing list