diff mbox series

[v2,09/23] linux: Use generic __syscall_error for sparc

Message ID 20201113165837.121629-10-adhemerval.zanella@linaro.org
State New
Headers show
Series Simplify internal Linux syscall | expand

Commit Message

Adhemerval Zanella Nov. 13, 2020, 4:58 p.m. UTC
The sparc kABI returns a positive errno value in 'o0' register for
failure case (the syscall error is signal on conditional register),
different than usual Linux kABI with return a negative value in range
of [-4096,0).  The __syscall_error thus has a different ABI than the
generic one, which requires fixing both the inline syscall wrappers
and some assembly implementation that calls __syscall_error directly.

Using inline function for __syscall_error does not yield any gain:

--- sizes-sparc64-linux-gnu.outline
+++ sizes-sparc64-linux-gnu.inline
    text           data     bss     dec     hex filename
-1469609          20464   14496 1504569  16f539 libc.so
- 152853           6960     352  160165   271a5 elf/ld.so
- 101586           1220   16672  119478   1d2b6 nptl/libpthread.so
-  27282            836    2296   30414    76ce rt/librt.so
+1473545          20464   14496 1508505  170499 libc.so
+ 153077           6960     352  160389   27285 elf/ld.so
+ 102578           1220   16672  120470   1d696 nptl/libpthread.so
+  27474            836    2296   30606    778e rt/librt.so

--- sizes-sparcv9-linux-gnu.outline
+++ sizes-sparcv9-linux-gnu.inline
    text           data     bss     dec     hex filename
-1557171          11208    9440 1577819  18135b libc.so
- 149507           4448     192  154147   25a23 elf/ld.so
- 101518            588    8356  110462   1af7e nptl/libpthread.so
-  26546            404     160   27110    69e6 rt/librt.so
+1563315          11208    9440 1583963  182b5b libc.so
+ 149795           4448     192  154435   25b43 elf/ld.so
+ 102286            588    8356  111230   1b27e nptl/libpthread.so
+  26930            404     160   27494    6b66 rt/librt.so

Checked on sparc64-linux-gnu and sparcv9-linux-gnu.
---
 sysdeps/unix/sysv/linux/sparc/Makefile         |  9 ++-------
 sysdeps/unix/sysv/linux/sparc/rt-sysdep.c      |  1 -
 sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S   |  1 +
 .../unix/sysv/linux/sparc/sparc32/syscall.S    |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S  |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S   |  1 +
 .../unix/sysv/linux/sparc/sparc64/syscall.S    |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S  |  1 +
 .../linux/sparc/{sysdep.c => syscall_error.h}  | 18 ++++++++----------
 11 files changed, 18 insertions(+), 18 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
 rename sysdeps/unix/sysv/linux/sparc/{sysdep.c => syscall_error.h} (74%)
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/sparc/Makefile b/sysdeps/unix/sysv/linux/sparc/Makefile
index 1475039677..3a47cd2da4 100644
--- a/sysdeps/unix/sysv/linux/sparc/Makefile
+++ b/sysdeps/unix/sysv/linux/sparc/Makefile
@@ -2,11 +2,6 @@  abi-variants := 32 64
 abi-32-condition := __WORDSIZE == 32
 abi-64-condition := __WORDSIZE == 64
 
-ifeq ($(subdir),rt)
-librt-routines += rt-sysdep
-librt-shared-only-routines += rt-sysdep
-endif
-
 ifeq ($(subdir),sysvipc)
 sysdep_routines += getshmlba
 endif
@@ -17,6 +12,6 @@  endif
 
 ifeq ($(subdir),nptl)
 # pull in __syscall_error routine
-libpthread-routines += sysdep sigreturn_stub
-libpthread-shared-only-routines += sysdep sigreturn_stub
+libpthread-routines += sigreturn_stub
+libpthread-shared-only-routines += sigreturn_stub
 endif
diff --git a/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c b/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
deleted file mode 100644
index 3ff55952e2..0000000000
--- a/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
+++ /dev/null
@@ -1 +0,0 @@ 
-#include <sysdep.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S b/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
index 0b10f1522b..d693527e7b 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
@@ -26,6 +26,7 @@  ENTRY(__libc_pipe)
 	ta	0x10
 	bcc	1f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 1:	st	%o0, [%o2]           /* PIPEDES[0] = %o0; */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S
index 90c639f043..a2b608179a 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S
@@ -30,6 +30,7 @@  ENTRY(syscall)
 	ta	0x10
 	bcc	1f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 1:	retl
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
index 2c3754770b..3e7671c391 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
@@ -65,6 +65,7 @@  ENTRY(name);					\
 #ifndef PIC
 # define SYSCALL_ERROR_HANDLER			\
 	mov	%o7, %g1;			\
+	neg	%o0, %o0;			\
 	call	__syscall_error;		\
 	 mov	%g1, %o7;
 #else
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S b/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S
index be48386016..c8d26a49a7 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S
@@ -26,6 +26,7 @@  ENTRY(__libc_vfork)
 	ta	0x10
 	bcc	2f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 2:	sub	%o1, 1, %o1
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S b/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
index 072a1936ea..ba75629261 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
@@ -27,6 +27,7 @@  ENTRY(__libc_pipe)
 	ta	0x6d
 	bcc,pt	%xcc, 1f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 1:	st	%o0, [%o2]		/* PIPEDES[0] = %o0; */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S
index fca114371f..63a28f65ee 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S
@@ -32,6 +32,7 @@  ENTRY(syscall)
 
 	bcc,pt	%xcc, 1f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 1:	retl
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
index 2010faf50f..329ec144cf 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
@@ -65,6 +65,7 @@  ENTRY(name);					\
 #ifndef PIC
 # define SYSCALL_ERROR_HANDLER			\
 	mov	%o7, %g1;			\
+	neg     %o0, %o0;			\
 	call	__syscall_error;		\
 	 mov	%g1, %o7;
 #else
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S b/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S
index 56a491f3de..0a34a3e68c 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S
@@ -26,6 +26,7 @@  ENTRY(__libc_vfork)
 	ta	0x6d
 	bcc,pt	%xcc, 2f
 	 mov	%o7, %g1
+	neg	%o0, %o0
 	call	__syscall_error
 	 mov	%g1, %o7
 2:	sub	%o1, 1, %o1
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep.c b/sysdeps/unix/sysv/linux/sparc/syscall_error.h
similarity index 74%
rename from sysdeps/unix/sysv/linux/sparc/sysdep.c
rename to sysdeps/unix/sysv/linux/sparc/syscall_error.h
index 1bf5ea6f62..6a9fac278a 100644
--- a/sysdeps/unix/sysv/linux/sparc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/sparc/syscall_error.h
@@ -1,4 +1,5 @@ 
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
+/* Linux wrappers for setting errno.  SPARC version.
+   Copyright (C) 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
@@ -15,13 +16,10 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
+#ifndef _SYSCALL_ERROR_H
+#define _SYSCALL_ERROR_H
 
-/* This routine is jumped to by all the syscall handlers, to stash
-   an error number into errno.  */
-int
-__syscall_error (int err_no)
-{
-  __set_errno (err_no);
-  return -1;
-}
+#define SYSCALL_ERROR_FUNC        1
+#define SYSCALL_ERROR_FUNC_ATTR
+
+#endif