Skip to content

Commit fb94261

Browse files
authored
[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`.
1 parent 39f5ff0 commit fb94261

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

libc/cmake/modules/LLVMLibCArchitectures.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,37 @@ else()
215215
"Unsupported libc target operating system ${LIBC_TARGET_OS}")
216216
endif()
217217

218+
# If the compiler target triple is not the same as the triple specified by
219+
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
220+
# if the compiler is clang. If the compiler is GCC we just error out as there
221+
# is no equivalent of an option like --target.
222+
if(explicit_target_triple AND
223+
(NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
224+
set(LIBC_CROSSBUILD TRUE)
225+
if(CMAKE_COMPILER_IS_GNUCXX)
226+
message(FATAL_ERROR
227+
"GCC target triple (${libc_compiler_triple}) and the explicity "
228+
"specified target triple (${explicit_target_triple}) do not match.")
229+
else()
230+
list(APPEND
231+
LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}")
232+
endif()
233+
endif()
234+
235+
if(LIBC_TARGET_OS_IS_DARWIN)
236+
execute_process(
237+
COMMAND xcrun --sdk macosx --show-sdk-path
238+
OUTPUT_VARIABLE MACOSX_SDK_PATH
239+
RESULT_VARIABLE MACOSX_SDK_PATH_RESULT
240+
OUTPUT_STRIP_TRAILING_WHITESPACE
241+
)
242+
if(MACOSX_SDK_PATH_RESULT EQUAL 0)
243+
list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "-I" "${MACOSX_SDK_PATH}/usr/include")
244+
else()
245+
message(WARNING "Could not find macOS SDK path. `xcrun --sdk macosx --show-sdk-path` failed.")
246+
endif()
247+
endif()
248+
218249
# Windows does not support full mode build.
219250
if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
220251
message(FATAL_ERROR "Windows does not support full mode build.")

libc/include/sys/syscall.h.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SYS_SYSCALL_H
1010
#define LLVM_LIBC_SYS_SYSCALL_H
1111

12-
//TODO: Handle non-linux syscalls
12+
#if defined(__linux__)
1313

1414
#include <asm/unistd.h>
1515

@@ -2361,5 +2361,6 @@
23612361
#define SYS_writev __NR_writev
23622362
#endif
23632363

2364+
#endif // __linux__
23642365

23652366
#endif // LLVM_LIBC_SYS_SYSCALL_H

0 commit comments

Comments
 (0)