Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][i386] syscall support #114264

Merged
merged 5 commits into from
Oct 31, 2024
Merged

Conversation

nickdesaulniers
Copy link
Member

Link: #93709

@llvmbot llvmbot added the libc label Oct 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

Link: #93709


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

2 Files Affected:

  • (added) libc/src/__support/OSUtil/linux/i386/syscall.h (+76)
  • (modified) libc/src/__support/OSUtil/linux/syscall.h (+3-1)
diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h
new file mode 100644
index 00000000000000..ddc51c543077ed
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/i386/syscall.h
@@ -0,0 +1,76 @@
+//===---------- inline implementation of i386 syscalls ------------* 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___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
+
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LIBC_INLINE long syscall_impl(long num) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1),
+                  "c"(arg2) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+                  "d"(arg3) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+                              long arg4) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+                  "d"(arg3), "S"(arg4) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+                              long arg4, long arg5) {
+  long ret;
+  LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+                  "d"(arg3), "S"(arg4), "D"(arg5) : "memory");
+  return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+                              long arg4, long arg5, long arg6) {
+  long ret;
+  LIBC_INLINE_ASM(R"(
+    push %[arg6]
+    push %%ebp
+    mov 4(%%esp), %%ebp
+    int $128
+    pop %%ebp
+    add $4, %%esp
+  )" : "=a"(ret) : "a"(num),
+                  "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
+                  "D"(arg5), [arg6] "m"(arg6) : "memory");
+  return ret;
+}
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
diff --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h
index ad3f6947d0a06a..24e0fca73c1678 100644
--- a/libc/src/__support/OSUtil/linux/syscall.h
+++ b/libc/src/__support/OSUtil/linux/syscall.h
@@ -14,7 +14,9 @@
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/architectures.h"
 
-#ifdef LIBC_TARGET_ARCH_IS_X86_64
+#ifdef LIBC_TARGET_ARCH_IS_X86_32
+#include "i386/syscall.h"
+#elif defined(LIBC_TARGET_ARCH_IS_X86_64)
 #include "x86_64/syscall.h"
 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
 #include "aarch64/syscall.h"

Copy link

github-actions bot commented Oct 30, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@nickdesaulniers nickdesaulniers merged commit 8413599 into llvm:main Oct 31, 2024
7 checks passed
@nickdesaulniers nickdesaulniers deleted the i386_syscalls branch October 31, 2024 20:41
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 31, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building libc at step 11 "Add check check-libc-amdgcn-amd-amdhsa".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7852

Here is the relevant piece of the build log for the reference
Step 11 (Add check check-libc-amdgcn-amd-amdhsa) failure: 1200 seconds without output running [b'ninja', b'-j 32', b'check-libc-amdgcn-amd-amdhsa'], attempting to kill
...
[2555/2681] Linking CXX executable libc/test/src/string/libc.test.src.string.memcmp_test.__hermetic__.__build__
[2556/2681] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtof_test.__hermetic__.__build__
[2557/2681] Linking CXX executable libc/test/src/string/libc.test.src.string.strncat_test.__hermetic__.__build__
[2558/2681] Linking CXX executable libc/test/src/string/libc.test.src.string.memmove_test.__hermetic__.__build__
[2559/2681] Linking CXX executable libc/test/src/string/libc.test.src.string.strxfrm_test.__hermetic__.__build__
[2560/2681] Linking CXX executable libc/test/src/inttypes/libc.test.src.inttypes.strtoimax_test.__hermetic__.__build__
[2561/2681] Linking CXX executable libc/test/src/string/libc.test.src.string.strlcat_test.__hermetic__.__build__
[2562/2681] Linking CXX executable libc/test/src/time/libc.test.src.time.clock_gettime_test.__hermetic__.__build__
[2563/2681] Linking CXX executable libc/test/src/stdio/libc.test.src.stdio.vasprintf_test.__hermetic__.__build__
[2564/2681] Linking CXX executable libc/test/src/stdio/libc.test.src.stdio.asprintf_test.__hermetic__.__build__
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', b'check-libc-amdgcn-amd-amdhsa'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1470.388382

smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants