[libc-commits] [libc] [libc] provide binary compatibility with syscall symbol (PR #117229)
via libc-commits
libc-commits at lists.llvm.org
Thu Nov 21 12:20:34 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Schrodinger ZHU Yifan (SchrodingerZhu)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/117229.diff
9 Files Affected:
- (modified) libc/config/linux/aarch64/entrypoints.txt (+1)
- (modified) libc/config/linux/riscv/entrypoints.txt (+1)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1)
- (modified) libc/src/unistd/CMakeLists.txt (+7)
- (modified) libc/src/unistd/linux/CMakeLists.txt (+10)
- (added) libc/src/unistd/linux/syscall_compat.cpp (+32)
- (added) libc/src/unistd/syscall_compat.h (+21)
- (modified) libc/test/src/unistd/CMakeLists.txt (+1)
- (modified) libc/test/src/unistd/syscall_test.cpp (+10)
``````````diff
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 74ca3742977a5f..9a34029ab78230 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1002,6 +1002,7 @@ if(LLVM_LIBC_FULL_BUILD)
# unistd.h entrypoints
libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd.syscall_compat
libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 5419462d4f5b3b..d7bdc6daa1b01c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -940,6 +940,7 @@ if(LLVM_LIBC_FULL_BUILD)
# unistd.h entrypoints
libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd.syscall_compat
libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 957e28bd66cc4c..5b6aa83712c991 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1094,6 +1094,7 @@ if(LLVM_LIBC_FULL_BUILD)
# unistd.h entrypoints
libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd.syscall_compat
libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt
index 1a0b2e3293d03c..29f71ceca64750 100644
--- a/libc/src/unistd/CMakeLists.txt
+++ b/libc/src/unistd/CMakeLists.txt
@@ -252,6 +252,13 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.__llvm_libc_syscall
)
+add_entrypoint_object(
+ syscall_compat
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.syscall_compat
+)
+
add_entrypoint_object(
sysconf
ALIAS
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 8a448731414143..106477cec2b07d 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -465,6 +465,16 @@ add_entrypoint_object(
libc.src.errno.errno
)
+add_entrypoint_object(
+ syscall_compat
+ SRCS
+ syscall_compat.cpp
+ HDRS
+ ../syscall_compat.h
+ DEPENDS
+ .__llvm_libc_syscall
+)
+
add_entrypoint_object(
sysconf
SRCS
diff --git a/libc/src/unistd/linux/syscall_compat.cpp b/libc/src/unistd/linux/syscall_compat.cpp
new file mode 100644
index 00000000000000..fc0039e15552f7
--- /dev/null
+++ b/libc/src/unistd/linux/syscall_compat.cpp
@@ -0,0 +1,32 @@
+//===-- Linux implementation of syscall (va compat) -----------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/syscall_compat.h"
+#include "src/__support/common.h"
+#include "src/unistd/syscall.h"
+
+#include "src/__support/macros/config.h"
+#include <stdarg.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+#undef syscall
+LLVM_LIBC_FUNCTION(long, syscall, (long n, ...)) {
+ va_list args;
+ va_start(args, n);
+ long arg1 = va_arg(args, long);
+ long arg2 = va_arg(args, long);
+ long arg3 = va_arg(args, long);
+ long arg4 = va_arg(args, long);
+ long arg5 = va_arg(args, long);
+ long arg6 = va_arg(args, long);
+ va_end(args);
+ return __llvm_libc_syscall(n, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/unistd/syscall_compat.h b/libc/src/unistd/syscall_compat.h
new file mode 100644
index 00000000000000..4f2271ce52d139
--- /dev/null
+++ b/libc/src/unistd/syscall_compat.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for syscall (va compat) -----------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_UNISTD_SYSCALL_COMPAT_H
+#define LLVM_LIBC_SRC_UNISTD_SYSCALL_COMPAT_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+#pragma push_macro("syscall")
+#undef syscall
+long syscall(long number, ...);
+#pragma pop_macro("syscall")
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_UNISTD_SYSCALL_COMPAT_H
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index e036e09cde702e..43491202626a1f 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -429,6 +429,7 @@ add_libc_unittest(
libc.include.sys_syscall
libc.src.errno.errno
libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd.syscall_compat
libc.test.UnitTest.ErrnoSetterMatcher
)
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index f6cc3eab9aabe8..9ac842267b4047 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -8,6 +8,7 @@
#include "src/errno/libc_errno.h"
#include "src/unistd/syscall.h"
+#include "src/unistd/syscall_compat.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -177,3 +178,12 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_close, dir_fd), 0l);
ASSERT_ERRNO_SUCCESS();
}
+
+TEST(LlvmLibcSyscallTest, TrivialCallCompat) {
+ LIBC_NAMESPACE::libc_errno = 0;
+#pragma push_macro("syscall")
+#undef syscall
+ ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_gettid), 0l);
+#pragma pop_macro("syscall")
+ ASSERT_ERRNO_SUCCESS();
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/117229
More information about the libc-commits
mailing list