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

Connector Switch via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 11 02:44:35 PST 2026


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/241205

This PR move symlinkat behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.


>From fe6fcb9ba5a5e66c2a0570734dedba3554afaf6e Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 11 Nov 2026 18:43:59 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for symlinkat

This PR move symlinkat behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
 .../linux/syscall_wrappers/CMakeLists.txt     | 12 +++++++
 .../OSUtil/linux/syscall_wrappers/symlinkat.h | 34 +++++++++++++++++++
 libc/src/unistd/linux/CMakeLists.txt          |  9 ++---
 libc/src/unistd/linux/symlinkat.cpp           | 20 ++++++-----
 .../llvm-project-overlay/libc/BUILD.bazel     | 18 ++++++++--
 5 files changed, 78 insertions(+), 15 deletions(-)
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 3e4042ae57d6d6..f16bd7fa7c3291 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1469,6 +1469,18 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  symlinkat
+  HDRS
+    symlinkat.h
+  DEPENDS
+    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(
   uname
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h
new file mode 100644
index 00000000000000..e5c0235229ffc2
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 symlinkat.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYMLINKAT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYMLINKAT_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> symlinkat(const char *path1, int fd,
+                                   const char *path2) {
+  return syscall_checked<int>(SYS_symlinkat, path1, fd, path2);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYMLINKAT_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index b9ed2e26c09dc8..42659bd3cb8d7c 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -1030,10 +1030,11 @@ add_entrypoint_object(
   HDRS
     ../symlinkat.h
   DEPENDS
-    libc.hdr.fcntl_macros
-    libc.include.unistd
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.hdr.unistd_macros
+    libc.src.__support.OSUtil.linux.syscall_wrappers.symlinkat
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
     libc.src.errno.errno
 )
 
diff --git a/libc/src/unistd/linux/symlinkat.cpp b/libc/src/unistd/linux/symlinkat.cpp
index 8cee172f39dfaa..c51eafc9226816 100644
--- a/libc/src/unistd/linux/symlinkat.cpp
+++ b/libc/src/unistd/linux/symlinkat.cpp
@@ -1,31 +1,33 @@
-//===-- Linux implementation of symlinkat ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 symlinkat.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/symlinkat.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h"
 #include "src/__support/common.h"
-
-#include "hdr/fcntl_macros.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, symlinkat,
                    (const char *path1, int fd, const char *path2)) {
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_symlinkat, path1, fd, path2);
-  if (ret < 0) {
-    libc_errno = -ret;
+  auto result = linux_syscalls::symlinkat(path1, fd, path2);
+  if (!result) {
+    libc_errno = result.error();
     return -1;
   }
-  return ret;
+  return result.value();
 }
 
 } // 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 cd565098affdcf..040ae84472042c 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3355,6 +3355,21 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_symlinkat",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h"],
+    target_compatible_with = select({
+        "@platforms//os:linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        ":__support_common",
+        ":__support_error_or",
+        ":__support_macros_config",
+        ":__support_osutil_syscall",
+    ],
+)
+
 libc_support_library(
     name = "__support_osutil_linux_syscall_wrappers_uname",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/uname.h"],
@@ -19338,9 +19353,8 @@ libc_function(
         ":__support_common",
         ":__support_libc_errno",
         ":__support_macros_config",
-        ":__support_osutil_syscall",
+        ":__support_osutil_linux_syscall_wrappers_symlinkat",
         ":errno",
-        ":hdr_fcntl_macros",
         ":hdr_unistd_macros",
     ],
 )



More information about the llvm-branch-commits mailing list