[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for uname (PR #237954)
via libc-commits
libc-commits at lists.llvm.org
Mon Nov 2 04:56:36 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Connector Switch (c8ef)
<details>
<summary>Changes</summary>
This PR move uname behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
---
Full diff: https://github.com/llvm/llvm-project/pull/237954.diff
5 Files Affected:
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+13)
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/uname.h (+35)
- (modified) libc/src/sys/utsname/linux/CMakeLists.txt (+4-2)
- (modified) libc/src/sys/utsname/linux/uname.cpp (+7-8)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+50)
``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 117191eecb042f..a5f464b015f31c 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1168,6 +1168,19 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ uname
+ HDRS
+ uname.h
+ DEPENDS
+ libc.hdr.types.struct_utsname
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+)
+
add_header_library(
unlink
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/uname.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/uname.h
new file mode 100644
index 00000000000000..79c152d0a12497
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/uname.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for uname.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UNAME_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UNAME_H
+
+#include "hdr/types/struct_utsname.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> uname(struct utsname *name) {
+ return syscall_checked<int>(SYS_uname, name);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UNAME_H
diff --git a/libc/src/sys/utsname/linux/CMakeLists.txt b/libc/src/sys/utsname/linux/CMakeLists.txt
index 3b6e2223b54fac..ffbb9aceb7cc3d 100644
--- a/libc/src/sys/utsname/linux/CMakeLists.txt
+++ b/libc/src/sys/utsname/linux/CMakeLists.txt
@@ -6,7 +6,9 @@ add_entrypoint_object(
../uname.h
DEPENDS
libc.hdr.types.struct_utsname
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.uname
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.errno.errno
)
diff --git a/libc/src/sys/utsname/linux/uname.cpp b/libc/src/sys/utsname/linux/uname.cpp
index cad716faf4d8bd..692876c45f7a2a 100644
--- a/libc/src/sys/utsname/linux/uname.cpp
+++ b/libc/src/sys/utsname/linux/uname.cpp
@@ -9,21 +9,20 @@
#include "src/sys/utsname/uname.h"
#include "hdr/types/struct_utsname.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/uname.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, uname, (struct utsname * name)) {
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_uname, name);
-
- if (ret >= 0)
- return 0;
- libc_errno = -ret;
- return -1;
+ auto result = linux_syscalls::uname(name);
+ if (!result) {
+ libc_errno = result.error();
+ return -1;
+ }
+ return 0;
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 1c8bf8769f8467..ade5f28f6e736c 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -794,6 +794,11 @@ libc_support_library(
hdrs = ["include/llvm-libc-types/struct_seminfo.h"],
)
+libc_support_library(
+ name = "llvm_libc_types_struct_utsname",
+ hdrs = ["include/llvm-libc-types/struct_utsname.h"],
+)
+
libc_support_library(
name = "llvm_libc_types_wchar_t",
hdrs = ["include/llvm-libc-types/wchar_t.h"],
@@ -1502,6 +1507,15 @@ libc_support_library(
hdrs = ["hdr/types/struct_sysinfo.h"],
)
+libc_support_library(
+ name = "types_struct_utsname",
+ hdrs = ["hdr/types/struct_utsname.h"],
+ deps = select({
+ ":full_build": [":llvm_libc_types_struct_utsname"],
+ "//conditions:default": [],
+ }),
+)
+
libc_support_library(
name = "types_key_t",
hdrs = ["hdr/types/key_t.h"],
@@ -3265,6 +3279,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_uname",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/uname.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_error_or",
+ ":__support_macros_config",
+ ":__support_osutil_syscall",
+ ":types_struct_utsname",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_unlink",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/unlink.h"],
@@ -20195,6 +20225,26 @@ libc_function(
],
)
+############################# sys/utsname targets ##############################
+
+libc_function(
+ name = "uname",
+ srcs = ["src/sys/utsname/linux/uname.cpp"],
+ hdrs = ["src/sys/utsname/uname.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_osutil_linux_syscall_wrappers_uname",
+ ":errno",
+ ":types_struct_utsname",
+ ],
+)
+
############################## sys/epoll targets ###############################
libc_function(
``````````
</details>
https://github.com/llvm/llvm-project/pull/237954
More information about the libc-commits
mailing list