[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for symlinkat (PR #241205)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 02:45:07 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 symlinkat behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
Full diff: https://github.com/llvm/llvm-project/pull/241205.diff
5 Files Affected:
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+12)
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/symlinkat.h (+34)
- (modified) libc/src/unistd/linux/CMakeLists.txt (+5-4)
- (modified) libc/src/unistd/linux/symlinkat.cpp (+11-9)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+16-2)
``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 3e4042ae57d6d..f16bd7fa7c329 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 0000000000000..e5c0235229ffc
--- /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 b9ed2e26c09dc..42659bd3cb8d7 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 8cee172f39dfa..c51eafc922681 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 cd565098affdc..040ae84472042 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",
],
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/241205
More information about the llvm-branch-commits
mailing list