[libc-commits] [libc] [libc] Fix missing sysroot path for kernel headers when crosscompiling (PR #99588)

Mikhail R. Gadelha via libc-commits libc-commits at lists.llvm.org
Thu Jul 18 17:21:05 PDT 2024


https://github.com/mikhailramalho created https://github.com/llvm/llvm-project/pull/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.

>From 240b9c549531fcc330a877099139277db2c5b85c Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Thu, 18 Jul 2024 21:14:44 -0300
Subject: [PATCH] [libc] Fix missing sysroot path for kernel headers when
 crosscompiling

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.
---
 libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 6 +++++-
 libc/src/time/linux/nanosleep.cpp                   | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 62e16d52cb3ea..a722fe709af5f 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -88,7 +88,11 @@ function(_get_common_compile_options output_var flags)
          (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}")
+        if(CMAKE_CROSSCOMPILING)
+          list(APPEND compile_options "-idirafter=${LIBC_KERNEL_HEADERS}")
+        else()
+          list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
+        endif()
       endif()
     endif()
 
diff --git a/libc/src/time/linux/nanosleep.cpp b/libc/src/time/linux/nanosleep.cpp
index b267c3238b01f..7a856376ffb20 100644
--- a/libc/src/time/linux/nanosleep.cpp
+++ b/libc/src/time/linux/nanosleep.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/time/nanosleep.h"
-
+#include "hdr/time_macros.h"
 #include "src/__support/OSUtil/syscall.h" // For syscall functions.
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"



More information about the libc-commits mailing list