Skip to content

Commit ac11430

Browse files
[libc] Fix missing sysroot path for kernel headers when crosscompiling (#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.
1 parent 9d86722 commit ac11430

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ function(_get_common_compile_options output_var flags)
8888
(LIBC_CC_SUPPORTS_NOSTDLIBINC OR COMPILER_RESOURCE_DIR))
8989
# We use -idirafter to avoid preempting libc's own headers in case the
9090
# directory (e.g. /usr/include) contains other headers.
91-
list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
91+
if(CMAKE_CROSSCOMPILING)
92+
list(APPEND compile_options "-idirafter=${LIBC_KERNEL_HEADERS}")
93+
else()
94+
list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
95+
endif()
9296
endif()
9397
endif()
9498

libc/src/time/linux/nanosleep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/time/nanosleep.h"
10-
10+
#include "hdr/time_macros.h"
1111
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1212
#include "src/__support/common.h"
1313
#include "src/__support/macros/config.h"

0 commit comments

Comments
 (0)