[libc-commits] [libc] fb94261 - [libc][darwin] add syscall numbers from macos sdk (#166354)
via libc-commits
libc-commits at lists.llvm.org
Thu Nov 27 07:56:47 PST 2025
Author: Shreeyash Pandey
Date: 2025-11-27T21:26:42+05:30
New Revision: fb94261d88eb679ba227281ccae88165172a68cb
URL: https://github.com/llvm/llvm-project/commit/fb94261d88eb679ba227281ccae88165172a68cb
DIFF: https://github.com/llvm/llvm-project/commit/fb94261d88eb679ba227281ccae88165172a68cb.diff
LOG: [libc][darwin] add syscall numbers from macos sdk (#166354)
This PR adds support to include syscall.h from MacOS sdk by explicitly including the path to the sdk via `xcrun`.
Added:
Modified:
libc/cmake/modules/LLVMLibCArchitectures.cmake
libc/include/sys/syscall.h.def
Removed:
################################################################################
diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 6c730f807de6d..939fc1226a4e9 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -215,6 +215,37 @@ else()
"Unsupported libc target operating system ${LIBC_TARGET_OS}")
endif()
+# If the compiler target triple is not the same as the triple specified by
+# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
+# if the compiler is clang. If the compiler is GCC we just error out as there
+# is no equivalent of an option like --target.
+if(explicit_target_triple AND
+ (NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
+ set(LIBC_CROSSBUILD TRUE)
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ message(FATAL_ERROR
+ "GCC target triple (${libc_compiler_triple}) and the explicity "
+ "specified target triple (${explicit_target_triple}) do not match.")
+ else()
+ list(APPEND
+ LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}")
+ endif()
+endif()
+
+if(LIBC_TARGET_OS_IS_DARWIN)
+ execute_process(
+ COMMAND xcrun --sdk macosx --show-sdk-path
+ OUTPUT_VARIABLE MACOSX_SDK_PATH
+ RESULT_VARIABLE MACOSX_SDK_PATH_RESULT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(MACOSX_SDK_PATH_RESULT EQUAL 0)
+ list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "-I" "${MACOSX_SDK_PATH}/usr/include")
+ else()
+ message(WARNING "Could not find macOS SDK path. `xcrun --sdk macosx --show-sdk-path` failed.")
+ endif()
+endif()
+
# Windows does not support full mode build.
if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
message(FATAL_ERROR "Windows does not support full mode build.")
diff --git a/libc/include/sys/syscall.h.def b/libc/include/sys/syscall.h.def
index 60e5024e500e3..f7e53cc4942d5 100644
--- a/libc/include/sys/syscall.h.def
+++ b/libc/include/sys/syscall.h.def
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SYS_SYSCALL_H
#define LLVM_LIBC_SYS_SYSCALL_H
-//TODO: Handle non-linux syscalls
+#if defined(__linux__)
#include <asm/unistd.h>
@@ -2361,5 +2361,6 @@
#define SYS_writev __NR_writev
#endif
+#endif // __linux__
#endif // LLVM_LIBC_SYS_SYSCALL_H
More information about the libc-commits
mailing list