[07/23] linux: Use generic __syscall_error for i386

Message ID 20201109201826.120534-8-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Simplify internal Linux syscall |

Commit Message

Adhemerval Zanella Nov. 9, 2020, 8:18 p.m. UTC
  The auto-generated syscalls calls the __syscall_error, and for i686
it results in much less compat code:

--- sizes-i686-linux-gnu.outline
+++ sizes-i686-linux-gnu.inline
    text           data     bss     dec     hex filename
-1933727          11324   10172 1955223  1dd597 libc.so
- 175366           4768     184  180318   2c05e elf/ld.so
- 109851            832    8408  119091   1d133 nptl/libpthread.so
-  27983            628     184   28795    707b rt/librt.so
+1937875          11324   10172 1959371  1de5cb libc.so
+ 175790           4768     184  180742   2c206 elf/ld.so
+ 110179            832    8408  119419   1d27b nptl/libpthread.so
+  28139            628     184   28951    7117 rt/librt.so

This patch enabled SYSCALL_ERROR_FUNC with the expected abi by also
defining SYSCALL_ERROR_FUNC_ATTR.

Checked on i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/i386/Makefile | 13 ------------
 sysdeps/unix/sysv/linux/i386/sysdep.c | 29 ---------------------------
 sysdeps/unix/sysv/linux/i386/sysdep.h |  3 +++
 3 files changed, 3 insertions(+), 42 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/i386/sysdep.c
  

Comments

Florian Weimer Nov. 10, 2020, 12:49 p.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> The auto-generated syscalls calls the __syscall_error, and for i686
> it results in much less compat code:
>
> --- sizes-i686-linux-gnu.outline
> +++ sizes-i686-linux-gnu.inline
>     text           data     bss     dec     hex filename
> -1933727          11324   10172 1955223  1dd597 libc.so
> - 175366           4768     184  180318   2c05e elf/ld.so
> - 109851            832    8408  119091   1d133 nptl/libpthread.so
> -  27983            628     184   28795    707b rt/librt.so
> +1937875          11324   10172 1959371  1de5cb libc.so
> + 175790           4768     184  180742   2c206 elf/ld.so
> + 110179            832    8408  119419   1d27b nptl/libpthread.so
> +  28139            628     184   28951    7117 rt/librt.so
>
> This patch enabled SYSCALL_ERROR_FUNC with the expected abi by also
> defining SYSCALL_ERROR_FUNC_ATTR.

Sorry, what do you mean with “compat code”?  And does the code size go
up or down with this change?

Thanks,
Florian
  
Adhemerval Zanella Nov. 11, 2020, 4:41 p.m. UTC | #2
On 10/11/2020 09:49, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> The auto-generated syscalls calls the __syscall_error, and for i686
>> it results in much less compat code:
>>
>> --- sizes-i686-linux-gnu.outline
>> +++ sizes-i686-linux-gnu.inline
>>     text           data     bss     dec     hex filename
>> -1933727          11324   10172 1955223  1dd597 libc.so
>> - 175366           4768     184  180318   2c05e elf/ld.so
>> - 109851            832    8408  119091   1d133 nptl/libpthread.so
>> -  27983            628     184   28795    707b rt/librt.so
>> +1937875          11324   10172 1959371  1de5cb libc.so
>> + 175790           4768     184  180742   2c206 elf/ld.so
>> + 110179            832    8408  119419   1d27b nptl/libpthread.so
>> +  28139            628     184   28951    7117 rt/librt.so
>>
>> This patch enabled SYSCALL_ERROR_FUNC with the expected abi by also
>> defining SYSCALL_ERROR_FUNC_ATTR.
> 
> Sorry, what do you mean with “compat code”?  And does the code size go
> up or down with this change?

I think I should have made it more clear in the patch description.  This
comparison only shows the code size difference between enabling or not
SYSCALL_ERROR_FUNC for the architecture.  It only affects the C
implementations and by 'compat code' I meant code size.

The code size difference for this *whole* patchset is show below,
where 'before' is the code size output (in bytes) from 'size' 
binutils tools with prior the first patch of the set and 'after' 
with all patch applied.

In general I see a small improvement in total code size.  I think we might
get some smalls improvement by changing the auto-generated assembly syscall
to C implementations, it would allow to move from outline call to inline
errno setting or vice-versa more easily.


Architecture    :   before ->   after : diff
aarch64-linux-gnu
  ld.so         :   138457 ->   138597 +0.10
  libc.so       :  1381655 ->  1381143 -0.04
  libpthread.so :    99675 ->    98987 -0.69
  librt.so      :    24027 ->    23939 -0.37
alpha-linux-gnu
  ld.so         :   171608 ->   171420 -0.11
  libc.so       :  1826396 ->  1825820 -0.03
  libpthread.so :   127926 ->   126998 -0.73
  librt.so      :    32881 ->    32625 -0.78
arc-linux-gnuhf
  ld.so         :   110037 ->   109617 -0.38
  libc.so       :   962368 ->   961226 -0.12
  libpthread.so :    75403 ->    75463 +0.08
  librt.so      :    18794 ->    18704 -0.48
arm-linux-gnueabihf
  ld.so         :   143219 ->   142755 -0.32
  libc.so       :  1266033 ->  1260285 -0.45
  libpthread.so :    98075 ->    97335 -0.75
  librt.so      :    22756 ->    22516 -1.05
csky-linux-gnuabiv2
  ld.so         :   121194 ->   121410 +0.18
  libc.so       :  1202783 ->  1203475 +0.06
  libpthread.so :    93140 ->    92756 -0.41
  librt.so      :    24727 ->    24935 +0.84
hppa-linux-gnu
  ld.so         :   172095 ->   171887 -0.12
  libc.so       :  1567942 ->  1563690 -0.27
  libpthread.so :   134371 ->   133235 -0.85
  librt.so      :    31613 ->    31221 -1.24
i686-linux-gnu
  ld.so         :   175790 ->   175262 -0.30
  libc.so       :  1939247 ->  1933823 -0.28
  libpthread.so :   110635 ->   109851 -0.71
  librt.so      :    28239 ->    27983 -0.91
ia64-linux-gnu
  ld.so         :   293693 ->   293757 +0.02
  libc.so       :  2905590 ->  2905334 -0.01
  libpthread.so :   206654 ->   205726 -0.45
  librt.so      :    47126 ->    46742 -0.81
m68k-linux-gnu
  ld.so         :   118461 ->   118413 -0.04
  libc.so       :  1280292 ->  1274264 -0.47
  libpthread.so :    87926 ->    86610 -1.50
  librt.so      :    24054 ->    23782 -1.13
microblaze-linux-gnu
  ld.so         :   187304 ->   187480 +0.09
  libc.so       :  1835193 ->  1828161 -0.38
  libpthread.so :   124416 ->   124048 -0.30
  librt.so      :    31028 ->    31032 +0.01
mips64-linux-gnu
  ld.so         :   164336 ->   164208 -0.08
  libc.so       :  1707476 ->  1706700 -0.05
  libpthread.so :   127189 ->   126341 -0.67
  librt.so      :    30543 ->    30252 -0.95
mips64-n32-linux-gnu
  ld.so         :   158416 ->   158244 -0.11
  libc.so       :  1618530 ->  1616922 -0.10
  libpthread.so :   119753 ->   118157 -1.33
  librt.so      :    29943 ->    29708 -0.78
mips-linux-gnu
  ld.so         :   173488 ->   173316 -0.10
  libc.so       :  1645227 ->  1644619 -0.04
  libpthread.so :   121321 ->   120945 -0.31
  librt.so      :    30837 ->    30822 -0.05
nios2-linux-gnu
  ld.so         :   142874 ->   142974 +0.07
  libc.so       :  1417868 ->  1418012 +0.01
  libpthread.so :   103026 ->   103026 +0.00
  librt.so      :    26472 ->    26412 -0.23
powerpc64le-linux-gnu
  ld.so         :   204310 ->   204878 +0.28
  libc.so       :  2013898 ->  2016558 +0.13
  libpthread.so :   139425 ->   138769 -0.47
  librt.so      :    31407 ->    31643 +0.75
powerpc64-linux-gnu
  ld.so         :   204077 ->   204677 +0.29
  libc.so       :  2011449 ->  2014389 +0.15
  libpthread.so :   154833 ->   154117 -0.46
  librt.so      :    36571 ->    36763 +0.53
powerpc-linux-gnu
  ld.so         :   175973 ->   175117 -0.49
  libc.so       :  1780644 ->  1771572 -0.51
  libpthread.so :   135547 ->   134231 -0.97
  librt.so      :    32271 ->    32115 -0.48
riscv32-linux-gnu-rv32imafdc-ilp32d
  ld.so         :    98229 ->    98065 -0.17
  libc.so       :   974660 ->   973224 -0.15
  libpthread.so :    70861 ->    71063 +0.29
  librt.so      :    17053 ->    17011 -0.25
riscv64-linux-gnu-rv64imafdc-lp64d
  ld.so         :    98274 ->    98168 -0.11
  libc.so       :  1031904 ->  1030870 -0.10
  libpthread.so :    76828 ->    76588 -0.31
  librt.so      :    18150 ->    18016 -0.74
s390-linux-gnu
  ld.so         :   139947 ->   139835 -0.08
  libc.so       :  1581950 ->  1581034 -0.06
  libpthread.so :   105734 ->   105194 -0.51
  librt.so      :    26981 ->    27065 +0.31
s390x-linux-gnu
  ld.so         :   168697 ->   168561 -0.08
  libc.so       :  1757244 ->  1756108 -0.06
  libpthread.so :   119026 ->   117906 -0.94
  librt.so      :    29735 ->    29527 -0.70
sh4-linux-gnu
  ld.so         :   122532 ->   122500 -0.03
  libc.so       :  1244034 ->  1240914 -0.25
  libpthread.so :    93172 ->    92808 -0.39
  librt.so      :    24042 ->    23746 -1.23
sparc64-linux-gnu
  ld.so         :   152025 ->   151577 -0.29
  libc.so       :  1477340 ->  1472988 -0.29
  libpthread.so :   103018 ->   101706 -1.27
  librt.so      :    27279 ->    27023 -0.94
sparcv9-linux-gnu
  ld.so         :   151207 ->   150951 -0.17
  libc.so       :  1569967 ->  1563567 -0.41
  libpthread.so :   102674 ->   101362 -1.28
  librt.so      :    26815 ->    26623 -0.72
x86_64-linux-gnu
  ld.so         :   167435 ->   167451 +0.01
  libc.so       :  1774908 ->  1774348 -0.03
  libpthread.so :   100013 ->    99261 -0.75
  librt.so      :    24935 ->    24751 -0.74
x86_64-linux-gnu-x32
  ld.so         :   163591 ->   163531 -0.04
  libc.so       :  1730210 ->  1729522 -0.04
  libpthread.so :    93950 ->    93398 -0.59
  librt.so      :    21951 ->    21851 -0.46
  

Patch

diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index da716e2c1b..983b02e081 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -28,22 +28,9 @@  gen-as-const-headers += ucontext_i.sym
 endif
 
 ifeq ($(subdir),csu)
-sysdep-dl-routines += sysdep
 ifeq (yes,$(build-shared))
 sysdep_routines += divdi3
 shared-only-routines += divdi3
 CPPFLAGS-divdi3.c = -Din_divdi3_c
 endif
 endif
-
-ifeq ($(subdir),nptl)
-# pull in __syscall_error routine
-libpthread-routines += sysdep
-libpthread-shared-only-routines += sysdep
-endif
-
-ifeq ($(subdir),rt)
-# pull in __syscall_error routine
-librt-routines += sysdep
-librt-shared-only-routines += sysdep
-endif
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.c b/sysdeps/unix/sysv/linux/i386/sysdep.c
deleted file mode 100644
index e6228406dd..0000000000
--- a/sysdeps/unix/sysv/linux/i386/sysdep.c
+++ /dev/null
@@ -1,29 +0,0 @@ 
-/* Copyright (C) 2015-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 <errno.h>
-
-/* This routine is jumped to by all the syscall handlers, to stash
-   an error number into errno.  ERROR is the negative error number
-   returned from the x86 kernel.  */
-int
-__attribute__ ((__regparm__ (1)))
-__syscall_error (int error)
-{
-  __set_errno (-error);
-  return -1;
-}
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 4680013de4..977dc1ab42 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -19,6 +19,9 @@ 
 #ifndef _LINUX_I386_SYSDEP_H
 #define _LINUX_I386_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+#define SYSCALL_ERROR_FUNC_ATTR __attribute__ ((__regparm__ (1)))
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/i386/sysdep.h>