[PATCH 13/23] linux: Use generic __syscall_error for x86_64
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Nov 9 20:18:16 GMT 2020
The auto-generated syscalls issue the __syscall_error only for
static objects, so a arch specific syscall_error is added. The
size of using extern __syscall_error is just slight better for
static case:
--- size-fstatat64.o.inline
+++ size-fstatat64.o.outline
@@ -1,2 +1,2 @@
text data bss dec hex filename
- 100 0 0 100 64 io/fstatat64.o
+ 94 0 0 94 5e io/fstatat64.o
For shared objects the inline __syscall_error does generate more
compact code:
--- sizes-x86_64-linux-gnu.inline
+++ sizes-x86_64-linux-gnu.outline
@@ -1,5 +1,5 @@
text data bss dec hex filename
-1774028 20520 15896 1810444 1ba00c libc.so
- 167499 7280 392 175171 2ac43 elf/ld.so
- 99261 1640 16728 117629 1cb7d nptl/libpthread.so
- 24751 1188 2400 28339 6eb3 rt/librt.so
+1776260 20520 15896 1812676 1ba8c4 libc.so
+ 167758 7280 392 175430 2ad46 elf/ld.so
+ 100221 1640 16728 118589 1cf3d nptl/libpthread.so
+ 24927 1188 2400 28515 6f63 rt/librt.so
A possible option might be to use the same strategy for both static
and PIC code, which allow to remove the arch-specific syscall_error.c
with a slight increase of code size in static library.
Checked on x86_64-linux-gnu.
---
sysdeps/unix/sysv/linux/sysdep.h | 8 +++
.../unix/sysv/linux/x86_64/syscall_error.c | 5 ++
sysdeps/unix/sysv/linux/x86_64/sysdep.S | 40 ---------------
sysdeps/unix/x86_64/sysdep.S | 49 -------------------
4 files changed, 13 insertions(+), 89 deletions(-)
create mode 100644 sysdeps/unix/sysv/linux/x86_64/syscall_error.c
delete mode 100644 sysdeps/unix/sysv/linux/x86_64/sysdep.S
delete mode 100644 sysdeps/unix/x86_64/sysdep.S
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 6c0d1f9f6f..4f5b978838 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -24,6 +24,14 @@
#include <errno.h>
#ifndef __ASSEMBLER__
+/* The errno setting might be set either inline or with a help function. For
+ some ABIs (x86_64), setting inline might generate less code; while for
+ others (i686) function call is preferable.
+
+ To use the helper function an ABI might define SYSCALL_ERROR_FUNC, it will
+ build a hidden function on each shared object that issues direct syscall
+ with {INLINE,INTERNAL}_SYSCALL_CALL. */
+
static inline _Bool
syscall_error (unsigned long int val)
{
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall_error.c b/sysdeps/unix/sysv/linux/x86_64/syscall_error.c
new file mode 100644
index 0000000000..40528f8ae9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/syscall_error.c
@@ -0,0 +1,5 @@
+/* The auto-generated syscalls calls __syscall_error for static objects. */
+#ifndef SHARED
+# define SYSCALL_ERROR_FUNC
+#endif
+#include <sysdeps/unix/sysv/linux/syscall_error.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.S b/sysdeps/unix/sysv/linux/x86_64/sysdep.S
deleted file mode 100644
index 2d3592296d..0000000000
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.S
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-
-/* The following code is only used in the shared library when we
- compile the reentrant version. Otherwise each system call defines
- each own version. */
-
-#ifndef PIC
-
-/* The syscall stubs jump here when they detect an error.
- The code for Linux is almost identical to the canonical Unix
- code, except that the error number in %rax is negated. */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers %rax. */
-
- .text
-ENTRY (__syscall_error)
- neg %RAX_LP
-
-#define __syscall_error __syscall_error_1
-#include <sysdeps/unix/x86_64/sysdep.S>
-
-#endif /* !PIC */
diff --git a/sysdeps/unix/x86_64/sysdep.S b/sysdeps/unix/x86_64/sysdep.S
deleted file mode 100644
index 2278fce9e4..0000000000
--- a/sysdeps/unix/x86_64/sysdep.S
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <errno.h>
-#include <tls.h>
-
-#if IS_IN (rtld)
-# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
-#endif
-
-.globl C_SYMBOL_NAME(errno)
-.globl syscall_error
-
-__syscall_error:
-#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
- /* We translate the system's EWOULDBLOCK error into EAGAIN.
- The GNU C library always defines EWOULDBLOCK==EAGAIN.
- EWOULDBLOCK_sys is the original number. */
- cmp $EWOULDBLOCK_sys, %RAX_LP /* Is it the old EWOULDBLOCK? */
- jne notb /* Branch if not. */
- movl $EAGAIN, %eax /* Yes; translate it to EAGAIN. */
-notb:
-#endif
-#ifdef PIC
- movq C_SYMBOL_NAME(errno@GOTTPOFF)(%rip), %rcx
- movl %eax, %fs:0(%rcx)
-#else
- movl %eax, %fs:C_SYMBOL_NAME(errno@TPOFF)
-#endif
- or $-1, %RAX_LP
- ret
-
-#undef __syscall_error
-END (__syscall_error)
--
2.25.1
More information about the Libc-alpha
mailing list