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