076f82
commit 1a5b9d1a231ae788aac3520dab07dc856e404c69
076f82
Author: Florian Weimer <fweimer@redhat.com>
076f82
Date:   Wed May 4 15:37:21 2022 +0200
076f82
076f82
    i386: Honor I386_USE_SYSENTER for 6-argument Linux system calls
076f82
    
076f82
    Introduce an int-80h-based version of __libc_do_syscall and use
076f82
    it if I386_USE_SYSENTER is defined as 0.
076f82
    
076f82
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
076f82
    (cherry picked from commit 60f0f2130d30cfd008ca39743027f1e200592dff)
076f82
076f82
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
076f82
index abd0009d58f06303..e379a2e767d96322 100644
076f82
--- a/sysdeps/unix/sysv/linux/i386/Makefile
076f82
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
076f82
@@ -14,7 +14,7 @@ install-bin += lddlibc4
076f82
 endif
076f82
 
076f82
 ifeq ($(subdir),io)
076f82
-sysdep_routines += libc-do-syscall
076f82
+sysdep_routines += libc-do-syscall libc-do-syscall-int80
076f82
 endif
076f82
 
076f82
 ifeq ($(subdir),stdlib)
076f82
diff --git a/sysdeps/unix/sysv/linux/i386/libc-do-syscall-int80.S b/sysdeps/unix/sysv/linux/i386/libc-do-syscall-int80.S
076f82
new file mode 100644
076f82
index 0000000000000000..2c472f255734b357
076f82
--- /dev/null
076f82
+++ b/sysdeps/unix/sysv/linux/i386/libc-do-syscall-int80.S
076f82
@@ -0,0 +1,25 @@
076f82
+/* Out-of-line syscall stub for six-argument syscalls from C.  For static PIE.
076f82
+   Copyright (C) 2022 Free Software Foundation, Inc.
076f82
+   This file is part of the GNU C Library.
076f82
+
076f82
+   The GNU C Library is free software; you can redistribute it and/or
076f82
+   modify it under the terms of the GNU Lesser General Public
076f82
+   License as published by the Free Software Foundation; either
076f82
+   version 2.1 of the License, or (at your option) any later version.
076f82
+
076f82
+   The GNU C Library is distributed in the hope that it will be useful,
076f82
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
076f82
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
076f82
+   Lesser General Public License for more details.
076f82
+
076f82
+   You should have received a copy of the GNU Lesser General Public
076f82
+   License along with the GNU C Library; if not, see
076f82
+   <https://www.gnu.org/licenses/>.  */
076f82
+
076f82
+#ifndef SHARED
076f82
+# define I386_USE_SYSENTER 0
076f82
+# include <sysdep.h>
076f82
+
076f82
+# define __libc_do_syscall __libc_do_syscall_int80
076f82
+# include "libc-do-syscall.S"
076f82
+#endif
076f82
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
076f82
index 39d6a3c13427abb5..4c6358c7fe43fe0b 100644
076f82
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
076f82
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
076f82
@@ -43,6 +43,15 @@
076f82
 # endif
076f82
 #endif
076f82
 
076f82
+#if !I386_USE_SYSENTER && IS_IN (libc) && !defined SHARED
076f82
+/* Inside static libc, we have two versions.  For compilation units
076f82
+   with !I386_USE_SYSENTER, the vDSO entry mechanism cannot be
076f82
+   used. */
076f82
+# define I386_DO_SYSCALL_STRING "__libc_do_syscall_int80"
076f82
+#else
076f82
+# define I386_DO_SYSCALL_STRING "__libc_do_syscall"
076f82
+#endif
076f82
+
076f82
 #ifdef __ASSEMBLER__
076f82
 
076f82
 /* Linux uses a negative return value to indicate syscall errors,
076f82
@@ -302,7 +311,7 @@ struct libc_do_syscall_args
076f82
     };									\
076f82
     asm volatile (							\
076f82
     "movl %1, %%eax\n\t"						\
076f82
-    "call __libc_do_syscall"						\
076f82
+    "call " I386_DO_SYSCALL_STRING					\
076f82
     : "=a" (resultvar)							\
076f82
     : "i" (__NR_##name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \
076f82
     : "memory", "cc")
076f82
@@ -316,7 +325,7 @@ struct libc_do_syscall_args
076f82
     };									\
076f82
     asm volatile (							\
076f82
     "movl %1, %%eax\n\t"						\
076f82
-    "call __libc_do_syscall"						\
076f82
+    "call " I386_DO_SYSCALL_STRING					\
076f82
     : "=a" (resultvar)							\
076f82
     : "a" (name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv)	\
076f82
     : "memory", "cc")