[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for gethostname (PR #240781)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Nov 10 02:46:51 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 gethostname behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.


---
Full diff: https://github.com/llvm/llvm-project/pull/240781.diff


3 Files Affected:

- (modified) libc/src/unistd/linux/CMakeLists.txt (+4-2) 
- (modified) libc/src/unistd/linux/gethostname.cpp (+10-7) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+20) 


``````````diff
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 064ea546e0187..530b0b1aae68e 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -433,8 +433,10 @@ add_entrypoint_object(
   DEPENDS
     libc.hdr.types.size_t
     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
     libc.src.string.string_utils
 )
diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp
index f65fd36540b83..8a1fa954e0f7b 100644
--- a/libc/src/unistd/linux/gethostname.cpp
+++ b/libc/src/unistd/linux/gethostname.cpp
@@ -1,23 +1,26 @@
-//===-- Linux implementation of gethostname -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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
+/// Linux implementation of gethostname.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/gethostname.h"
 
 #include "hdr/types/size_t.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 "src/string/string_utils.h"
 
-#include <sys/syscall.h> // For syscall numbers.
-
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) {
@@ -30,9 +33,9 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) {
   // Because there is no SYS_gethostname syscall, we use uname to get the
   // hostname.
   utsname unameData;
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_uname, &unameData);
-  if (ret < 0) {
-    libc_errno = static_cast<int>(-ret);
+  auto result = linux_syscalls::uname(&unameData);
+  if (!result) {
+    libc_errno = result.error();
     return -1;
   }
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 689ae5d486f01..06b51a9af9acc 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -18763,6 +18763,26 @@ libc_function(
     ],
 )
 
+libc_function(
+    name = "gethostname",
+    srcs = ["src/unistd/linux/gethostname.cpp"],
+    hdrs = ["src/unistd/gethostname.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",
+        ":string_utils",
+        ":types_size_t",
+        ":types_struct_utsname",
+    ],
+)
+
 libc_function(
     name = "getpagesize",
     srcs = ["src/unistd/linux/getpagesize.cpp"],

``````````

</details>


https://github.com/llvm/llvm-project/pull/240781


More information about the llvm-branch-commits mailing list