public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/23] Simplify internal Linux syscall
@ 2020-11-09 20:18 Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO Adhemerval Zanella
                   ` (22 more replies)
  0 siblings, 23 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

This refactor aims to remove and simplify the Linux internal syscall
mechanism by using inline functions instead of macros and by removing
the possible requirement to each architecture to define a
__syscall_error routine to handle errno setting.

Instead of issuing the following for syscalls that don't set the
errno:

  int r = INTERNAL_SYSCALL_CALL (syscall, ...);
  if (! INTERNAL_SYSCALL_ERROR_P (r)
      || INTERNAL_SYSCALL_ERRNO (r) != ENOSYS)
    return INTERNAL_SYSCALL_ERRNO (r);
  r = INTERNAL_SYSCALL_CALL (fallback, ...);
  return INTERNAL_SYSCALL_ERRNO (r) ? -r : 0;

It would be written as:

  int r = INTERNAL_SYSCALL_CALL (syscall, ...);
  if (! syscall_error (r) || -r != ENOSYS)
    return -r;
  return -INTERNAL_SYSCALL_CALL (fallback, ...);

The error check can be even simplified to 'if -r != ENOSYS' now that
INTERNAL_SYSCALL_CALL will return a value between [-4096UL, 0UL) in
the case of failure.

For syscall which sets the errno, instead of:

  int r = INTERNAL_SYSCALL_CALL (syscall, ...);
  if (! INTERNAL_SYSCALL_ERROR_P (r)
      || INTERNAL_SYSCALL_ERRNO (r) != ENOSYS)
    return INLINE_SYSCALL_ERROR_RETURN_VALUE (r);
  r = INTERNAL_SYSCALL_CALL (fallback, ...);
  [...]
  __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (sc_ret))
    ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (sc_ret))
    : sc_ret;

It would be written as:

  int r = INTERNAL_SYSCALL_CALL (syscall, ...);
  if (! syscall_error (r) || -r != ENOSYS)
    return syscall_ret (r);
  r = INTERNAL_SYSCALL_CALL (fallback, ...);
  [...]
  return syscall_ret (r);

The compiler should easily optimize the first syscall_ret to just call
__syscall_error in first case.

Another optimization is to avoid require each archicture to define an
arch-specific __syscall_error for the case where calling an external
symbols yields faster or more compact code (for instance on i386).  Each
architecture might define SYSCALL_ERROR_FUNC, which in turn will build
and link to each library that issues syscall a local __syscall_error
routine.

I checked each architecture whether inline or outline __syscall_error
results or not in a better code size and enable it accordingly.  Some
ABIs only enables for static case (x86_64), even when the gain is
minimal.

This is a first step to move the syscall to proper inline implementation
instead of the macro hell and to move the auto-generation to use C
generated instead of the assembly ones.


Adhemerval Zanella (23):
  linux: Remove INTERNAL_SYSCALL_ERRNO
  linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function
  Remove tls.h inclusion from internal errno.h
  linux: Add syscall_ret and use it on INLINE_SYSCALL
  linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error
  linux: Use generic __syscall_error for aarch64
  linux: Use generic __syscall_error for i386
  linux: Use generic __syscall_error for arc
  linux: Use generic __syscall_error for powerpc
  linux: Use generic __syscall_error for sparc
  linux: Use generic __syscall_error for hppa
  linux: Use generic __syscall_error for arm
  linux: Use generic __syscall_error for x86_64
  linux: Use generic __syscall_error for s390
  linux: Use generic __syscall_error for sh
  linux: Use generic __syscall_error for microblaze
  linux: Use generic __syscall_error for ia64
  linux: Use generic __syscall_error for m68k
  linux: Use generic __syscall_error for csky
  linux: Use generic __syscall_error for riscv
  linux: Use generic __syscall_error for nios2
  linux: Use generic __syscall_error for alpha
  linux: Use generic __syscall_error for mips

 include/errno.h                               |   2 -
 io/lchmod.c                                   |   4 +-
 malloc/reallocarray.c                         |   1 +
 misc/ustat.c                                  |   1 +
 nptl/allocatestack.c                          |   6 +-
 nptl/nptl-init.c                              |   6 +-
 nptl/pthread_cancel.c                         |   4 +-
 nptl/pthread_getaffinity.c                    |   4 +-
 nptl/pthread_mutex_trylock.c                  |   3 +-
 nptl/pthread_setaffinity.c                    |   9 +-
 nptl/pthread_sigmask.c                        |   8 +-
 nss/nss_fgetent_r.c                           |   1 +
 posix/execl.c                                 |   1 +
 posix/execle.c                                |   1 +
 posix/execlp.c                                |   1 +
 posix/spawn_faction_addchdir.c                |   2 +-
 pwd/putpwent.c                                |   1 +
 signal/sigempty.c                             |   1 +
 signal/sigismem.c                             |   1 +
 sysdeps/arc/Versions                          |   3 -
 sysdeps/arc/nptl/tls.h                        |   2 +-
 sysdeps/csky/nptl/tls.h                       |   2 +-
 sysdeps/generic/internal-signals.h            |   1 +
 sysdeps/ia64/nptl/Makefile                    |   5 -
 sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c        |   3 -
 sysdeps/m68k/nptl/tls.h                       |   2 +-
 sysdeps/mach/hurd/mmap64.c                    |   1 +
 sysdeps/mach/hurd/waitid.c                    |   1 +
 sysdeps/microblaze/backtrace.c                |   1 +
 sysdeps/mips/Makefile                         |   5 -
 sysdeps/mips/nptl/Makefile                    |   5 -
 sysdeps/mips/nptl/nptl-sysdep.S               |   2 -
 sysdeps/mips/nptl/tls.h                       |   2 +-
 sysdeps/nptl/futex-internal.h                 |   1 +
 sysdeps/nptl/lowlevellock-futex.h             |   7 +-
 sysdeps/powerpc/nofpu/sfp-machine.h           |   2 +-
 sysdeps/powerpc/powerpc32/sysdep.h            |   1 +
 sysdeps/powerpc/powerpc64/sysdep.h            |   7 +-
 sysdeps/riscv/nptl/Makefile                   |   5 -
 sysdeps/riscv/nptl/nptl-sysdep.S              |   2 -
 sysdeps/s390/nptl/Makefile                    |   5 -
 sysdeps/unix/alpha/Makefile                   |   8 +-
 sysdeps/unix/alpha/rt-sysdep.S                |   1 -
 .../alpha/{sysdep.S => syscall_error_asm.S}   |   8 +-
 sysdeps/unix/arm/sysdep.S                     |  62 ----------
 sysdeps/unix/mips/mips32/sysdep.h             |   5 +-
 sysdeps/unix/mips/mips64/sysdep.h             |   3 +-
 sysdeps/unix/mips/rt-sysdep.S                 |   1 -
 sysdeps/unix/mips/sysdep.S                    |  99 ---------------
 sysdeps/unix/sh/sysdep.S                      | 115 ------------------
 sysdeps/unix/sysv/linux/Makefile              |   9 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.c      |  33 -----
 sysdeps/unix/sysv/linux/aarch64/sysdep.h      |   2 +
 sysdeps/unix/sysv/linux/adjtime.c             |   3 +-
 sysdeps/unix/sysv/linux/alpha/Makefile        |   3 +-
 sysdeps/unix/sysv/linux/alpha/fxstat64.c      |   2 +-
 sysdeps/unix/sysv/linux/alpha/lxstat64.c      |   2 +-
 sysdeps/unix/sysv/linux/alpha/sysdep.h        |   4 +-
 sysdeps/unix/sysv/linux/alpha/xstat64.c       |   2 +-
 sysdeps/unix/sysv/linux/arc/sysdep.c          |  33 -----
 sysdeps/unix/sysv/linux/arc/sysdep.h          |  19 +--
 sysdeps/unix/sysv/linux/arm/sysdep.S          |  33 -----
 sysdeps/unix/sysv/linux/arm/sysdep.h          |   2 +
 sysdeps/unix/sysv/linux/arm/tls.h             |   2 +-
 sysdeps/unix/sysv/linux/clock_getcpuclockid.c |   1 +
 sysdeps/unix/sysv/linux/clock_nanosleep.c     |   2 +-
 sysdeps/unix/sysv/linux/createthread.c        |   6 +-
 sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S   |  65 ----------
 sysdeps/unix/sysv/linux/csky/sysdep.h         |   2 +
 sysdeps/unix/sysv/linux/dl-origin.c           |   2 +-
 sysdeps/unix/sysv/linux/dl-write.c            |   5 +-
 sysdeps/unix/sysv/linux/faccessat.c           |  10 +-
 sysdeps/unix/sysv/linux/fchmodat.c            |   2 +-
 sysdeps/unix/sysv/linux/fcntl_nocancel.c      |   5 +-
 sysdeps/unix/sysv/linux/fstatat.c             |   8 +-
 sysdeps/unix/sysv/linux/fstatat64.c           |   6 +-
 sysdeps/unix/sysv/linux/ftime.c               |   1 +
 sysdeps/unix/sysv/linux/ftruncate64.c         |   1 -
 sysdeps/unix/sysv/linux/futimens.c            |   2 +-
 sysdeps/unix/sysv/linux/fxstat.c              |   2 +-
 sysdeps/unix/sysv/linux/fxstat64.c            |   2 +-
 sysdeps/unix/sysv/linux/fxstatat.c            |   2 +-
 sysdeps/unix/sysv/linux/fxstatat64.c          |   2 +-
 sysdeps/unix/sysv/linux/generic/chmod.c       |   4 +-
 sysdeps/unix/sysv/linux/generic/chown.c       |   4 +-
 sysdeps/unix/sysv/linux/generic/dl-origin.c   |   2 +-
 sysdeps/unix/sysv/linux/generic/dup2.c        |   3 +-
 .../unix/sysv/linux/generic/epoll_create.c    |   5 +-
 .../unix/sysv/linux/generic/inotify_init.c    |   5 +-
 sysdeps/unix/sysv/linux/generic/lchown.c      |   4 +-
 sysdeps/unix/sysv/linux/generic/link.c        |   3 +-
 sysdeps/unix/sysv/linux/generic/pipe.c        |   3 +-
 sysdeps/unix/sysv/linux/generic/readlink.c    |   2 +-
 sysdeps/unix/sysv/linux/generic/rmdir.c       |   4 +-
 sysdeps/unix/sysv/linux/generic/symlink.c     |   3 +-
 sysdeps/unix/sysv/linux/generic/unlink.c      |   4 +-
 .../sysv/linux/generic/wordsize-32/fstatfs.c  |   2 +-
 .../sysv/linux/generic/wordsize-32/overflow.h |   1 +
 .../sysv/linux/generic/wordsize-32/sendfile.c |   2 +
 .../sysv/linux/generic/wordsize-32/statfs.c   |   2 +-
 sysdeps/unix/sysv/linux/getdents.c            |   2 +-
 sysdeps/unix/sysv/linux/getentropy.c          |   1 +
 sysdeps/unix/sysv/linux/getrlimit.c           |   3 +-
 sysdeps/unix/sysv/linux/getrlimit64.c         |   1 +
 sysdeps/unix/sysv/linux/gettimeofday.c        |   7 +-
 .../unix/sysv/linux/hppa/____longjmp_chk.c    |   2 +-
 sysdeps/unix/sysv/linux/hppa/clone.S          |   6 +-
 sysdeps/unix/sysv/linux/hppa/sysdep.c         |  29 -----
 sysdeps/unix/sysv/linux/hppa/sysdep.h         |   4 +
 sysdeps/unix/sysv/linux/i386/Makefile         |  13 --
 sysdeps/unix/sysv/linux/i386/brk.c            |   2 +-
 sysdeps/unix/sysv/linux/i386/sysdep.c         |  30 -----
 sysdeps/unix/sysv/linux/i386/sysdep.h         |   6 +-
 sysdeps/unix/sysv/linux/ia64/Makefile         |   5 -
 sysdeps/unix/sysv/linux/ia64/rt-sysdep.S      |   1 -
 sysdeps/unix/sysv/linux/ia64/syscall_error.c  |   3 +
 sysdeps/unix/sysv/linux/ia64/sysdep.S         |  58 ---------
 sysdeps/unix/sysv/linux/internal-signals.h    |   1 +
 sysdeps/unix/sysv/linux/libc_fatal.c          |   5 +-
 sysdeps/unix/sysv/linux/lxstat.c              |   2 +-
 sysdeps/unix/sysv/linux/lxstat64.c            |   2 +-
 .../unix/sysv/linux/m68k/____longjmp_chk.c    |   2 +-
 sysdeps/unix/sysv/linux/m68k/getpagesize.c    |   2 +-
 sysdeps/unix/sysv/linux/m68k/sysdep.S         |  50 --------
 sysdeps/unix/sysv/linux/m68k/sysdep.h         |  11 +-
 sysdeps/unix/sysv/linux/microblaze/Makefile   |   6 -
 sysdeps/unix/sysv/linux/microblaze/sysdep.S   |  39 ------
 sysdeps/unix/sysv/linux/microblaze/sysdep.h   |   4 +
 sysdeps/unix/sysv/linux/mips/clone.S          |   1 +
 sysdeps/unix/sysv/linux/mips/getcontext.S     |   1 +
 .../unix/sysv/linux/mips/mips64/fxstatat64.c  |   2 +-
 .../unix/sysv/linux/mips/mips64/n64/ioctl.S   |   3 +-
 sysdeps/unix/sysv/linux/mips/mips64/syscall.S |   3 +-
 sysdeps/unix/sysv/linux/mips/setcontext.S     |   1 +
 sysdeps/unix/sysv/linux/mips/swapcontext.S    |   1 +
 sysdeps/unix/sysv/linux/mips/syscall_error.c  |   3 +
 sysdeps/unix/sysv/linux/mips/vfork.S          |   1 +
 sysdeps/unix/sysv/linux/mknodat.c             |   3 +-
 sysdeps/unix/sysv/linux/mmap.c                |   2 +-
 sysdeps/unix/sysv/linux/mmap64.c              |   2 +-
 sysdeps/unix/sysv/linux/mq_open.c             |   2 +-
 sysdeps/unix/sysv/linux/mq_unlink.c           |  14 +--
 .../unix/sysv/linux/netlink_assert_response.c |   1 +
 sysdeps/unix/sysv/linux/nios2/sysdep.S        |  50 --------
 sysdeps/unix/sysv/linux/nios2/sysdep.h        |   2 +
 sysdeps/unix/sysv/linux/not-errno.h           |  14 +--
 sysdeps/unix/sysv/linux/nscd_setup_thread.c   |   2 +-
 sysdeps/unix/sysv/linux/personality.c         |  10 +-
 sysdeps/unix/sysv/linux/posix_fadvise.c       |  19 ++-
 sysdeps/unix/sysv/linux/posix_fadvise64.c     |  14 +--
 sysdeps/unix/sysv/linux/posix_fallocate.c     |   6 +-
 sysdeps/unix/sysv/linux/posix_fallocate64.c   |   6 +-
 sysdeps/unix/sysv/linux/posix_madvise.c       |   3 +-
 sysdeps/unix/sysv/linux/powerpc/Makefile      |   7 --
 .../unix/sysv/linux/powerpc/powerpc32/brk.S   |   1 +
 .../unix/sysv/linux/powerpc/powerpc32/clone.S |   3 +-
 .../sysv/linux/powerpc/powerpc32/getcontext.S |   2 +
 .../linux/powerpc/powerpc32/makecontext.S     |   2 +-
 .../powerpc/powerpc32/nofpu/getcontext.S      |   2 +-
 .../powerpc/powerpc32/nofpu/setcontext.S      |   2 +-
 .../powerpc/powerpc32/nofpu/swapcontext.S     |   2 +-
 .../sysv/linux/powerpc/powerpc32/setcontext.S |   3 +-
 .../linux/powerpc/powerpc32/swapcontext.S     |   3 +-
 sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c   |   1 -
 sysdeps/unix/sysv/linux/powerpc/sysdep.h      |   2 +
 sysdeps/unix/sysv/linux/prlimit.c             |   8 +-
 sysdeps/unix/sysv/linux/pthread_kill.c        |   4 +-
 sysdeps/unix/sysv/linux/pthread_sigqueue.c    |   5 +-
 sysdeps/unix/sysv/linux/readahead.c           |   2 +-
 sysdeps/unix/sysv/linux/riscv/syscall.c       |   2 +-
 sysdeps/unix/sysv/linux/riscv/sysdep.S        |  51 --------
 sysdeps/unix/sysv/linux/riscv/sysdep.h        |   2 +
 sysdeps/unix/sysv/linux/s390/Makefile         |   5 -
 sysdeps/unix/sysv/linux/s390/rt-sysdep.S      |   1 -
 .../sysv/linux/s390/s390-32/____longjmp_chk.c |   2 +-
 .../sysv/linux/s390/s390-32/posix_fadvise64.c |   5 +-
 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S |  74 -----------
 sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c |   2 +-
 .../unix/sysv/linux/s390/s390-32/utmpx32.c    |   2 +-
 .../sysv/linux/s390/s390-64/____longjmp_chk.c |   2 +-
 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S |  75 ------------
 sysdeps/unix/sysv/linux/s390/syscall_error.c  |   5 +
 sysdeps/unix/sysv/linux/semop.c               |   2 +-
 sysdeps/unix/sysv/linux/setegid.c             |   2 +-
 sysdeps/unix/sysv/linux/seteuid.c             |   2 +-
 sysdeps/unix/sysv/linux/setrlimit.c           |   3 +-
 sysdeps/unix/sysv/linux/setrlimit64.c         |   1 +
 sysdeps/unix/sysv/linux/settimezone.c         |   1 +
 sysdeps/unix/sysv/linux/sh/localplt.data      |   1 -
 sysdeps/unix/sysv/linux/sh/sysdep.S           |  32 -----
 sysdeps/unix/sysv/linux/sh/sysdep.h           |   2 +
 sysdeps/unix/sysv/linux/shmat.c               |   4 +-
 sysdeps/unix/sysv/linux/shmget.c              |   3 +-
 sysdeps/unix/sysv/linux/socketcall.h          |   2 +
 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 +
 .../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 +
 .../unix/sysv/linux/sparc/sparc64/sysdep.h    |   1 +
 sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S |   1 +
 sysdeps/unix/sysv/linux/sparc/sysdep.c        |   1 -
 sysdeps/unix/sysv/linux/sparc/sysdep.h        |   2 +
 sysdeps/unix/sysv/linux/speed.c               |   6 +-
 sysdeps/unix/sysv/linux/statx.c               |   2 +-
 .../{powerpc/sysdep.c => syscall_error.c}     |  16 +--
 sysdeps/unix/sysv/linux/sysctl.c              |   1 +
 sysdeps/unix/sysv/linux/sysdep-vdso.h         |  26 +---
 sysdeps/unix/sysv/linux/sysdep.h              |  77 +++++++-----
 sysdeps/unix/sysv/linux/tcsendbrk.c           |   2 +-
 sysdeps/unix/sysv/linux/tcsetattr.c           |   2 +-
 sysdeps/unix/sysv/linux/timer_create.c        |   4 +-
 sysdeps/unix/sysv/linux/times.c               |   7 +-
 sysdeps/unix/sysv/linux/truncate64.c          |   1 -
 sysdeps/unix/sysv/linux/ustat.c               |   6 +-
 sysdeps/unix/sysv/linux/utimensat.c           |   2 +-
 .../unix/sysv/linux/x86_64/syscall_error.c    |   5 +
 sysdeps/unix/sysv/linux/x86_64/sysdep.S       |  40 ------
 sysdeps/unix/sysv/linux/x86_64/x32/times.c    |   9 +-
 sysdeps/unix/sysv/linux/xmknod.c              |   3 +-
 sysdeps/unix/sysv/linux/xmknodat.c            |   3 +-
 sysdeps/unix/sysv/linux/xstat.c               |   2 +-
 sysdeps/unix/sysv/linux/xstat64.c             |   2 +-
 sysdeps/unix/sysv/linux/xstatconv.c           |  13 +-
 sysdeps/unix/x86_64/sysdep.S                  |  49 --------
 sysdeps/x86_64/stackinfo.h                    |  10 +-
 229 files changed, 388 insertions(+), 1468 deletions(-)
 delete mode 100644 sysdeps/mips/nptl/nptl-sysdep.S
 delete mode 100644 sysdeps/riscv/nptl/nptl-sysdep.S
 delete mode 100644 sysdeps/unix/alpha/rt-sysdep.S
 rename sysdeps/unix/alpha/{sysdep.S => syscall_error_asm.S} (94%)
 delete mode 100644 sysdeps/unix/arm/sysdep.S
 delete mode 100644 sysdeps/unix/mips/rt-sysdep.S
 delete mode 100644 sysdeps/unix/mips/sysdep.S
 delete mode 100644 sysdeps/unix/sh/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/aarch64/sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/arc/sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/hppa/sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_error.c
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/m68k/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/microblaze/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/mips/syscall_error.c
 delete mode 100644 sysdeps/unix/sysv/linux/nios2/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/riscv/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/s390/rt-sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/s390/syscall_error.c
 delete mode 100644 sysdeps/unix/sysv/linux/sh/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sysdep.c
 rename sysdeps/unix/sysv/linux/{powerpc/sysdep.c => syscall_error.c} (77%)
 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

-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-10 11:11   ` Florian Weimer
  2020-11-09 20:18 ` [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function Adhemerval Zanella
                   ` (21 subsequent siblings)
  22 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

All architectures now returns the error code on the INTERNAL_SYSCALL
value and follow the Linux de-facto ABI (error are signaled with a
value between -4096UL and -1UL).  This make the INTERNAL_SYSCALL_ERRNO
superflous and some implementations already checks for either values
different than 0 or for an specific errno in the failure case.

Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.
---
 nptl/allocatestack.c                                   |  2 +-
 nptl/nptl-init.c                                       |  2 +-
 nptl/pthread_cancel.c                                  |  2 +-
 nptl/pthread_getaffinity.c                             |  2 +-
 nptl/pthread_mutex_trylock.c                           |  3 +--
 nptl/pthread_setaffinity.c                             |  2 +-
 nptl/pthread_sigmask.c                                 |  2 +-
 sysdeps/nptl/lowlevellock-futex.h                      |  2 +-
 sysdeps/unix/sysv/linux/createthread.c                 |  2 +-
 sysdeps/unix/sysv/linux/dl-write.c                     |  5 +----
 sysdeps/unix/sysv/linux/fcntl_nocancel.c               |  3 +--
 sysdeps/unix/sysv/linux/libc_fatal.c                   |  3 +--
 sysdeps/unix/sysv/linux/mq_unlink.c                    |  7 +++----
 sysdeps/unix/sysv/linux/not-errno.h                    |  4 ++--
 sysdeps/unix/sysv/linux/personality.c                  | 10 +---------
 sysdeps/unix/sysv/linux/posix_fadvise.c                |  4 +---
 sysdeps/unix/sysv/linux/posix_fadvise64.c              |  4 +---
 sysdeps/unix/sysv/linux/posix_fallocate.c              |  4 ++--
 sysdeps/unix/sysv/linux/posix_fallocate64.c            |  4 ++--
 sysdeps/unix/sysv/linux/posix_madvise.c                |  3 +--
 sysdeps/unix/sysv/linux/pthread_kill.c                 |  3 +--
 sysdeps/unix/sysv/linux/pthread_sigqueue.c             |  3 +--
 sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c |  4 +---
 sysdeps/unix/sysv/linux/shmat.c                        |  2 +-
 sysdeps/unix/sysv/linux/sysdep-vdso.h                  |  4 ++--
 sysdeps/unix/sysv/linux/sysdep.h                       |  5 +----
 sysdeps/unix/sysv/linux/timer_create.c                 |  2 +-
 sysdeps/unix/sysv/linux/times.c                        |  2 +-
 28 files changed, 34 insertions(+), 61 deletions(-)

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 4b45f8c884..a9e9d39354 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -1174,7 +1174,7 @@ __nptl_setxid (struct xid_command *cmdp)
   int error = 0;
   if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result)))
     {
-      error = INTERNAL_SYSCALL_ERRNO (result);
+      error = -result;
       __set_errno (error);
       result = -1;
     }
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 95c60a524a..8aef4c83b5 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -192,7 +192,7 @@ sighandler_setxid (int sig, siginfo_t *si, void *ctx)
 				 __xidcmd->id[1], __xidcmd->id[2]);
   int error = 0;
   if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result)))
-    error = INTERNAL_SYSCALL_ERRNO (result);
+    error = -result;
   __nptl_setxid_error (__xidcmd, error);
 
   /* Reset the SETXID flag.  */
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 88c1ab8f6a..7daf4f8c15 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -70,7 +70,7 @@ __pthread_cancel (pthread_t th)
 	  int val = INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid,
 					   SIGCANCEL);
 	  if (INTERNAL_SYSCALL_ERROR_P (val))
-	    result = INTERNAL_SYSCALL_ERRNO (val);
+	    result = -val;
 
 	  break;
 	}
diff --git a/nptl/pthread_getaffinity.c b/nptl/pthread_getaffinity.c
index 6ebd1ded2d..ffeb878c7c 100644
--- a/nptl/pthread_getaffinity.c
+++ b/nptl/pthread_getaffinity.c
@@ -34,7 +34,7 @@ __pthread_getaffinity_np (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset)
   int res = INTERNAL_SYSCALL_CALL (sched_getaffinity, pd->tid,
 				   MIN (INT_MAX, cpusetsize), cpuset);
   if (INTERNAL_SYSCALL_ERROR_P (res))
-    return INTERNAL_SYSCALL_ERRNO (res);
+    return -res;
 
   /* Clean the rest of the memory the kernel didn't do.  */
   memset ((char *) cpuset + res, '\0', cpusetsize - res);
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 2130f52529..5c294a3eea 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -301,8 +301,7 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
 					   __lll_private_flag (FUTEX_TRYLOCK_PI,
 							       private), 0, 0);
 
-	    if (INTERNAL_SYSCALL_ERROR_P (e)
-		&& INTERNAL_SYSCALL_ERRNO (e) == EWOULDBLOCK)
+	    if (INTERNAL_SYSCALL_ERROR_P (e) && e == -EWOULDBLOCK)
 	      {
 		/* The kernel has not yet finished the mutex owner death.
 		   We do not need to ensure ordering wrt another memory
diff --git a/nptl/pthread_setaffinity.c b/nptl/pthread_setaffinity.c
index b0bd90c324..aaaa4f0194 100644
--- a/nptl/pthread_setaffinity.c
+++ b/nptl/pthread_setaffinity.c
@@ -34,7 +34,7 @@ __pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
 			       cpuset);
 
   return (INTERNAL_SYSCALL_ERROR_P (res)
-	  ? INTERNAL_SYSCALL_ERRNO (res)
+	  ? -res
 	  : 0);
 }
 versioned_symbol (libpthread, __pthread_setaffinity_new,
diff --git a/nptl/pthread_sigmask.c b/nptl/pthread_sigmask.c
index 7b65ae1f27..1d6d753af4 100644
--- a/nptl/pthread_sigmask.c
+++ b/nptl/pthread_sigmask.c
@@ -42,7 +42,7 @@ __pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask)
 				      oldmask, __NSIG_BYTES);
 
   return (INTERNAL_SYSCALL_ERROR_P (result)
-	  ? INTERNAL_SYSCALL_ERRNO (result)
+	  ? -result
 	  : 0);
 }
 libc_hidden_def (__pthread_sigmask)
diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h
index 2209ca76a1..dd36997021 100644
--- a/sysdeps/nptl/lowlevellock-futex.h
+++ b/sysdeps/nptl/lowlevellock-futex.h
@@ -70,7 +70,7 @@
     long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, 	\
 				       __VA_ARGS__);                    \
     (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
-     ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0);                     	\
+     ? __ret : 0);                     					\
   })
 
 /* For most of these macros, the return value is never really used.
diff --git a/sysdeps/unix/sysv/linux/createthread.c b/sysdeps/unix/sysv/linux/createthread.c
index 6588893ba5..01cf2ff42a 100644
--- a/sysdeps/unix/sysv/linux/createthread.c
+++ b/sysdeps/unix/sysv/linux/createthread.c
@@ -132,7 +132,7 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr,
 	      pid_t pid = __getpid ();
 	      INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid, SIGCANCEL);
 
-	      return INTERNAL_SYSCALL_ERRNO (res);
+	      return -res;
 	    }
 	}
 
diff --git a/sysdeps/unix/sysv/linux/dl-write.c b/sysdeps/unix/sysv/linux/dl-write.c
index 1c6298fb41..cce5a55e68 100644
--- a/sysdeps/unix/sysv/linux/dl-write.c
+++ b/sysdeps/unix/sysv/linux/dl-write.c
@@ -23,8 +23,5 @@
 ssize_t
 _dl_write (int fd, const void *buffer, size_t length)
 {
-  long int r = INTERNAL_SYSCALL_CALL (write, fd, buffer, length);
-  if (INTERNAL_SYSCALL_ERROR_P (r))
-    r = - INTERNAL_SYSCALL_ERRNO (r);
-  return r;
+  return INTERNAL_SYSCALL_CALL (write, fd, buffer, length);
 }
diff --git a/sysdeps/unix/sysv/linux/fcntl_nocancel.c b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
index ed9211001f..1bf3030f75 100644
--- a/sysdeps/unix/sysv/linux/fcntl_nocancel.c
+++ b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
@@ -56,8 +56,7 @@ __fcntl64_nocancel_adjusted (int fd, int cmd, void *arg)
       if (!INTERNAL_SYSCALL_ERROR_P (res))
 	return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
 
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE
-        (INTERNAL_SYSCALL_ERRNO (res));
+      return INLINE_SYSCALL_ERROR_RETURN_VALUE (-res);
     }
 
   return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c
index 7e22c0fc32..35a20ca0fd 100644
--- a/sysdeps/unix/sysv/linux/libc_fatal.c
+++ b/sysdeps/unix/sysv/linux/libc_fatal.c
@@ -25,8 +25,7 @@ writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
   ssize_t cnt;
   do
     cnt = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov);
-  while (INTERNAL_SYSCALL_ERROR_P (cnt)
-         && INTERNAL_SYSCALL_ERRNO (cnt) == EINTR);
+  while (INTERNAL_SYSCALL_ERROR_P (cnt) && cnt == -EINTR);
   return cnt == total;
 }
 #define WRITEV_FOR_FATAL	writev_for_fatal
diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c
index 85fb5d0951..ed7858dc9d 100644
--- a/sysdeps/unix/sysv/linux/mq_unlink.c
+++ b/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -32,10 +32,9 @@ mq_unlink (const char *name)
      return just EACCES.  */
   if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret)))
     {
-      ret = INTERNAL_SYSCALL_ERRNO (ret);
-      if (ret == EPERM)
-	ret = EACCES;
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (ret);
+      if (ret == -EPERM)
+	ret = -EACCES;
+      return INLINE_SYSCALL_ERROR_RETURN_VALUE (-ret);
     }
 
   return ret;
diff --git a/sysdeps/unix/sysv/linux/not-errno.h b/sysdeps/unix/sysv/linux/not-errno.h
index 394dabeb93..fc0eda09d9 100644
--- a/sysdeps/unix/sysv/linux/not-errno.h
+++ b/sysdeps/unix/sysv/linux/not-errno.h
@@ -32,7 +32,7 @@ __access_noerrno (const char *pathname, int mode)
   res = INTERNAL_SYSCALL_CALL (faccessat, AT_FDCWD, pathname, mode);
 #endif
   if (INTERNAL_SYSCALL_ERROR_P (res))
-    return INTERNAL_SYSCALL_ERRNO (res);
+    return -res;
   return 0;
 }
 
@@ -42,6 +42,6 @@ __kill_noerrno (pid_t pid, int sig)
   int res;
   res = INTERNAL_SYSCALL_CALL (kill, pid, sig);
   if (INTERNAL_SYSCALL_ERROR_P (res))
-    return INTERNAL_SYSCALL_ERRNO (res);
+    return -res;
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/personality.c b/sysdeps/unix/sysv/linux/personality.c
index e45fffa1c2..75f9d0adb2 100644
--- a/sysdeps/unix/sysv/linux/personality.c
+++ b/sysdeps/unix/sysv/linux/personality.c
@@ -35,14 +35,6 @@ __personality (unsigned long persona)
   persona = (unsigned int) persona;
 #endif
 
-  long int ret = INTERNAL_SYSCALL_CALL (personality, persona);
-
-  /* Starting with kernel commit v2.6.29-6609-g11d06b2, the personality syscall
-     never fails.  However, 32-bit kernels might flag valid values as errors, so
-     we need to reverse the error setting.  We can't use the raw result as some
-     arches split the return/error values.  */
-  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret)))
-    ret = -INTERNAL_SYSCALL_ERRNO (ret);
-  return ret;
+  return INTERNAL_SYSCALL_CALL (personality, persona);
 }
 weak_alias (__personality, personality)
diff --git a/sysdeps/unix/sysv/linux/posix_fadvise.c b/sysdeps/unix/sysv/linux/posix_fadvise.c
index bada96b697..1191ab3db5 100644
--- a/sysdeps/unix/sysv/linux/posix_fadvise.c
+++ b/sysdeps/unix/sysv/linux/posix_fadvise.c
@@ -60,8 +60,6 @@ posix_fadvise (int fd, off_t offset, off_t len, int advise)
 				   SYSCALL_LL (len), advise);
 #  endif
 # endif
-  if (INTERNAL_SYSCALL_ERROR_P (ret))
-    return INTERNAL_SYSCALL_ERRNO (ret);
-  return 0;
+  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
 }
 #endif /* __OFF_T_MATCHES_OFF64_T  */
diff --git a/sysdeps/unix/sysv/linux/posix_fadvise64.c b/sysdeps/unix/sysv/linux/posix_fadvise64.c
index 9787ab4c7c..e3726a6a8a 100644
--- a/sysdeps/unix/sysv/linux/posix_fadvise64.c
+++ b/sysdeps/unix/sysv/linux/posix_fadvise64.c
@@ -48,9 +48,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
 				   __ALIGNMENT_ARG SYSCALL_LL64 (offset),
 				   SYSCALL_LL64 (len), advise);
 #endif
-  if (!INTERNAL_SYSCALL_ERROR_P (ret))
-    return 0;
-  return INTERNAL_SYSCALL_ERRNO (ret);
+  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
 }
 
 /* The type of the len argument was changed from size_t to off_t in
diff --git a/sysdeps/unix/sysv/linux/posix_fallocate.c b/sysdeps/unix/sysv/linux/posix_fallocate.c
index 7238b00038..87532668cd 100644
--- a/sysdeps/unix/sysv/linux/posix_fallocate.c
+++ b/sysdeps/unix/sysv/linux/posix_fallocate.c
@@ -30,7 +30,7 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
 				   SYSCALL_LL (offset), SYSCALL_LL (len));
   if (! INTERNAL_SYSCALL_ERROR_P (res))
     return 0;
-  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
-    return INTERNAL_SYSCALL_ERRNO (res);
+  if (res != -EOPNOTSUPP)
+    return -res;
   return internal_fallocate (fd, offset, len);
 }
diff --git a/sysdeps/unix/sysv/linux/posix_fallocate64.c b/sysdeps/unix/sysv/linux/posix_fallocate64.c
index 2de63ac277..0340357e57 100644
--- a/sysdeps/unix/sysv/linux/posix_fallocate64.c
+++ b/sysdeps/unix/sysv/linux/posix_fallocate64.c
@@ -32,8 +32,8 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
 				   SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
   if (! INTERNAL_SYSCALL_ERROR_P (res))
     return 0;
-  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
-    return INTERNAL_SYSCALL_ERRNO (res);
+  if (-res != EOPNOTSUPP)
+    return -res;
   return internal_fallocate64 (fd, offset, len);
 }
 libc_hidden_def (__posix_fallocate64_l64)
diff --git a/sysdeps/unix/sysv/linux/posix_madvise.c b/sysdeps/unix/sysv/linux/posix_madvise.c
index 0e49f3b7ac..5fe2e5f653 100644
--- a/sysdeps/unix/sysv/linux/posix_madvise.c
+++ b/sysdeps/unix/sysv/linux/posix_madvise.c
@@ -31,6 +31,5 @@ posix_madvise (void *addr, size_t len, int advice)
   if (advice == POSIX_MADV_DONTNEED)
     return 0;
 
-  int result = INTERNAL_SYSCALL_CALL (madvise, addr, len, advice);
-  return INTERNAL_SYSCALL_ERRNO (result);
+  return -INTERNAL_SYSCALL_CALL (madvise, addr, len, advice);
 }
diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c
index 4dfe08ffcd..defdeaecac 100644
--- a/sysdeps/unix/sysv/linux/pthread_kill.c
+++ b/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -51,7 +51,6 @@ __pthread_kill (pthread_t threadid, int signo)
   pid_t pid = __getpid ();
 
   int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo);
-  return (INTERNAL_SYSCALL_ERROR_P (val)
-	  ? INTERNAL_SYSCALL_ERRNO (val) : 0);
+  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
 }
 strong_alias (__pthread_kill, pthread_kill)
diff --git a/sysdeps/unix/sysv/linux/pthread_sigqueue.c b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
index 4b32be2d64..fbbd9fee20 100644
--- a/sysdeps/unix/sysv/linux/pthread_sigqueue.c
+++ b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
@@ -63,8 +63,7 @@ pthread_sigqueue (pthread_t threadid, int signo, const union sigval value)
   /* We have a special syscall to do the work.  */
   int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo,
 				   &info);
-  return (INTERNAL_SYSCALL_ERROR_P (val)
-	  ? INTERNAL_SYSCALL_ERRNO (val) : 0);
+  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
 #else
   return ENOSYS;
 #endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
index b556a6caae..6199589307 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
@@ -43,9 +43,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
   parameters.len = len;
   parameters.advise = advise;
   int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, &parameters);
-  if (!INTERNAL_SYSCALL_ERROR_P (ret))
-    return 0;
-  return INTERNAL_SYSCALL_ERRNO (ret);
+  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
 }
 
 #include <shlib-compat.h>
diff --git a/sysdeps/unix/sysv/linux/shmat.c b/sysdeps/unix/sysv/linux/shmat.c
index 89df350d84..d5a65c06c1 100644
--- a/sysdeps/unix/sysv/linux/shmat.c
+++ b/sysdeps/unix/sysv/linux/shmat.c
@@ -36,7 +36,7 @@ shmat (int shmid, const void *shmaddr, int shmflg)
   resultvar = INTERNAL_SYSCALL_CALL (ipc, IPCOP_shmat, shmid, shmflg,
 				     &raddr, shmaddr);
   if (INTERNAL_SYSCALL_ERROR_P (resultvar))
-    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (resultvar));
+    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (-resultvar);
 
   return raddr;
 #endif
diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index a9215494dc..88db076184 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -38,7 +38,7 @@
 	sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
 	if (!INTERNAL_SYSCALL_ERROR_P (sc_ret))			      	      \
 	  goto out;							      \
-	if (INTERNAL_SYSCALL_ERRNO (sc_ret) != ENOSYS)		      	      \
+	if (sc_ret != -ENOSYS)		      	      			      \
 	  goto iserr;							      \
       }									      \
 									      \
@@ -46,7 +46,7 @@
     if (INTERNAL_SYSCALL_ERROR_P (sc_ret))			      	      \
       {									      \
       iserr:								      \
-        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret));		      	      \
+        __set_errno (-sc_ret);		      	      			      \
         sc_ret = -1L;							      \
       }									      \
   out:									      \
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 5e7b6c5765..4e25e51470 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -42,13 +42,10 @@
   ({									\
     long int sc_ret = INTERNAL_SYSCALL (name, nr, args);		\
     __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (sc_ret))		\
-    ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (sc_ret))		\
+    ? SYSCALL_ERROR_LABEL (-sc_ret)					\
     : sc_ret;								\
   })
 
-#undef INTERNAL_SYSCALL_ERRNO
-#define INTERNAL_SYSCALL_ERRNO(val)     (-(val))
-
 /* Set error number and return -1.  A target may choose to return the
    internal function, __syscall_error, which sets errno and returns -1.
    We use -1l, instead of -1, so that it can be casted to (void *).  */
diff --git a/sysdeps/unix/sysv/linux/timer_create.c b/sysdeps/unix/sysv/linux/timer_create.c
index 18fb00c6e6..d8289d1dc7 100644
--- a/sysdeps/unix/sysv/linux/timer_create.c
+++ b/sysdeps/unix/sysv/linux/timer_create.c
@@ -127,7 +127,7 @@ timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid)
 	if (INTERNAL_SYSCALL_ERROR_P (res))
 	  {
 	    free (newp);
-	    __set_errno (INTERNAL_SYSCALL_ERRNO (res));
+	    __set_errno (-res);
 	    return -1;
 	  }
 
diff --git a/sysdeps/unix/sysv/linux/times.c b/sysdeps/unix/sysv/linux/times.c
index e3db9cb400..b5eb6404c9 100644
--- a/sysdeps/unix/sysv/linux/times.c
+++ b/sysdeps/unix/sysv/linux/times.c
@@ -25,7 +25,7 @@ __times (struct tms *buf)
 {
   clock_t ret = INTERNAL_SYSCALL_CALL (times, buf);
   if (INTERNAL_SYSCALL_ERROR_P (ret)
-      && __glibc_unlikely (INTERNAL_SYSCALL_ERRNO (ret) == EFAULT)
+      && __glibc_unlikely (ret == -EFAULT)
       && buf)
     {
       /* This might be an error or not.  For architectures which have no
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-10 11:27   ` Florian Weimer
  2020-11-09 20:18 ` [PATCH 03/23] Remove tls.h inclusion from internal errno.h Adhemerval Zanella
                   ` (20 subsequent siblings)
  22 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

It also allows simplify some posix and pthread implementations.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 nptl/allocatestack.c                            |  4 ++--
 nptl/nptl-init.c                                |  4 ++--
 nptl/pthread_cancel.c                           |  2 +-
 nptl/pthread_getaffinity.c                      |  2 +-
 nptl/pthread_mutex_trylock.c                    |  2 +-
 nptl/pthread_setaffinity.c                      |  9 ++-------
 nptl/pthread_sigmask.c                          |  8 ++------
 sysdeps/arc/nptl/tls.h                          |  2 +-
 sysdeps/csky/nptl/tls.h                         |  2 +-
 sysdeps/m68k/nptl/tls.h                         |  2 +-
 sysdeps/mips/nptl/tls.h                         |  2 +-
 sysdeps/nptl/lowlevellock-futex.h               |  7 +------
 sysdeps/powerpc/nofpu/sfp-machine.h             |  2 +-
 sysdeps/unix/sysv/linux/arm/tls.h               |  2 +-
 sysdeps/unix/sysv/linux/clock_nanosleep.c       |  2 +-
 sysdeps/unix/sysv/linux/createthread.c          |  4 ++--
 sysdeps/unix/sysv/linux/dl-origin.c             |  2 +-
 sysdeps/unix/sysv/linux/fcntl_nocancel.c        |  2 +-
 sysdeps/unix/sysv/linux/fstatat.c               |  2 +-
 sysdeps/unix/sysv/linux/fstatat64.c             |  2 +-
 sysdeps/unix/sysv/linux/generic/dl-origin.c     |  2 +-
 sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c  |  2 +-
 sysdeps/unix/sysv/linux/libc_fatal.c            |  2 +-
 sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c  |  2 +-
 sysdeps/unix/sysv/linux/m68k/getpagesize.c      |  2 +-
 sysdeps/unix/sysv/linux/mq_unlink.c             |  2 +-
 sysdeps/unix/sysv/linux/not-errno.h             | 14 +++-----------
 sysdeps/unix/sysv/linux/nscd_setup_thread.c     |  2 +-
 sysdeps/unix/sysv/linux/posix_fadvise.c         | 17 ++++++++---------
 sysdeps/unix/sysv/linux/posix_fadvise64.c       | 11 +++++------
 sysdeps/unix/sysv/linux/posix_fallocate.c       |  4 +---
 sysdeps/unix/sysv/linux/posix_fallocate64.c     |  4 +---
 sysdeps/unix/sysv/linux/pthread_kill.c          |  3 +--
 sysdeps/unix/sysv/linux/pthread_sigqueue.c      |  4 +---
 sysdeps/unix/sysv/linux/riscv/syscall.c         |  2 +-
 .../sysv/linux/s390/s390-32/____longjmp_chk.c   |  2 +-
 .../sysv/linux/s390/s390-32/posix_fadvise64.c   |  3 +--
 .../sysv/linux/s390/s390-64/____longjmp_chk.c   |  2 +-
 sysdeps/unix/sysv/linux/shmat.c                 |  2 +-
 sysdeps/unix/sysv/linux/sysdep-vdso.h           |  4 ++--
 sysdeps/unix/sysv/linux/sysdep.h                | 14 ++++++++++----
 sysdeps/unix/sysv/linux/timer_create.c          |  2 +-
 sysdeps/unix/sysv/linux/times.c                 |  5 ++++-
 sysdeps/unix/sysv/linux/x86_64/x32/times.c      |  9 ++++++---
 44 files changed, 80 insertions(+), 100 deletions(-)

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index a9e9d39354..1e34623a86 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -1043,7 +1043,7 @@ setxid_signal_thread (struct xid_command *cmdp, struct pthread *t)
   val = INTERNAL_SYSCALL_CALL (tgkill, pid, t->tid, SIGSETXID);
 
   /* If this failed, it must have had not started yet or else exited.  */
-  if (!INTERNAL_SYSCALL_ERROR_P (val))
+  if (!syscall_error (val))
     {
       atomic_increment (&cmdp->cntr);
       return 1;
@@ -1172,7 +1172,7 @@ __nptl_setxid (struct xid_command *cmdp)
   result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, 3,
 				 cmdp->id[0], cmdp->id[1], cmdp->id[2]);
   int error = 0;
-  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result)))
+  if (__glibc_unlikely (syscall_error (result)))
     {
       error = -result;
       __set_errno (error);
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 8aef4c83b5..38a3bbea56 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -191,7 +191,7 @@ sighandler_setxid (int sig, siginfo_t *si, void *ctx)
   result = INTERNAL_SYSCALL_NCS (__xidcmd->syscall_no, 3, __xidcmd->id[0],
 				 __xidcmd->id[1], __xidcmd->id[2]);
   int error = 0;
-  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result)))
+  if (__glibc_unlikely (syscall_error (result)))
     error = -result;
   __nptl_setxid_error (__xidcmd, error);
 
@@ -243,7 +243,7 @@ __pthread_initialize_minimal_internal (void)
 						__data.__list.__next));
     int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head,
 				     sizeof (struct robust_list_head));
-    if (INTERNAL_SYSCALL_ERROR_P (res))
+    if (syscall_error (res))
       set_robust_list_not_avail ();
   }
 
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 7daf4f8c15..855ecef87b 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -69,7 +69,7 @@ __pthread_cancel (pthread_t th)
 
 	  int val = INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid,
 					   SIGCANCEL);
-	  if (INTERNAL_SYSCALL_ERROR_P (val))
+	  if (syscall_error (val))
 	    result = -val;
 
 	  break;
diff --git a/nptl/pthread_getaffinity.c b/nptl/pthread_getaffinity.c
index ffeb878c7c..a9e7071e62 100644
--- a/nptl/pthread_getaffinity.c
+++ b/nptl/pthread_getaffinity.c
@@ -33,7 +33,7 @@ __pthread_getaffinity_np (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset)
 
   int res = INTERNAL_SYSCALL_CALL (sched_getaffinity, pd->tid,
 				   MIN (INT_MAX, cpusetsize), cpuset);
-  if (INTERNAL_SYSCALL_ERROR_P (res))
+  if (syscall_error (res))
     return -res;
 
   /* Clean the rest of the memory the kernel didn't do.  */
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 5c294a3eea..492f011cae 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -301,7 +301,7 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
 					   __lll_private_flag (FUTEX_TRYLOCK_PI,
 							       private), 0, 0);
 
-	    if (INTERNAL_SYSCALL_ERROR_P (e) && e == -EWOULDBLOCK)
+	    if (e == -EWOULDBLOCK)
 	      {
 		/* The kernel has not yet finished the mutex owner death.
 		   We do not need to ensure ordering wrt another memory
diff --git a/nptl/pthread_setaffinity.c b/nptl/pthread_setaffinity.c
index aaaa4f0194..bcf8ac1376 100644
--- a/nptl/pthread_setaffinity.c
+++ b/nptl/pthread_setaffinity.c
@@ -28,14 +28,9 @@ __pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
 			   const cpu_set_t *cpuset)
 {
   const struct pthread *pd = (const struct pthread *) th;
-  int res;
 
-  res = INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, cpusetsize,
-			       cpuset);
-
-  return (INTERNAL_SYSCALL_ERROR_P (res)
-	  ? -res
-	  : 0);
+  return -INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, cpusetsize,
+				 cpuset);
 }
 versioned_symbol (libpthread, __pthread_setaffinity_new,
 		  pthread_setaffinity_np, GLIBC_2_3_4);
diff --git a/nptl/pthread_sigmask.c b/nptl/pthread_sigmask.c
index 1d6d753af4..7939a6cfe6 100644
--- a/nptl/pthread_sigmask.c
+++ b/nptl/pthread_sigmask.c
@@ -38,12 +38,8 @@ __pthread_sigmask (int how, const sigset_t *newmask, sigset_t *oldmask)
     }
 
   /* We know that realtime signals are available if NPTL is used.  */
-  int result = INTERNAL_SYSCALL_CALL (rt_sigprocmask, how, newmask,
-				      oldmask, __NSIG_BYTES);
-
-  return (INTERNAL_SYSCALL_ERROR_P (result)
-	  ? -result
-	  : 0);
+  return -INTERNAL_SYSCALL_CALL (rt_sigprocmask, how, newmask, oldmask,
+				 __NSIG_BYTES);
 }
 libc_hidden_def (__pthread_sigmask)
 
diff --git a/sysdeps/arc/nptl/tls.h b/sysdeps/arc/nptl/tls.h
index 184b550ab5..de9cd9c3ca 100644
--- a/sysdeps/arc/nptl/tls.h
+++ b/sysdeps/arc/nptl/tls.h
@@ -81,7 +81,7 @@ typedef struct
 	long result_var;					\
 	__builtin_set_thread_pointer (tcbp);     		\
 	result_var = INTERNAL_SYSCALL_CALL (arc_settls, (tcbp));\
-	INTERNAL_SYSCALL_ERROR_P (result_var)			\
+	syscall_error (result_var)				\
 	  ? "settls syscall error" : NULL;			\
    })
 
diff --git a/sysdeps/csky/nptl/tls.h b/sysdeps/csky/nptl/tls.h
index bcca9674a1..dd864cdc7c 100644
--- a/sysdeps/csky/nptl/tls.h
+++ b/sysdeps/csky/nptl/tls.h
@@ -99,7 +99,7 @@ typedef struct
   ({ long int result_var;						\
      result_var = INTERNAL_SYSCALL_CALL (set_thread_area, 		\
                     (char *) (tcbp) + TLS_TCB_OFFSET);			\
-     INTERNAL_SYSCALL_ERROR_P (result_var)				\
+     syscall_error (result_var)						\
        ? "unknown error" : NULL; })
 
 /* Return the address of the dtv for the current thread.  */
diff --git a/sysdeps/m68k/nptl/tls.h b/sysdeps/m68k/nptl/tls.h
index 68ea952e79..77b7afe67f 100644
--- a/sysdeps/m68k/nptl/tls.h
+++ b/sysdeps/m68k/nptl/tls.h
@@ -99,7 +99,7 @@ typedef struct
 									\
     _sys_result = INTERNAL_SYSCALL_CALL (set_thread_area, 		\
 				    ((void *) (tcbp)) + TLS_TCB_OFFSET); \
-    INTERNAL_SYSCALL_ERROR_P (_sys_result) ? "unknown error" : NULL; })
+    syscall_error (_sys_result) ? "unknown error" : NULL; })
 
 # define TLS_DEFINE_INIT_TP(tp, pd) \
   void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h
index 8b55f19c37..e91c0074e8 100644
--- a/sysdeps/mips/nptl/tls.h
+++ b/sysdeps/mips/nptl/tls.h
@@ -123,7 +123,7 @@ typedef struct
   ({ long int result_var;						\
      result_var = INTERNAL_SYSCALL_CALL (set_thread_area, 		\
 				    (char *) (tcbp) + TLS_TCB_OFFSET);	\
-     INTERNAL_SYSCALL_ERROR_P (result_var)				\
+     syscall_error (result_var)						\
        ? "unknown error" : NULL; })
 
 /* Value passed to 'clone' for initialization of the thread register.  */
diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h
index dd36997021..c6a0908ff1 100644
--- a/sysdeps/nptl/lowlevellock-futex.h
+++ b/sysdeps/nptl/lowlevellock-futex.h
@@ -66,12 +66,7 @@
 # endif
 
 # define lll_futex_syscall(nargs, futexp, op, ...)                      \
-  ({                                                                    \
-    long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, 	\
-				       __VA_ARGS__);                    \
-    (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
-     ? __ret : 0);                     					\
-  })
+  INTERNAL_SYSCALL (futex, nargs, futexp, op, __VA_ARGS__)
 
 /* For most of these macros, the return value is never really used.
    Nevertheless, the protocol is that each one returns a negated errno
diff --git a/sysdeps/powerpc/nofpu/sfp-machine.h b/sysdeps/powerpc/nofpu/sfp-machine.h
index 8489c0f1c0..110a3bf547 100644
--- a/sysdeps/powerpc/nofpu/sfp-machine.h
+++ b/sysdeps/powerpc/nofpu/sfp-machine.h
@@ -70,7 +70,7 @@ libc_hidden_proto (__feraiseexcept_soft)
 									\
       _spefscr = fegetenv_register ();					\
       _r = INTERNAL_SYSCALL_CALL (prctl, PR_GET_FPEXC, &_ftrapex);	\
-      if (INTERNAL_SYSCALL_ERROR_P (_r))				\
+      if (syscall_error (_r))						\
 	_ftrapex = 0;							\
     }									\
   while (0)
diff --git a/sysdeps/unix/sysv/linux/arm/tls.h b/sysdeps/unix/sysv/linux/arm/tls.h
index 57b583dbd8..4155d6c030 100644
--- a/sysdeps/unix/sysv/linux/arm/tls.h
+++ b/sysdeps/unix/sysv/linux/arm/tls.h
@@ -33,7 +33,7 @@
 # define TLS_INIT_TP(tcbp) \
   ({ long int result_var;						\
      result_var = INTERNAL_SYSCALL_CALL (set_tls, (tcbp));		\
-     INTERNAL_SYSCALL_ERROR_P (result_var)				\
+     syscall_error (result_var)						\
        ? "unknown error" : NULL; })
 
 #endif /* __ASSEMBLER__ */
diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c
index 6ad3321435..ace1191d90 100644
--- a/sysdeps/unix/sysv/linux/clock_nanosleep.c
+++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -57,7 +57,7 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec
   struct timespec ts32 = valid_timespec64_to_timespec (*req);
   r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, clock_id, flags,
                                &ts32, &tr32);
-  if (INTERNAL_SYSCALL_ERROR_P (r))
+  if (syscall_error (r))
     {
       if (r == -EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0)
 	*rem = valid_timespec_to_timespec64 (tr32);
diff --git a/sysdeps/unix/sysv/linux/createthread.c b/sysdeps/unix/sysv/linux/createthread.c
index 01cf2ff42a..1c224155f8 100644
--- a/sysdeps/unix/sysv/linux/createthread.c
+++ b/sysdeps/unix/sysv/linux/createthread.c
@@ -123,7 +123,7 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr,
 				       attr->extension->cpusetsize,
 				       attr->extension->cpuset);
 
-	  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (res)))
+	  if (__glibc_unlikely (syscall_error (res)))
 	  err_out:
 	    {
 	      /* The operation failed.  We have to kill the thread.
@@ -144,7 +144,7 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr,
 	  res = INTERNAL_SYSCALL_CALL (sched_setscheduler, pd->tid,
 				       pd->schedpolicy, &pd->schedparam);
 
-	  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (res)))
+	  if (__glibc_unlikely (syscall_error (res)))
 	    goto err_out;
 	}
     }
diff --git a/sysdeps/unix/sysv/linux/dl-origin.c b/sysdeps/unix/sysv/linux/dl-origin.c
index 515ed6fc8c..00cba11495 100644
--- a/sysdeps/unix/sysv/linux/dl-origin.c
+++ b/sysdeps/unix/sysv/linux/dl-origin.c
@@ -40,7 +40,7 @@ _dl_get_origin (void)
 
   len = INTERNAL_SYSCALL_CALL (readlink, "/proc/self/exe", linkval,
 			       sizeof (linkval));
-  if (! INTERNAL_SYSCALL_ERROR_P (len) && len > 0 && linkval[0] != '[')
+  if (! syscall_error (len) && len > 0 && linkval[0] != '[')
     {
       /* We can use this value.  */
       assert (linkval[0] == '/');
diff --git a/sysdeps/unix/sysv/linux/fcntl_nocancel.c b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
index 1bf3030f75..a16fc75cb7 100644
--- a/sysdeps/unix/sysv/linux/fcntl_nocancel.c
+++ b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
@@ -53,7 +53,7 @@ __fcntl64_nocancel_adjusted (int fd, int cmd, void *arg)
     {
       struct f_owner_ex fex;
       int res = INTERNAL_SYSCALL_CALL (fcntl64, fd, F_GETOWN_EX, &fex);
-      if (!INTERNAL_SYSCALL_ERROR_P (res))
+      if (!syscall_error (res))
 	return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
 
       return INLINE_SYSCALL_ERROR_RETURN_VALUE (-res);
diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index db49e3155c..a61fffa6e7 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -80,7 +80,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
 #  endif /* __nr_fstatat64  */
 # endif /* STAT_IS_KERNEL_STAT  */
 
-  return INTERNAL_SYSCALL_ERROR_P (r)
+  return syscall_error (r)
 	 ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
 	 : 0;
 }
diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c
index 44347603b4..6e12cf2456 100644
--- a/sysdeps/unix/sysv/linux/fstatat64.c
+++ b/sysdeps/unix/sysv/linux/fstatat64.c
@@ -102,7 +102,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf,
 # endif
 #endif
 
-  return INTERNAL_SYSCALL_ERROR_P (r)
+  return syscall_error (r)
 	 ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
 	 : 0;
 }
diff --git a/sysdeps/unix/sysv/linux/generic/dl-origin.c b/sysdeps/unix/sysv/linux/generic/dl-origin.c
index 1ab02bbf10..f90b59b1ef 100644
--- a/sysdeps/unix/sysv/linux/generic/dl-origin.c
+++ b/sysdeps/unix/sysv/linux/generic/dl-origin.c
@@ -41,7 +41,7 @@ _dl_get_origin (void)
 
   len = INTERNAL_SYSCALL_CALL (readlinkat, AT_FDCWD, "/proc/self/exe",
 			       linkval, sizeof (linkval));
-  if (! INTERNAL_SYSCALL_ERROR_P (len) && len > 0 && linkval[0] != '[')
+  if (! syscall_error (len) && len > 0 && linkval[0] != '[')
     {
       /* We can use this value.  */
       assert (linkval[0] == '/');
diff --git a/sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c b/sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c
index eae0a7fe31..541c05fcf4 100644
--- a/sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c
+++ b/sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c
@@ -35,7 +35,7 @@
 	   that we are jumping *out* of the alternate stack. Note that	\
 	   the check for that is the same as that for _STACK_GROWS_UP	\
 	   as for _STACK_GROWS_DOWN.  */				\
-        if (!INTERNAL_SYSCALL_ERROR_P (result)				\
+        if (!syscall_error (result)					\
             && ((oss.ss_flags & SS_ONSTACK) == 0			\
                 || ((unsigned long) oss.ss_sp + oss.ss_size		\
                     - (unsigned long) (sp)) < oss.ss_size))		\
diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c
index 35a20ca0fd..52fcd9761b 100644
--- a/sysdeps/unix/sysv/linux/libc_fatal.c
+++ b/sysdeps/unix/sysv/linux/libc_fatal.c
@@ -25,7 +25,7 @@ writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
   ssize_t cnt;
   do
     cnt = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov);
-  while (INTERNAL_SYSCALL_ERROR_P (cnt) && cnt == -EINTR);
+  while (syscall_error (cnt) && cnt == -EINTR);
   return cnt == total;
 }
 #define WRITEV_FOR_FATAL	writev_for_fatal
diff --git a/sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c b/sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c
index 1e9c5259ab..7a3ed27a5c 100644
--- a/sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c
+++ b/sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c
@@ -26,7 +26,7 @@
       {									      \
 	stack_t oss;							      \
 	int result = INTERNAL_SYSCALL_CALL (sigaltstack, NULL, &oss);         \
-	if (!INTERNAL_SYSCALL_ERROR_P (result)				      \
+	if (!syscall_error (result)					      \
 	    && ((oss.ss_flags & SS_ONSTACK) == 0			      \
 		|| ((unsigned long) oss.ss_sp + oss.ss_size		      \
 		    - (unsigned long) (sp)) < oss.ss_size))		      \
diff --git a/sysdeps/unix/sysv/linux/m68k/getpagesize.c b/sysdeps/unix/sysv/linux/m68k/getpagesize.c
index 99c83313d2..99ab5772b3 100644
--- a/sysdeps/unix/sysv/linux/m68k/getpagesize.c
+++ b/sysdeps/unix/sysv/linux/m68k/getpagesize.c
@@ -35,7 +35,7 @@ __getpagesize (void)
 
   result = INTERNAL_SYSCALL_CALL (getpagesize);
   /* The only possible error is ENOSYS.  */
-  if (!INTERNAL_SYSCALL_ERROR_P (result))
+  if (!syscall_error (result))
     return result;
 
   return 4096;
diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c
index ed7858dc9d..4964eb9028 100644
--- a/sysdeps/unix/sysv/linux/mq_unlink.c
+++ b/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -30,7 +30,7 @@ mq_unlink (const char *name)
 
   /* While unlink can return either EPERM or EACCES, mq_unlink should
      return just EACCES.  */
-  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret)))
+  if (__glibc_unlikely (syscall_error (ret)))
     {
       if (ret == -EPERM)
 	ret = -EACCES;
diff --git a/sysdeps/unix/sysv/linux/not-errno.h b/sysdeps/unix/sysv/linux/not-errno.h
index fc0eda09d9..07330a83ca 100644
--- a/sysdeps/unix/sysv/linux/not-errno.h
+++ b/sysdeps/unix/sysv/linux/not-errno.h
@@ -25,23 +25,15 @@
 static inline int
 __access_noerrno (const char *pathname, int mode)
 {
-  int res;
 #ifdef __NR_access
-  res = INTERNAL_SYSCALL_CALL (access, pathname, mode);
+  return -INTERNAL_SYSCALL_CALL (access, pathname, mode);
 #else
-  res = INTERNAL_SYSCALL_CALL (faccessat, AT_FDCWD, pathname, mode);
+  return -INTERNAL_SYSCALL_CALL (faccessat, AT_FDCWD, pathname, mode);
 #endif
-  if (INTERNAL_SYSCALL_ERROR_P (res))
-    return -res;
-  return 0;
 }
 
 static inline int
 __kill_noerrno (pid_t pid, int sig)
 {
-  int res;
-  res = INTERNAL_SYSCALL_CALL (kill, pid, sig);
-  if (INTERNAL_SYSCALL_ERROR_P (res))
-    return -res;
-  return 0;
+  return -INTERNAL_SYSCALL_CALL (kill, pid, sig);
 }
diff --git a/sysdeps/unix/sysv/linux/nscd_setup_thread.c b/sysdeps/unix/sysv/linux/nscd_setup_thread.c
index 2ba64ebea5..fe70da0b5e 100644
--- a/sysdeps/unix/sysv/linux/nscd_setup_thread.c
+++ b/sysdeps/unix/sysv/linux/nscd_setup_thread.c
@@ -36,7 +36,7 @@ setup_thread (struct database_dyn *db)
      since none of the threads ever terminates.  */
   int r = INTERNAL_SYSCALL_CALL (set_tid_address,
 				 &db->head->nscd_certainly_running);
-  if (!INTERNAL_SYSCALL_ERROR_P (r))
+  if (!syscall_error (r))
     /* We know the kernel can reset this field when nscd terminates.
        So, set the field to a nonzero value which indicates that nscd
        is certainly running and clients can skip the test.  */
diff --git a/sysdeps/unix/sysv/linux/posix_fadvise.c b/sysdeps/unix/sysv/linux/posix_fadvise.c
index 1191ab3db5..3d6bf4b972 100644
--- a/sysdeps/unix/sysv/linux/posix_fadvise.c
+++ b/sysdeps/unix/sysv/linux/posix_fadvise.c
@@ -42,24 +42,23 @@ int
 posix_fadvise (int fd, off_t offset, off_t len, int advise)
 {
 # if defined (__NR_fadvise64) && !defined (__ASSUME_FADVISE64_AS_64_64)
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64, fd,
-				   __ALIGNMENT_ARG SYSCALL_LL (offset),
-				   len, advise);
+  return -INTERNAL_SYSCALL_CALL (fadvise64, fd,
+				 __ALIGNMENT_ARG SYSCALL_LL (offset),
+				 len, advise);
 # else
 #  ifdef __ASSUME_FADVISE64_64_6ARG
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, fd, advise,
-				   SYSCALL_LL (offset), SYSCALL_LL (len));
+  return -INTERNAL_SYSCALL_CALL (fadvise64_64, fd, advise,
+				 SYSCALL_LL (offset), SYSCALL_LL (len));
 #  else
 
 #   ifndef __NR_fadvise64_64
 #    define __NR_fadvise64_64 __NR_fadvise64
 #   endif
 
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, fd,
-				   __ALIGNMENT_ARG SYSCALL_LL (offset),
-				   SYSCALL_LL (len), advise);
+  return -INTERNAL_SYSCALL_CALL (fadvise64_64, fd,
+				 __ALIGNMENT_ARG SYSCALL_LL (offset),
+				 SYSCALL_LL (len), advise);
 #  endif
 # endif
-  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
 }
 #endif /* __OFF_T_MATCHES_OFF64_T  */
diff --git a/sysdeps/unix/sysv/linux/posix_fadvise64.c b/sysdeps/unix/sysv/linux/posix_fadvise64.c
index e3726a6a8a..6ef425cf22 100644
--- a/sysdeps/unix/sysv/linux/posix_fadvise64.c
+++ b/sysdeps/unix/sysv/linux/posix_fadvise64.c
@@ -41,14 +41,13 @@ int
 __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
 {
 #ifdef __ASSUME_FADVISE64_64_6ARG
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, fd, advise,
-				   SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
+  return -INTERNAL_SYSCALL_CALL (fadvise64_64, fd, advise,
+				 SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
 #else
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, fd,
-				   __ALIGNMENT_ARG SYSCALL_LL64 (offset),
-				   SYSCALL_LL64 (len), advise);
+  return -INTERNAL_SYSCALL_CALL (fadvise64_64, fd,
+				 __ALIGNMENT_ARG SYSCALL_LL64 (offset),
+				 SYSCALL_LL64 (len), advise);
 #endif
-  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
 }
 
 /* The type of the len argument was changed from size_t to off_t in
diff --git a/sysdeps/unix/sysv/linux/posix_fallocate.c b/sysdeps/unix/sysv/linux/posix_fallocate.c
index 87532668cd..3c8f7cafeb 100644
--- a/sysdeps/unix/sysv/linux/posix_fallocate.c
+++ b/sysdeps/unix/sysv/linux/posix_fallocate.c
@@ -28,9 +28,7 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
 {
   int res = INTERNAL_SYSCALL_CALL (fallocate, fd, 0,
 				   SYSCALL_LL (offset), SYSCALL_LL (len));
-  if (! INTERNAL_SYSCALL_ERROR_P (res))
-    return 0;
-  if (res != -EOPNOTSUPP)
+  if (! syscall_error (res) || -res != EOPNOTSUPP)
     return -res;
   return internal_fallocate (fd, offset, len);
 }
diff --git a/sysdeps/unix/sysv/linux/posix_fallocate64.c b/sysdeps/unix/sysv/linux/posix_fallocate64.c
index 0340357e57..910f83384c 100644
--- a/sysdeps/unix/sysv/linux/posix_fallocate64.c
+++ b/sysdeps/unix/sysv/linux/posix_fallocate64.c
@@ -30,9 +30,7 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
 {
   int res = INTERNAL_SYSCALL_CALL (fallocate, fd, 0,
 				   SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
-  if (! INTERNAL_SYSCALL_ERROR_P (res))
-    return 0;
-  if (-res != EOPNOTSUPP)
+  if (! syscall_error (res) || -res != EOPNOTSUPP)
     return -res;
   return internal_fallocate64 (fd, offset, len);
 }
diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c
index defdeaecac..525383f960 100644
--- a/sysdeps/unix/sysv/linux/pthread_kill.c
+++ b/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -50,7 +50,6 @@ __pthread_kill (pthread_t threadid, int signo)
   /* We have a special syscall to do the work.  */
   pid_t pid = __getpid ();
 
-  int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo);
-  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
+  return -INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo);
 }
 strong_alias (__pthread_kill, pthread_kill)
diff --git a/sysdeps/unix/sysv/linux/pthread_sigqueue.c b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
index fbbd9fee20..814f449b63 100644
--- a/sysdeps/unix/sysv/linux/pthread_sigqueue.c
+++ b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
@@ -61,9 +61,7 @@ pthread_sigqueue (pthread_t threadid, int signo, const union sigval value)
   info.si_value = value;
 
   /* We have a special syscall to do the work.  */
-  int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo,
-				   &info);
-  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
+  return -INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo, &info);
 #else
   return ENOSYS;
 #endif
diff --git a/sysdeps/unix/sysv/linux/riscv/syscall.c b/sysdeps/unix/sysv/linux/riscv/syscall.c
index a99375c054..4ebb759b72 100644
--- a/sysdeps/unix/sysv/linux/riscv/syscall.c
+++ b/sysdeps/unix/sysv/linux/riscv/syscall.c
@@ -27,7 +27,7 @@ syscall (long int syscall_number, long int arg1, long int arg2, long int arg3,
   ret = INTERNAL_SYSCALL_NCS (syscall_number, 7, arg1, arg2, arg3, arg4,
 			      arg5, arg6, arg7);
 
-  if (INTERNAL_SYSCALL_ERROR_P (ret))
+  if (syscall_error (ret))
     return __syscall_error (ret);
 
   return ret;
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/____longjmp_chk.c b/sysdeps/unix/sysv/linux/s390/s390-32/____longjmp_chk.c
index 1f214173fe..7cb3a69e90 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/____longjmp_chk.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/____longjmp_chk.c
@@ -40,7 +40,7 @@
 	{								\
 	  stack_t oss;							\
 	  int res = INTERNAL_SYSCALL_CALL (sigaltstack, NULL, &oss);	\
-	  if (!INTERNAL_SYSCALL_ERROR_P (res))				\
+	  if (!syscall_error (res))					\
 	    {								\
 	      if ((oss.ss_flags & SS_ONSTACK) == 0			\
 		  || ((uintptr_t) (oss.ss_sp + oss.ss_size) - new_sp	\
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
index 6199589307..75c1318d83 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
@@ -42,8 +42,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
   parameters.offset = offset;
   parameters.len = len;
   parameters.advise = advise;
-  int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, &parameters);
-  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
+  return -INTERNAL_SYSCALL_CALL (fadvise64_64, &parameters);
 }
 
 #include <shlib-compat.h>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/____longjmp_chk.c b/sysdeps/unix/sysv/linux/s390/s390-64/____longjmp_chk.c
index bc74408135..84c6d13655 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/____longjmp_chk.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/____longjmp_chk.c
@@ -40,7 +40,7 @@
 	{								\
 	  stack_t oss;							\
 	  int res = INTERNAL_SYSCALL_CALL (sigaltstack, NULL, &oss);	\
-	  if (!INTERNAL_SYSCALL_ERROR_P (res))				\
+	  if (!syscall_error (res))					\
 	    {								\
 	      if ((oss.ss_flags & SS_ONSTACK) == 0			\
 		  || ((uintptr_t) (oss.ss_sp + oss.ss_size) - new_sp	\
diff --git a/sysdeps/unix/sysv/linux/shmat.c b/sysdeps/unix/sysv/linux/shmat.c
index d5a65c06c1..98291fe972 100644
--- a/sysdeps/unix/sysv/linux/shmat.c
+++ b/sysdeps/unix/sysv/linux/shmat.c
@@ -35,7 +35,7 @@ shmat (int shmid, const void *shmaddr, int shmflg)
 
   resultvar = INTERNAL_SYSCALL_CALL (ipc, IPCOP_shmat, shmid, shmflg,
 				     &raddr, shmaddr);
-  if (INTERNAL_SYSCALL_ERROR_P (resultvar))
+  if (syscall_error (resultvar))
     return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (-resultvar);
 
   return raddr;
diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index 88db076184..7c578808c6 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -36,14 +36,14 @@
     if (vdsop != NULL)							      \
       {									      \
 	sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
-	if (!INTERNAL_SYSCALL_ERROR_P (sc_ret))			      	      \
+	if (!syscall_error (sc_ret))					      \
 	  goto out;							      \
 	if (sc_ret != -ENOSYS)		      	      			      \
 	  goto iserr;							      \
       }									      \
 									      \
     sc_ret = INTERNAL_SYSCALL_CALL (name, ##args);		      	      \
-    if (INTERNAL_SYSCALL_ERROR_P (sc_ret))			      	      \
+    if (syscall_error (sc_ret))					      	      \
       {									      \
       iserr:								      \
         __set_errno (-sc_ret);		      	      			      \
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 4e25e51470..3fa29dd588 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -22,9 +22,13 @@
 #include <kernel-features.h>
 #include <errno.h>
 
-#undef INTERNAL_SYSCALL_ERROR_P
-#define INTERNAL_SYSCALL_ERROR_P(val) \
-  ((unsigned long int) (val) > -4096UL)
+#ifndef __ASSEMBLER__
+static inline _Bool
+syscall_error (unsigned long int val)
+{
+  return val > -4096UL;
+}
+#endif
 
 #ifndef SYSCALL_ERROR_LABEL
 # define SYSCALL_ERROR_LABEL(sc_err)					\
@@ -34,6 +38,7 @@
   })
 #endif
 
+#ifndef __ASSEMBLER__
 /* Define a macro which expands into the inline wrapper code for a system
    call.  It sets the errno and returns -1 on a failure, or the syscall
    return value otherwise.  */
@@ -41,10 +46,11 @@
 #define INLINE_SYSCALL(name, nr, args...)				\
   ({									\
     long int sc_ret = INTERNAL_SYSCALL (name, nr, args);		\
-    __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (sc_ret))		\
+    __glibc_unlikely (syscall_error (sc_ret))				\
     ? SYSCALL_ERROR_LABEL (-sc_ret)					\
     : sc_ret;								\
   })
+#endif
 
 /* Set error number and return -1.  A target may choose to return the
    internal function, __syscall_error, which sets errno and returns -1.
diff --git a/sysdeps/unix/sysv/linux/timer_create.c b/sysdeps/unix/sysv/linux/timer_create.c
index d8289d1dc7..1f5f2b95da 100644
--- a/sysdeps/unix/sysv/linux/timer_create.c
+++ b/sysdeps/unix/sysv/linux/timer_create.c
@@ -124,7 +124,7 @@ timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid)
 	int res;
 	res = INTERNAL_SYSCALL_CALL (timer_create, syscall_clockid, &sev,
 				     &newp->ktimerid);
-	if (INTERNAL_SYSCALL_ERROR_P (res))
+	if (syscall_error (res))
 	  {
 	    free (newp);
 	    __set_errno (-res);
diff --git a/sysdeps/unix/sysv/linux/times.c b/sysdeps/unix/sysv/linux/times.c
index b5eb6404c9..0b47979bfd 100644
--- a/sysdeps/unix/sysv/linux/times.c
+++ b/sysdeps/unix/sysv/linux/times.c
@@ -19,12 +19,15 @@
 #include <sys/times.h>
 #include <sysdep.h>
 
+#ifndef SYSCALL_ERROR
+# define SYSCALL_ERROR(__val) syscall_error(__val)
+#endif
 
 clock_t
 __times (struct tms *buf)
 {
   clock_t ret = INTERNAL_SYSCALL_CALL (times, buf);
-  if (INTERNAL_SYSCALL_ERROR_P (ret)
+  if (syscall_error (ret)
       && __glibc_unlikely (ret == -EFAULT)
       && buf)
     {
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/times.c b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
index 864c123117..f540447b0a 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/times.c
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
@@ -33,8 +33,11 @@
     (long long int) resultvar;						\
 })
 
-#undef INTERNAL_SYSCALL_ERROR_P
-#define INTERNAL_SYSCALL_ERROR_P(val) \
-  ((unsigned long long int) (val) >= -4095LL)
+static inline _Bool
+syscall_error_u64 (unsigned long long int val)
+{
+  return val > -4096ULL;
+}
+#define SYSCALL_ERROR(__val) syscall_error_u64 (__val)
 
 #include <sysdeps/unix/sysv/linux/times.c>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 03/23] Remove tls.h inclusion from internal errno.h
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-10 10:45   ` Florian Weimer
  2020-11-09 20:18 ` [PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL Adhemerval Zanella
                   ` (19 subsequent siblings)
  22 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The tls.h inclusion is not really required and limits possible
definition on more arch specific headers.

This is a cleanup to allow inline functions on sysdep.h, more
specifically on i386 and ia64 which requires to access some tls
definitions its own.

No semantic changes expected, checked with a build against all
affected ABIs.
---
 include/errno.h                                        |  2 --
 io/lchmod.c                                            |  4 +---
 malloc/reallocarray.c                                  |  1 +
 misc/ustat.c                                           |  1 +
 nss/nss_fgetent_r.c                                    |  1 +
 posix/execl.c                                          |  1 +
 posix/execle.c                                         |  1 +
 posix/execlp.c                                         |  1 +
 posix/spawn_faction_addchdir.c                         |  2 +-
 pwd/putpwent.c                                         |  1 +
 signal/sigempty.c                                      |  1 +
 signal/sigismem.c                                      |  1 +
 sysdeps/generic/internal-signals.h                     |  1 +
 sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c                 |  3 ---
 sysdeps/mach/hurd/mmap64.c                             |  1 +
 sysdeps/mach/hurd/waitid.c                             |  1 +
 sysdeps/microblaze/backtrace.c                         |  1 +
 sysdeps/nptl/futex-internal.h                          |  1 +
 sysdeps/unix/sysv/linux/adjtime.c                      |  1 +
 sysdeps/unix/sysv/linux/clock_getcpuclockid.c          |  1 +
 sysdeps/unix/sysv/linux/faccessat.c                    |  6 +-----
 sysdeps/unix/sysv/linux/ftime.c                        |  1 +
 sysdeps/unix/sysv/linux/ftruncate64.c                  |  1 -
 sysdeps/unix/sysv/linux/generic/chmod.c                |  4 +---
 sysdeps/unix/sysv/linux/generic/chown.c                |  4 +---
 sysdeps/unix/sysv/linux/generic/dup2.c                 |  3 +--
 sysdeps/unix/sysv/linux/generic/epoll_create.c         |  5 +----
 sysdeps/unix/sysv/linux/generic/inotify_init.c         |  5 +----
 sysdeps/unix/sysv/linux/generic/lchown.c               |  4 +---
 sysdeps/unix/sysv/linux/generic/link.c                 |  3 +--
 sysdeps/unix/sysv/linux/generic/pipe.c                 |  3 +--
 sysdeps/unix/sysv/linux/generic/readlink.c             |  2 +-
 sysdeps/unix/sysv/linux/generic/rmdir.c                |  4 +---
 sysdeps/unix/sysv/linux/generic/symlink.c              |  3 +--
 sysdeps/unix/sysv/linux/generic/unlink.c               |  4 +---
 sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c  |  2 +-
 sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h |  1 +
 sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c |  2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c   |  2 +-
 sysdeps/unix/sysv/linux/getentropy.c                   |  1 +
 sysdeps/unix/sysv/linux/getrlimit.c                    |  3 +--
 sysdeps/unix/sysv/linux/getrlimit64.c                  |  1 +
 sysdeps/unix/sysv/linux/gettimeofday.c                 |  7 ++++---
 sysdeps/unix/sysv/linux/hppa/sysdep.h                  |  2 ++
 sysdeps/unix/sysv/linux/internal-signals.h             |  1 +
 sysdeps/unix/sysv/linux/libc_fatal.c                   |  2 ++
 sysdeps/unix/sysv/linux/microblaze/sysdep.h            |  2 ++
 sysdeps/unix/sysv/linux/mknodat.c                      |  1 +
 sysdeps/unix/sysv/linux/netlink_assert_response.c      |  1 +
 sysdeps/unix/sysv/linux/posix_fadvise64.c              |  1 +
 sysdeps/unix/sysv/linux/prlimit.c                      |  4 +---
 sysdeps/unix/sysv/linux/readahead.c                    |  2 +-
 sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c          |  2 +-
 sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c         |  2 +-
 sysdeps/unix/sysv/linux/semop.c                        |  2 +-
 sysdeps/unix/sysv/linux/setrlimit.c                    |  3 +--
 sysdeps/unix/sysv/linux/setrlimit64.c                  |  1 +
 sysdeps/unix/sysv/linux/settimezone.c                  |  1 +
 sysdeps/unix/sysv/linux/shmget.c                       |  3 ++-
 sysdeps/unix/sysv/linux/socketcall.h                   |  2 ++
 sysdeps/unix/sysv/linux/speed.c                        |  2 +-
 sysdeps/unix/sysv/linux/statx.c                        |  2 +-
 sysdeps/unix/sysv/linux/sysctl.c                       |  1 +
 sysdeps/unix/sysv/linux/sysdep.h                       |  1 +
 sysdeps/unix/sysv/linux/truncate64.c                   |  1 -
 sysdeps/unix/sysv/linux/ustat.c                        |  2 +-
 sysdeps/unix/sysv/linux/xmknod.c                       |  1 +
 sysdeps/unix/sysv/linux/xmknodat.c                     |  1 +
 sysdeps/unix/sysv/linux/xstatconv.c                    |  1 +
 sysdeps/x86_64/stackinfo.h                             | 10 ++++++++--
 70 files changed, 82 insertions(+), 70 deletions(-)

diff --git a/include/errno.h b/include/errno.h
index 457114b27a..c361a785c2 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -22,8 +22,6 @@ extern int rtld_errno attribute_hidden;
 
 # elif IS_IN_LIB && !IS_IN (rtld)
 
-#  include <tls.h>
-
 #  undef  errno
 #  if IS_IN (libc)
 #   define errno __libc_errno
diff --git a/io/lchmod.c b/io/lchmod.c
index 8b788034ee..3a0f714576 100644
--- a/io/lchmod.c
+++ b/io/lchmod.c
@@ -16,10 +16,8 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <fcntl.h>
-#include <sys/types.h>
-#include <unistd.h>
+#include <sys/stat.h>
 
 /* Change the protections of FILE to MODE.  */
 int
diff --git a/malloc/reallocarray.c b/malloc/reallocarray.c
index aca689e2c5..20b0215220 100644
--- a/malloc/reallocarray.c
+++ b/malloc/reallocarray.c
@@ -17,6 +17,7 @@
    not, see <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <stdlib.h>
 #include <malloc.h>
 
 void *
diff --git a/misc/ustat.c b/misc/ustat.c
index a1b057f640..ad75c5c1bf 100644
--- a/misc/ustat.c
+++ b/misc/ustat.c
@@ -23,6 +23,7 @@
 
 # include <unistd.h>
 # include <errno.h>
+# include <sys/types.h>
 
 struct ustat
  {
diff --git a/nss/nss_fgetent_r.c b/nss/nss_fgetent_r.c
index 8f7c5b5cc7..7fecde7e8f 100644
--- a/nss/nss_fgetent_r.c
+++ b/nss/nss_fgetent_r.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <nss_files.h>
+#include <stdbool.h>
 
 int
 __nss_fgetent_r (FILE *fp, void *result, char *buffer, size_t buffer_length,
diff --git a/posix/execl.c b/posix/execl.c
index 8d319a4528..61aef66126 100644
--- a/posix/execl.c
+++ b/posix/execl.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <sys/param.h>
+#include <stddef.h>
 
 /* Execute PATH with all arguments after PATH until
    a NULL pointer and environment from `environ'.  */
diff --git a/posix/execle.c b/posix/execle.c
index 7539ce6b8d..f6608ee112 100644
--- a/posix/execle.c
+++ b/posix/execle.c
@@ -19,6 +19,7 @@
 #include <stdarg.h>
 #include <errno.h>
 #include <sys/param.h>
+#include <stddef.h>
 
 /* Execute PATH with all arguments after PATH until a NULL pointer,
    and the argument after that for environment.  */
diff --git a/posix/execlp.c b/posix/execlp.c
index 9eaca5fd25..4761962176 100644
--- a/posix/execlp.c
+++ b/posix/execlp.c
@@ -19,6 +19,7 @@
 #include <stdarg.h>
 #include <errno.h>
 #include <sys/param.h>
+#include <stddef.h>
 
 /* Execute FILE, searching in the `PATH' environment variable if
    it contains no slashes, with all arguments after FILE until a
diff --git a/posix/spawn_faction_addchdir.c b/posix/spawn_faction_addchdir.c
index 6558628547..20a3ba92ab 100644
--- a/posix/spawn_faction_addchdir.c
+++ b/posix/spawn_faction_addchdir.c
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <spawn.h>
 #include <string.h>
-
+#include <stdlib.h>
 #include "spawn_int.h"
 
 int
diff --git a/pwd/putpwent.c b/pwd/putpwent.c
index a6673acbf2..baf312a6fe 100644
--- a/pwd/putpwent.c
+++ b/pwd/putpwent.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <pwd.h>
+#include <stdlib.h>
 #include <nss.h>
 
 #define _S(x)	x ?: ""
diff --git a/signal/sigempty.c b/signal/sigempty.c
index 31b1145027..01848c82d5 100644
--- a/signal/sigempty.c
+++ b/signal/sigempty.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <sigsetops.h>
+#include <stddef.h>
 
 /* Clear all signals from SET.  */
 int
diff --git a/signal/sigismem.c b/signal/sigismem.c
index 728d58f7a3..c788ca83b1 100644
--- a/signal/sigismem.c
+++ b/signal/sigismem.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <signal.h>
+#include <stddef.h>
 #include <sigsetops.h>
 
 /* Return 1 if SIGNO is in SET, 0 if not.  */
diff --git a/sysdeps/generic/internal-signals.h b/sysdeps/generic/internal-signals.h
index 73a0c29d82..cd675e4fd4 100644
--- a/sysdeps/generic/internal-signals.h
+++ b/sysdeps/generic/internal-signals.h
@@ -22,6 +22,7 @@
 #include <signal.h>
 #include <sigsetops.h>
 #include <stdbool.h>
+#include <stddef.h>
 
 static inline bool
 __is_internal_signal (int sig)
diff --git a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
index f77253e520..6ced407e26 100644
--- a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
@@ -20,9 +20,6 @@
 #include <float.h>
 #include <math.h>
 
-/* Need to set this when including gmp headers after system headers.  */
-#define HAVE_ALLOCA 1
-
 #include "gmp.h"
 #include "gmp-impl.h"
 
diff --git a/sysdeps/mach/hurd/mmap64.c b/sysdeps/mach/hurd/mmap64.c
index 6d8566b5b1..23d7ca7f34 100644
--- a/sysdeps/mach/hurd/mmap64.c
+++ b/sysdeps/mach/hurd/mmap64.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 #include <sys/types.h>
+#include <mach/port.h>
 
 /* Map addresses starting near ADDR and extending for LEN bytes.  From
    OFFSET into the file FD describes according to PROT and FLAGS.  If ADDR
diff --git a/sysdeps/mach/hurd/waitid.c b/sysdeps/mach/hurd/waitid.c
index dce72339dd..044a1dd8e3 100644
--- a/sysdeps/mach/hurd/waitid.c
+++ b/sysdeps/mach/hurd/waitid.c
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <sys/wait.h>
+#include <stddef.h>
 
 int
 __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
diff --git a/sysdeps/microblaze/backtrace.c b/sysdeps/microblaze/backtrace.c
index 8af5a4d7f5..f4a4b69df5 100644
--- a/sysdeps/microblaze/backtrace.c
+++ b/sysdeps/microblaze/backtrace.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sysdep.h>
 #include <signal.h>
diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
index cd356e4fa8..c27d0cdac8 100644
--- a/sysdeps/nptl/futex-internal.h
+++ b/sysdeps/nptl/futex-internal.h
@@ -23,6 +23,7 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <lowlevellock-futex.h>
 #include <libc-diag.h>
 
 /* This file defines futex operations used internally in glibc.  A futex
diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
index 6d1d1b6af2..8e7c8cc5da 100644
--- a/sysdeps/unix/sysv/linux/adjtime.c
+++ b/sysdeps/unix/sysv/linux/adjtime.c
@@ -19,6 +19,7 @@
 #include <limits.h>
 #include <sys/time.h>
 #include <sys/timex.h>
+#include <sysdep.h>
 
 #define MAX_SEC	(INT_MAX / 1000000L - 2)
 #define MIN_SEC	(INT_MIN / 1000000L + 2)
diff --git a/sysdeps/unix/sysv/linux/clock_getcpuclockid.c b/sysdeps/unix/sysv/linux/clock_getcpuclockid.c
index 7d2e6d6bfe..1eb780a164 100644
--- a/sysdeps/unix/sysv/linux/clock_getcpuclockid.c
+++ b/sysdeps/unix/sysv/linux/clock_getcpuclockid.c
@@ -20,6 +20,7 @@
 #include <time.h>
 #include <unistd.h>
 #include "kernel-posix-cpu-timers.h"
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 int
diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c
index b697053da1..5d078371b5 100644
--- a/sysdeps/unix/sysv/linux/faccessat.c
+++ b/sysdeps/unix/sysv/linux/faccessat.c
@@ -16,14 +16,10 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <fcntl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <alloca.h>
+#include <sys/stat.h>
 #include <sysdep.h>
 
 
diff --git a/sysdeps/unix/sysv/linux/ftime.c b/sysdeps/unix/sysv/linux/ftime.c
index 1755fcf967..2f43b7650d 100644
--- a/sysdeps/unix/sysv/linux/ftime.c
+++ b/sysdeps/unix/sysv/linux/ftime.c
@@ -18,6 +18,7 @@
 
 #include <features.h>
 #include <sys/timeb.h>
+#include <time.h>
 #include <errno.h>
 
 int
diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
index 606a0e86e0..3d43a5a90f 100644
--- a/sysdeps/unix/sysv/linux/ftruncate64.c
+++ b/sysdeps/unix/sysv/linux/ftruncate64.c
@@ -17,7 +17,6 @@
 
 #include <unistd.h>
 #include <sysdep.h>
-#include <errno.h>
 
 #ifndef __NR_ftruncate64
 # define __NR_ftruncate64 __NR_ftruncate
diff --git a/sysdeps/unix/sysv/linux/generic/chmod.c b/sysdeps/unix/sysv/linux/generic/chmod.c
index b9631a9103..802e4006ee 100644
--- a/sysdeps/unix/sysv/linux/generic/chmod.c
+++ b/sysdeps/unix/sysv/linux/generic/chmod.c
@@ -16,11 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <fcntl.h>
-#include <sys/stat.h>
 #include <sys/types.h>
+#include <sysdep.h>
 
 /* Change the protections of FILE to MODE.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/chown.c b/sysdeps/unix/sysv/linux/generic/chown.c
index d676eefab4..57a81834db 100644
--- a/sysdeps/unix/sysv/linux/generic/chown.c
+++ b/sysdeps/unix/sysv/linux/generic/chown.c
@@ -16,11 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/types.h>
+#include <sysdep.h>
 
 /* Change the owner and group of FILE.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/dup2.c b/sysdeps/unix/sysv/linux/generic/dup2.c
index 32592f9450..dfa348b375 100644
--- a/sysdeps/unix/sysv/linux/generic/dup2.c
+++ b/sysdeps/unix/sysv/linux/generic/dup2.c
@@ -16,10 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <fcntl.h>
-#include <limits.h>
 #include <unistd.h>
+#include <sysdep.h>
 
 /* Duplicate FD to FD2, closing the old FD2 and making FD2 be
    open the same file as FD is.  Return FD2 or -1.  */
diff --git a/sysdeps/unix/sysv/linux/generic/epoll_create.c b/sysdeps/unix/sysv/linux/generic/epoll_create.c
index e3eac4a7ac..1715c6d9bf 100644
--- a/sysdeps/unix/sysv/linux/generic/epoll_create.c
+++ b/sysdeps/unix/sysv/linux/generic/epoll_create.c
@@ -16,11 +16,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <stddef.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <sys/epoll.h>
+#include <sysdep.h>
 
 libc_hidden_proto (epoll_create)
 
diff --git a/sysdeps/unix/sysv/linux/generic/inotify_init.c b/sysdeps/unix/sysv/linux/generic/inotify_init.c
index 7f84124850..25a323f7e7 100644
--- a/sysdeps/unix/sysv/linux/generic/inotify_init.c
+++ b/sysdeps/unix/sysv/linux/generic/inotify_init.c
@@ -16,11 +16,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <stddef.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <sys/inotify.h>
+#include <sysdep.h>
 
 libc_hidden_proto (inotify_init)
 
diff --git a/sysdeps/unix/sysv/linux/generic/lchown.c b/sysdeps/unix/sysv/linux/generic/lchown.c
index a483241fd3..379079e8ca 100644
--- a/sysdeps/unix/sysv/linux/generic/lchown.c
+++ b/sysdeps/unix/sysv/linux/generic/lchown.c
@@ -16,11 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/types.h>
+#include <sysdep.h>
 
 /* Change the owner and group of FILE.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/link.c b/sysdeps/unix/sysv/linux/generic/link.c
index a038ba1408..1baa6b5e6a 100644
--- a/sysdeps/unix/sysv/linux/generic/link.c
+++ b/sysdeps/unix/sysv/linux/generic/link.c
@@ -16,10 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sysdep.h>
 
 /* Make a link to FROM called TO.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/pipe.c b/sysdeps/unix/sysv/linux/generic/pipe.c
index 5d4a95f3e7..52f3231cb8 100644
--- a/sysdeps/unix/sysv/linux/generic/pipe.c
+++ b/sysdeps/unix/sysv/linux/generic/pipe.c
@@ -16,9 +16,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <unistd.h>
-#include <stddef.h>
+#include <sysdep.h>
 
 /* Create a one-way communication channel (__pipe).
    If successful, two file descriptors are stored in PIPEDES;
diff --git a/sysdeps/unix/sysv/linux/generic/readlink.c b/sysdeps/unix/sysv/linux/generic/readlink.c
index 721f84e3dd..6f690a9750 100644
--- a/sysdeps/unix/sysv/linux/generic/readlink.c
+++ b/sysdeps/unix/sysv/linux/generic/readlink.c
@@ -16,9 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sysdep.h>
 
 /* Read the contents of the symbolic link PATH into no more than
    LEN bytes of BUF.  The contents are not null-terminated.
diff --git a/sysdeps/unix/sysv/linux/generic/rmdir.c b/sysdeps/unix/sysv/linux/generic/rmdir.c
index e357a10e8d..f9d721f3db 100644
--- a/sysdeps/unix/sysv/linux/generic/rmdir.c
+++ b/sysdeps/unix/sysv/linux/generic/rmdir.c
@@ -16,11 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
-
+#include <sysdep.h>
 
 /* Remove the directory PATH.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/symlink.c b/sysdeps/unix/sysv/linux/generic/symlink.c
index cddc11acf0..2c358f54c9 100644
--- a/sysdeps/unix/sysv/linux/generic/symlink.c
+++ b/sysdeps/unix/sysv/linux/generic/symlink.c
@@ -16,10 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sysdep.h>
 
 /* Make a link to FROM called TO.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/unlink.c b/sysdeps/unix/sysv/linux/generic/unlink.c
index 7908d0a576..8df55753a0 100644
--- a/sysdeps/unix/sysv/linux/generic/unlink.c
+++ b/sysdeps/unix/sysv/linux/generic/unlink.c
@@ -16,11 +16,9 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
-
+#include <sysdep.h>
 
 /* Remove the link named NAME.  */
 int
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
index 93d9d94a0a..f80b56b303 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
@@ -16,10 +16,10 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <sys/statfs.h>
 #include <kernel_stat.h>
 #include <stddef.h>
+#include <sysdep.h>
 
 #if !STATFS_IS_STATFS64
 #include "overflow.h"
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
index c5e028625a..e200f6319b 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
@@ -19,6 +19,7 @@
 
 #include <sys/stat.h>
 #include <sys/statfs.h>
+#include <sys/types.h>
 
 /* Test for overflows of structures where we ask the kernel to fill them
    in with standard 64-bit syscalls but return them through APIs that
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c
index c556a37cd4..72e2d49d1a 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c
@@ -17,7 +17,9 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sys/sendfile.h>
+#include <stddef.h>
 #include <errno.h>
+#include <sysdep.h>
 
 /* Send COUNT bytes from file associated with IN_FD starting at OFFSET to
    descriptor OUT_FD.  */
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
index 7421501b4a..4484341075 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <sys/statfs.h>
 #include <kernel_stat.h>
-#include <stddef.h>
+#include <sysdep.h>
 
 #if !STATFS_IS_STATFS64
 #include "overflow.h"
diff --git a/sysdeps/unix/sysv/linux/getentropy.c b/sysdeps/unix/sysv/linux/getentropy.c
index 2f3a4e4692..02cf46ff42 100644
--- a/sysdeps/unix/sysv/linux/getentropy.c
+++ b/sysdeps/unix/sysv/linux/getentropy.c
@@ -20,6 +20,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <unistd.h>
+#include <sysdep.h>
 
 /* Write LENGTH bytes of randomness starting at BUFFER.  Return 0 on
    success and -1 on failure.  */
diff --git a/sysdeps/unix/sysv/linux/getrlimit.c b/sysdeps/unix/sysv/linux/getrlimit.c
index ecb34dd742..339d943bd2 100644
--- a/sysdeps/unix/sysv/linux/getrlimit.c
+++ b/sysdeps/unix/sysv/linux/getrlimit.c
@@ -16,9 +16,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <sys/resource.h>
-#include <sys/types.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 #if !__RLIM_T_MATCHES_RLIM64_T
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 0f9a2f4936..e06ffd1a16 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
index cb57bc9cf2..1c92e6d643 100644
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/gettimeofday.c
@@ -16,15 +16,16 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <time.h>
+#include <string.h>
+
 /* Optimize the function call by setting the PLT directly to vDSO symbol.  */
 #ifdef USE_IFUNC_GETTIMEOFDAY
-# include <time.h>
-# include <string.h>
 # include <sysdep.h>
 # include <sysdep-vdso.h>
 
 # ifdef SHARED
-#  include <dl-vdso.h>
+# include <dl-vdso.h>
 # include <libc-vdso.h>
 
 static int
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.h b/sysdeps/unix/sysv/linux/hppa/sysdep.h
index 7f8da30d23..531fe2beed 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep.h
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep.h
@@ -28,6 +28,8 @@
 /* Defines RTLD_PRIVATE_ERRNO.  */
 #include <dl-sysdep.h>
 
+#include <tls.h>
+
 /* In order to get __set_errno() definition in INLINE_SYSCALL.  */
 #ifndef __ASSEMBLER__
 #include <errno.h>
diff --git a/sysdeps/unix/sysv/linux/internal-signals.h b/sysdeps/unix/sysv/linux/internal-signals.h
index 35f2de04c5..8455ca8de1 100644
--- a/sysdeps/unix/sysv/linux/internal-signals.h
+++ b/sysdeps/unix/sysv/linux/internal-signals.h
@@ -23,6 +23,7 @@
 #include <sigsetops.h>
 #include <stdbool.h>
 #include <limits.h>
+#include <stddef.h>
 #include <sysdep.h>
 
 /* The signal used for asynchronous cancelation.  */
diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c
index 52fcd9761b..486c65e600 100644
--- a/sysdeps/unix/sysv/linux/libc_fatal.c
+++ b/sysdeps/unix/sysv/linux/libc_fatal.c
@@ -18,6 +18,8 @@
 
 #include <errno.h>
 #include <sys/uio.h>
+#include <stdbool.h>
+#include <sysdep.h>
 
 static bool
 writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
index d500172114..6fd96adbf0 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
@@ -26,6 +26,8 @@
 /* Defines RTLD_PRIVATE_ERRNO.  */
 #include <dl-sysdep.h>
 
+#include <tls.h>
+
 /* In order to get __set_errno() definition in INLINE_SYSCALL.  */
 #ifndef __ASSEMBLER__
 # include <errno.h>
diff --git a/sysdeps/unix/sysv/linux/mknodat.c b/sysdeps/unix/sysv/linux/mknodat.c
index fdb8f1951a..279a4404f5 100644
--- a/sysdeps/unix/sysv/linux/mknodat.c
+++ b/sysdeps/unix/sysv/linux/mknodat.c
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <sysdep.h>
 
 int
 __mknodat (int fd, const char *path, mode_t mode, dev_t dev)
diff --git a/sysdeps/unix/sysv/linux/netlink_assert_response.c b/sysdeps/unix/sysv/linux/netlink_assert_response.c
index 5fc0920bb0..5bacf7377f 100644
--- a/sysdeps/unix/sysv/linux/netlink_assert_response.c
+++ b/sysdeps/unix/sysv/linux/netlink_assert_response.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <sys/socket.h>
 
 #include "netlinkaccess.h"
diff --git a/sysdeps/unix/sysv/linux/posix_fadvise64.c b/sysdeps/unix/sysv/linux/posix_fadvise64.c
index 6ef425cf22..4a1fc0225b 100644
--- a/sysdeps/unix/sysv/linux/posix_fadvise64.c
+++ b/sysdeps/unix/sysv/linux/posix_fadvise64.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 int __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise);
diff --git a/sysdeps/unix/sysv/linux/prlimit.c b/sysdeps/unix/sysv/linux/prlimit.c
index aa74a52eb7..e12eb4e9bc 100644
--- a/sysdeps/unix/sysv/linux/prlimit.c
+++ b/sysdeps/unix/sysv/linux/prlimit.c
@@ -15,10 +15,8 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <sys/resource.h>
-#include <sys/syscall.h>
-
+#include <sysdep.h>
 
 int
 prlimit (__pid_t pid, enum __rlimit_resource resource,
diff --git a/sysdeps/unix/sysv/linux/readahead.c b/sysdeps/unix/sysv/linux/readahead.c
index a189c3ac79..ad01a0aed8 100644
--- a/sysdeps/unix/sysv/linux/readahead.c
+++ b/sysdeps/unix/sysv/linux/readahead.c
@@ -17,7 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <fcntl.h>
-#include <errno.h>
+#include <sys/types.h>
 #include <sysdep.h>
 
 ssize_t
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c b/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c
index e4b82512f6..fa4b244728 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c
@@ -19,7 +19,7 @@
 #include <sys/types.h>
 #include <utmp.h>
 #include <errno.h>
-#include <libc-symbols.h>
+#include <stdlib.h>
 
 #include "utmp32.h"
 #include "utmp-convert.h"
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c b/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c
index 3f78fa62db..bdfe396d59 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c
@@ -19,7 +19,7 @@
 #include <sys/types.h>
 #include <utmp.h>
 #include <errno.h>
-#include <libc-symbols.h>
+#include <stdlib.h>
 
 #include "utmp32.h"
 #include "utmp-convert.h"
diff --git a/sysdeps/unix/sysv/linux/semop.c b/sysdeps/unix/sysv/linux/semop.c
index e955f0cd31..ab790ea40f 100644
--- a/sysdeps/unix/sysv/linux/semop.c
+++ b/sysdeps/unix/sysv/linux/semop.c
@@ -17,9 +17,9 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sys/sem.h>
+#include <stddef.h>
 #include <ipc_priv.h>
 #include <sysdep.h>
-#include <errno.h>
 
 /* Perform user-defined atomical operation of array of semaphores.  */
 
diff --git a/sysdeps/unix/sysv/linux/setrlimit.c b/sysdeps/unix/sysv/linux/setrlimit.c
index 8611d577a4..6648fad5c0 100644
--- a/sysdeps/unix/sysv/linux/setrlimit.c
+++ b/sysdeps/unix/sysv/linux/setrlimit.c
@@ -16,9 +16,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <sys/resource.h>
-#include <sys/types.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 #if !__RLIM_T_MATCHES_RLIM64_T
diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
index e4c5bab437..02c94e3c73 100644
--- a/sysdeps/unix/sysv/linux/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/setrlimit64.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
diff --git a/sysdeps/unix/sysv/linux/settimezone.c b/sysdeps/unix/sysv/linux/settimezone.c
index fa463866f3..163956275f 100644
--- a/sysdeps/unix/sysv/linux/settimezone.c
+++ b/sysdeps/unix/sysv/linux/settimezone.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <sys/time.h>
+#include <stddef.h>
 #include <sysdep.h>
 
 /* Set the system-wide timezone.
diff --git a/sysdeps/unix/sysv/linux/shmget.c b/sysdeps/unix/sysv/linux/shmget.c
index 71de81c365..6ea788351b 100644
--- a/sysdeps/unix/sysv/linux/shmget.c
+++ b/sysdeps/unix/sysv/linux/shmget.c
@@ -16,9 +16,10 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <sys/msg.h>
+#include <stddef.h>
 #include <ipc_priv.h>
 #include <sysdep.h>
-#include <errno.h>
 
 /* Return an identifier for an shared memory segment of at least size SIZE
    which is associated with KEY.  */
diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h
index 75c2a6404d..b9975f92b4 100644
--- a/sysdeps/unix/sysv/linux/socketcall.h
+++ b/sysdeps/unix/sysv/linux/socketcall.h
@@ -19,6 +19,8 @@
 #ifndef _SYS_SOCKETCALL_H
 #define _SYS_SOCKETCALL_H	1
 
+#include <sysdep.h>
+
 /* Define unique numbers for the operations permitted on socket.  Linux
    uses a single system call for all these functions.  The relevant code
    file is /usr/include/linux/net.h.
diff --git a/sysdeps/unix/sysv/linux/speed.c b/sysdeps/unix/sysv/linux/speed.c
index c02a06a379..d7d74ddb67 100644
--- a/sysdeps/unix/sysv/linux/speed.c
+++ b/sysdeps/unix/sysv/linux/speed.c
@@ -19,7 +19,7 @@
 #include <stddef.h>
 #include <errno.h>
 #include <termios.h>
-
+#include <sysdep.h>
 
 /* This is a gross hack around a kernel bug.  If the cfsetispeed functions
    is called with the SPEED argument set to zero this means use the same
diff --git a/sysdeps/unix/sysv/linux/statx.c b/sysdeps/unix/sysv/linux/statx.c
index 9721fc12a5..cea6eefb7e 100644
--- a/sysdeps/unix/sysv/linux/statx.c
+++ b/sysdeps/unix/sysv/linux/statx.c
@@ -18,7 +18,7 @@
 
 #include <errno.h>
 #include <sys/stat.h>
-
+#include <sysdep.h>
 #include "statx_generic.c"
 
 int
diff --git a/sysdeps/unix/sysv/linux/sysctl.c b/sysdeps/unix/sysv/linux/sysctl.c
index 389b958226..479ba386bd 100644
--- a/sysdeps/unix/sysv/linux/sysctl.c
+++ b/sysdeps/unix/sysv/linux/sysctl.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <stddef.h>
 #include <shlib-compat.h>
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32)
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 3fa29dd588..9750c0418e 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -20,6 +20,7 @@
 
 #include <bits/wordsize.h>
 #include <kernel-features.h>
+#include <endian.h>
 #include <errno.h>
 
 #ifndef __ASSEMBLER__
diff --git a/sysdeps/unix/sysv/linux/truncate64.c b/sysdeps/unix/sysv/linux/truncate64.c
index d4b46574dc..ac43a2b542 100644
--- a/sysdeps/unix/sysv/linux/truncate64.c
+++ b/sysdeps/unix/sysv/linux/truncate64.c
@@ -17,7 +17,6 @@
 
 #include <unistd.h>
 #include <sysdep.h>
-#include <errno.h>
 
 #ifndef __NR_truncate64
 # define __NR_truncate64 __NR_truncate
diff --git a/sysdeps/unix/sysv/linux/ustat.c b/sysdeps/unix/sysv/linux/ustat.c
index 51f20a2a73..e38b792705 100644
--- a/sysdeps/unix/sysv/linux/ustat.c
+++ b/sysdeps/unix/sysv/linux/ustat.c
@@ -23,7 +23,7 @@
 #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_28)
 
 # include <sysdep.h>
-# include <errno.h>
+# include <sys/types.h>
 
 # ifndef DEV_TO_KDEV
 #  define DEV_TO_KDEV(__dev)					\
diff --git a/sysdeps/unix/sysv/linux/xmknod.c b/sysdeps/unix/sysv/linux/xmknod.c
index 82bb0bd953..10e874a514 100644
--- a/sysdeps/unix/sysv/linux/xmknod.c
+++ b/sysdeps/unix/sysv/linux/xmknod.c
@@ -19,6 +19,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33)
diff --git a/sysdeps/unix/sysv/linux/xmknodat.c b/sysdeps/unix/sysv/linux/xmknodat.c
index fae3fe54d1..17ffea16c9 100644
--- a/sysdeps/unix/sysv/linux/xmknodat.c
+++ b/sysdeps/unix/sysv/linux/xmknodat.c
@@ -17,6 +17,7 @@
 
 #include <sys/stat.h>
 #include <errno.h>
+#include <sysdep.h>
 #include <shlib-compat.h>
 
 #if SHLIB_COMPAT(libc, GLIBC_2_4, GLIBC_2_33)
diff --git a/sysdeps/unix/sysv/linux/xstatconv.c b/sysdeps/unix/sysv/linux/xstatconv.c
index 3622a82cd0..b100e07783 100644
--- a/sysdeps/unix/sysv/linux/xstatconv.c
+++ b/sysdeps/unix/sysv/linux/xstatconv.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <kernel_stat.h>
+#include <sysdep.h>
 
 #if STAT_IS_KERNEL_STAT
 
diff --git a/sysdeps/x86_64/stackinfo.h b/sysdeps/x86_64/stackinfo.h
index 7bcb3b1499..4a4e54cd76 100644
--- a/sysdeps/x86_64/stackinfo.h
+++ b/sysdeps/x86_64/stackinfo.h
@@ -23,6 +23,12 @@
 
 #include <elf.h>
 
+#ifdef __ILP32__
+# define RSP_REG "esp"
+#else
+# define RSP_REG "rsp"
+#endif
+
 /* On x86_64 the stack grows down.  */
 #define _STACK_GROWS_DOWN	1
 
@@ -34,10 +40,10 @@
    for which they need to act as barriers as well, hence the additional
    (unnecessary) parameters.  */
 #define stackinfo_get_sp() \
-  ({ void *p__; asm volatile ("mov %%" RSP_LP ", %0" : "=r" (p__)); p__; })
+  ({ void *p__; asm volatile ("mov %%" RSP_REG ", %0" : "=r" (p__)); p__; })
 #define stackinfo_sub_sp(ptr) \
   ({ ptrdiff_t d__;						\
-     asm volatile ("sub %%" RSP_LP " , %0" : "=r" (d__) : "0" (ptr));	\
+     asm volatile ("sub %%" RSP_REG " , %0" : "=r" (d__) : "0" (ptr));	\
      d__; })
 
 #endif	/* stackinfo.h */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (2 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 03/23] Remove tls.h inclusion from internal errno.h Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error Adhemerval Zanella
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

It check the resulting value from INTERNAL_SYSCALL_CALL and sets the
errno accordingly.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/fstatat.c     |  4 +---
 sysdeps/unix/sysv/linux/fstatat64.c   |  4 +---
 sysdeps/unix/sysv/linux/mq_unlink.c   | 11 +++--------
 sysdeps/unix/sysv/linux/sysdep-vdso.h | 26 +++++--------------------
 sysdeps/unix/sysv/linux/sysdep.h      | 28 ++++++++++++---------------
 5 files changed, 22 insertions(+), 51 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index a61fffa6e7..5ba1b99372 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -80,9 +80,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
 #  endif /* __nr_fstatat64  */
 # endif /* STAT_IS_KERNEL_STAT  */
 
-  return syscall_error (r)
-	 ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
-	 : 0;
+  return syscall_ret (r);
 }
 
 weak_alias (__fstatat, fstatat)
diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c
index 6e12cf2456..a788940390 100644
--- a/sysdeps/unix/sysv/linux/fstatat64.c
+++ b/sysdeps/unix/sysv/linux/fstatat64.c
@@ -102,9 +102,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf,
 # endif
 #endif
 
-  return syscall_error (r)
-	 ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
-	 : 0;
+  return syscall_ret (r);
 }
 #if __TIMESIZE != 64
 hidden_def (__fstatat64_time64)
diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c
index 4964eb9028..701bc86438 100644
--- a/sysdeps/unix/sysv/linux/mq_unlink.c
+++ b/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -30,12 +30,7 @@ mq_unlink (const char *name)
 
   /* While unlink can return either EPERM or EACCES, mq_unlink should
      return just EACCES.  */
-  if (__glibc_unlikely (syscall_error (ret)))
-    {
-      if (ret == -EPERM)
-	ret = -EACCES;
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (-ret);
-    }
-
-  return ret;
+  if (ret == -EPERM)
+    ret = -EACCES;
+  return syscall_ret (ret);
 }
diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index 7c578808c6..9f59198444 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -28,29 +28,13 @@
 
 #define INLINE_VSYSCALL(name, nr, args...)				      \
   ({									      \
-    __label__ out;							      \
-    __label__ iserr;							      \
-    long int sc_ret;							      \
-									      \
+    long int sc_ret = -ENOSYS;						      \
     __typeof (GLRO(dl_vdso_##name)) vdsop = GLRO(dl_vdso_##name);	      \
     if (vdsop != NULL)							      \
-      {									      \
-	sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
-	if (!syscall_error (sc_ret))					      \
-	  goto out;							      \
-	if (sc_ret != -ENOSYS)		      	      			      \
-	  goto iserr;							      \
-      }									      \
-									      \
-    sc_ret = INTERNAL_SYSCALL_CALL (name, ##args);		      	      \
-    if (syscall_error (sc_ret))					      	      \
-      {									      \
-      iserr:								      \
-        __set_errno (-sc_ret);		      	      			      \
-        sc_ret = -1L;							      \
-      }									      \
-  out:									      \
-    sc_ret;								      \
+      sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
+    if (sc_ret == -ENOSYS)						      \
+      sc_ret = INTERNAL_SYSCALL_CALL (name, ##args);		      	      \
+    syscall_ret (sc_ret);						      \
   })
 
 #endif /* SYSDEP_VDSO_LINUX_H  */
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 9750c0418e..66bac892a5 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -29,28 +29,24 @@ syscall_error (unsigned long int val)
 {
   return val > -4096UL;
 }
-#endif
 
-#ifndef SYSCALL_ERROR_LABEL
-# define SYSCALL_ERROR_LABEL(sc_err)					\
-  ({									\
-    __set_errno (sc_err);						\
-    -1L;								\
-  })
-#endif
+static inline long int
+syscall_ret (unsigned long int val)
+{
+  if (syscall_error (val))
+    {
+      __set_errno (-val);
+      return -1;
+    }
+  return val;
+}
 
-#ifndef __ASSEMBLER__
 /* Define a macro which expands into the inline wrapper code for a system
    call.  It sets the errno and returns -1 on a failure, or the syscall
    return value otherwise.  */
 #undef INLINE_SYSCALL
-#define INLINE_SYSCALL(name, nr, args...)				\
-  ({									\
-    long int sc_ret = INTERNAL_SYSCALL (name, nr, args);		\
-    __glibc_unlikely (syscall_error (sc_ret))				\
-    ? SYSCALL_ERROR_LABEL (-sc_ret)					\
-    : sc_ret;								\
-  })
+#define INLINE_SYSCALL(...)				\
+  syscall_ret (INTERNAL_SYSCALL (__VA_ARGS__))
 #endif
 
 /* Set error number and return -1.  A target may choose to return the
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (3 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 22:14   ` Joseph Myers
  2020-11-09 20:18 ` [PATCH 06/23] linux: Use generic __syscall_error for aarch64 Adhemerval Zanella
                   ` (17 subsequent siblings)
  22 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The INLINE_SYSCALL_ERROR_RETURN_VALUE macro was added as a way to
optimize i686 errno setting when {INTERNAL,INLINE}_SYSCALL is called
(since calling__x86.get_pc_thunk.reg to load PC into reg to access
errno is costly for the cases where there is no error).

However this i686 optimizations was also remove by fcb78a55058f,
which consolidate INLINE_SYSCALL semantic and removed i686
INLINE_SYSCALL_ERROR_RETURN_VALUE definition.

This patch adds this optimization back, but in a more generic way.
Each architecture/ABI might select how __syscall_error is emitted,
either by using a static inline or using a external call.  To avoid
the potential PLT call overhead, for the latter __syscall_error is
added on each library that issues {INTERNAL,INLINE}_SYSCALL as a
hidden symbol (and this follow the idea of moving all the libpthread
and librt to libc).

No semantic changes expected, checked with a build against all
affected ABIs.
---
 sysdeps/unix/sysv/linux/Makefile              |  9 ++++-
 sysdeps/unix/sysv/linux/aarch64/sysdep.c      |  1 -
 sysdeps/unix/sysv/linux/adjtime.c             |  2 +-
 sysdeps/unix/sysv/linux/alpha/fxstat64.c      |  2 +-
 sysdeps/unix/sysv/linux/alpha/lxstat64.c      |  2 +-
 sysdeps/unix/sysv/linux/alpha/xstat64.c       |  2 +-
 sysdeps/unix/sysv/linux/arc/sysdep.c          |  8 ++--
 sysdeps/unix/sysv/linux/arc/sysdep.h          |  5 ---
 sysdeps/unix/sysv/linux/faccessat.c           |  4 +-
 sysdeps/unix/sysv/linux/fchmodat.c            |  2 +-
 sysdeps/unix/sysv/linux/fcntl_nocancel.c      |  2 +-
 sysdeps/unix/sysv/linux/fstatat.c             |  4 +-
 sysdeps/unix/sysv/linux/fstatat64.c           |  2 +-
 sysdeps/unix/sysv/linux/futimens.c            |  2 +-
 sysdeps/unix/sysv/linux/fxstat.c              |  2 +-
 sysdeps/unix/sysv/linux/fxstat64.c            |  2 +-
 sysdeps/unix/sysv/linux/fxstatat.c            |  2 +-
 sysdeps/unix/sysv/linux/fxstatat64.c          |  2 +-
 sysdeps/unix/sysv/linux/getdents.c            |  2 +-
 sysdeps/unix/sysv/linux/hppa/sysdep.c         |  2 -
 sysdeps/unix/sysv/linux/i386/brk.c            |  2 +-
 sysdeps/unix/sysv/linux/i386/sysdep.c         |  1 -
 sysdeps/unix/sysv/linux/i386/sysdep.h         |  3 --
 sysdeps/unix/sysv/linux/lxstat.c              |  2 +-
 sysdeps/unix/sysv/linux/lxstat64.c            |  2 +-
 .../unix/sysv/linux/mips/mips64/fxstatat64.c  |  2 +-
 sysdeps/unix/sysv/linux/mknodat.c             |  2 +-
 sysdeps/unix/sysv/linux/mmap.c                |  2 +-
 sysdeps/unix/sysv/linux/mmap64.c              |  2 +-
 sysdeps/unix/sysv/linux/mq_open.c             |  2 +-
 sysdeps/unix/sysv/linux/mq_unlink.c           |  2 +-
 sysdeps/unix/sysv/linux/powerpc/sysdep.c      |  1 -
 sysdeps/unix/sysv/linux/prlimit.c             |  4 +-
 sysdeps/unix/sysv/linux/setegid.c             |  2 +-
 sysdeps/unix/sysv/linux/seteuid.c             |  2 +-
 sysdeps/unix/sysv/linux/shmat.c               |  2 +-
 sysdeps/unix/sysv/linux/speed.c               |  4 +-
 sysdeps/unix/sysv/linux/syscall_error.c       | 30 +++++++++++++++
 sysdeps/unix/sysv/linux/sysdep.h              | 37 ++++++++++++-------
 sysdeps/unix/sysv/linux/tcsendbrk.c           |  2 +-
 sysdeps/unix/sysv/linux/tcsetattr.c           |  2 +-
 sysdeps/unix/sysv/linux/ustat.c               |  4 +-
 sysdeps/unix/sysv/linux/utimensat.c           |  2 +-
 sysdeps/unix/sysv/linux/xmknod.c              |  2 +-
 sysdeps/unix/sysv/linux/xmknodat.c            |  2 +-
 sysdeps/unix/sysv/linux/xstat.c               |  2 +-
 sysdeps/unix/sysv/linux/xstat64.c             |  2 +-
 sysdeps/unix/sysv/linux/xstatconv.c           | 12 +++---
 48 files changed, 113 insertions(+), 80 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/syscall_error.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 09604e128b..241b5f2c53 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -41,7 +41,7 @@ update-syscall-lists: arch-syscall.h
 endif
 
 ifeq ($(subdir),csu)
-sysdep_routines += errno-loc
+sysdep_routines += errno-loc syscall_error
 endif
 
 ifeq ($(subdir),assert)
@@ -283,7 +283,8 @@ tests += tst-fallocate tst-fallocate64 tst-o_path-locks
 endif
 
 ifeq ($(subdir),elf)
-sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir
+sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \
+			syscall_error
 
 libof-lddlibc4 = lddlibc4
 
@@ -295,6 +296,8 @@ endif
 ifeq ($(subdir),rt)
 CFLAGS-mq_send.c += -fexceptions
 CFLAGS-mq_receive.c += -fexceptions
+librt-routines += syscall_error
+librt-shared-only-routines += syscall_error
 endif
 
 ifeq ($(subdir),nscd)
@@ -303,5 +306,7 @@ CFLAGS-gai.c += -DNEED_NETLINK
 endif
 
 ifeq ($(subdir),nptl)
+libpthread-routines += syscall_error
+libpthread-shared-only-routines += syscall_error
 tests += tst-align-clone tst-getpid1
 endif
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.c b/sysdeps/unix/sysv/linux/aarch64/sysdep.c
index b6c01e1aec..6b88f3484f 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.c
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.c
@@ -16,7 +16,6 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
 #include <errno.h>
 
 long __syscall_error (long err);
diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
index 8e7c8cc5da..1a1a37acd3 100644
--- a/sysdeps/unix/sysv/linux/adjtime.c
+++ b/sysdeps/unix/sysv/linux/adjtime.c
@@ -37,7 +37,7 @@ __adjtime64 (const struct __timeval64 *itv, struct __timeval64 *otv)
       tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
       tmp.tv_usec = itv->tv_usec % 1000000L;
       if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+	return __syscall_error (-EINVAL);
       tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;
       tntx.modes = ADJ_OFFSET_SINGLESHOT;
     }
diff --git a/sysdeps/unix/sysv/linux/alpha/fxstat64.c b/sysdeps/unix/sysv/linux/alpha/fxstat64.c
index bcfb55050c..806ef66598 100644
--- a/sysdeps/unix/sysv/linux/alpha/fxstat64.c
+++ b/sysdeps/unix/sysv/linux/alpha/fxstat64.c
@@ -40,7 +40,7 @@ __fxstat64 (int vers, int fd, struct stat64 *buf)
 	int r = INTERNAL_SYSCALL_CALL (fstat, fd, &kbuf);
 	if (r == 0)
 	  return __xstat_conv (vers, &kbuf, buf);
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+	return __syscall_error (r);
       }
     }
 }
diff --git a/sysdeps/unix/sysv/linux/alpha/lxstat64.c b/sysdeps/unix/sysv/linux/alpha/lxstat64.c
index 7424b2f621..0499b0f8f1 100644
--- a/sysdeps/unix/sysv/linux/alpha/lxstat64.c
+++ b/sysdeps/unix/sysv/linux/alpha/lxstat64.c
@@ -41,7 +41,7 @@ __lxstat64 (int vers, const char *name, struct stat64 *buf)
 	int r = INTERNAL_SYSCALL_CALL (lstat, name, &kbuf);
 	if (r == 0)
 	  return __xstat_conv (vers, &kbuf, buf);
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+	return __syscall_error (r);
       }
     }
 }
diff --git a/sysdeps/unix/sysv/linux/alpha/xstat64.c b/sysdeps/unix/sysv/linux/alpha/xstat64.c
index 59f7ddae7f..b08ade68d4 100644
--- a/sysdeps/unix/sysv/linux/alpha/xstat64.c
+++ b/sysdeps/unix/sysv/linux/alpha/xstat64.c
@@ -41,7 +41,7 @@ __xstat64 (int vers, const char *name, struct stat64 *buf)
 	int r = INTERNAL_SYSCALL_CALL (stat, name, &kbuf);
 	if (r == 0)
 	  return __xstat_conv (vers, &kbuf, buf);
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+	return __syscall_error (r);
       }
     }
 }
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.c b/sysdeps/unix/sysv/linux/arc/sysdep.c
index f33d646798..fe904d723b 100644
--- a/sysdeps/unix/sysv/linux/arc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/arc/sysdep.c
@@ -16,9 +16,11 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
 #include <errno.h>
 
+extern long int __syscall_error (long int);
+libc_hidden_proto (__syscall_error)
+
 /* All syscall handlers land here to avoid generated code bloat due to
    GOT reference  to errno_location or it's equivalent.  */
 long int
@@ -28,6 +30,4 @@ __syscall_error (long int err_no)
   return -1;
 }
 
-#if IS_IN (libc)
-hidden_def (__syscall_error)
-#endif
+libc_hidden_def (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
index 8465a2f623..4ab44f6925 100644
--- a/sysdeps/unix/sysv/linux/arc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
@@ -134,11 +134,6 @@ L (call_syscall_err):			ASM_LINE_SEP	\
 
 # define SINGLE_THREAD_BY_GLOBAL		1
 
-# if IS_IN (libc)
-extern long int __syscall_error (long int);
-hidden_proto (__syscall_error)
-# endif
-
 # define ARC_TRAP_INSN	"trap_s 0	\n\t"
 
 # undef INTERNAL_SYSCALL_NCS
diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c
index 5d078371b5..a54cc65767 100644
--- a/sysdeps/unix/sysv/linux/faccessat.c
+++ b/sysdeps/unix/sysv/linux/faccessat.c
@@ -34,7 +34,7 @@ faccessat (int fd, const char *file, int mode, int flag)
     return ret;
 
   if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   if ((flag == 0 || ((flag & ~AT_EACCESS) == 0 && ! __libc_enable_secure)))
     return INLINE_SYSCALL (faccessat, 3, fd, file, mode);
@@ -70,6 +70,6 @@ faccessat (int fd, const char *file, int mode, int flag)
   if (granted == mode)
     return 0;
 
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
+  return __syscall_error (-EACCES);
 #endif /* !__ASSUME_FACCESSAT2 */
 }
diff --git a/sysdeps/unix/sysv/linux/fchmodat.c b/sysdeps/unix/sysv/linux/fchmodat.c
index 5531f1aa6f..f1408b6f6a 100644
--- a/sysdeps/unix/sysv/linux/fchmodat.c
+++ b/sysdeps/unix/sysv/linux/fchmodat.c
@@ -31,7 +31,7 @@ fchmodat (int fd, const char *file, mode_t mode, int flag)
   if (flag == 0)
     return INLINE_SYSCALL (fchmodat, 3, fd, file, mode);
   else if (flag != AT_SYMLINK_NOFOLLOW)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
   else
     {
       /* The kernel system call does not have a mode argument.
diff --git a/sysdeps/unix/sysv/linux/fcntl_nocancel.c b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
index a16fc75cb7..2e2ae72a9d 100644
--- a/sysdeps/unix/sysv/linux/fcntl_nocancel.c
+++ b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
@@ -56,7 +56,7 @@ __fcntl64_nocancel_adjusted (int fd, int cmd, void *arg)
       if (!syscall_error (res))
 	return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
 
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (-res);
+      return __syscall_error (res);
     }
 
   return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index 5ba1b99372..ba58232472 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -35,7 +35,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
   if (r == 0 && (buf->__st_ino_pad != 0
 		 || buf->__st_size_pad != 0
 		 || buf->__st_blocks_pad != 0))
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+    return __syscall_error (-EOVERFLOW);
 # else
 #  ifdef __NR_fstatat64
   /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32,
@@ -47,7 +47,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
       if (! in_ino_t_range (st64.st_ino)
 	  || ! in_off_t_range (st64.st_size)
 	  || ! in_blkcnt_t_range (st64.st_blocks))
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	return __syscall_error (-EOVERFLOW);
 
       /* Clear internal pad and reserved fields.  */
       memset (buf, 0, sizeof (*buf));
diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c
index a788940390..831a5b8e54 100644
--- a/sysdeps/unix/sysv/linux/fstatat64.c
+++ b/sysdeps/unix/sysv/linux/fstatat64.c
@@ -47,7 +47,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf,
       return 0;
     }
   if (-r != ENOSYS)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+    return __syscall_error (r);
 #endif
 
 #if XSTAT_IS_XSTAT64
diff --git a/sysdeps/unix/sysv/linux/futimens.c b/sysdeps/unix/sysv/linux/futimens.c
index 2c698b4e85..756a61a935 100644
--- a/sysdeps/unix/sysv/linux/futimens.c
+++ b/sysdeps/unix/sysv/linux/futimens.c
@@ -32,7 +32,7 @@ int
 __futimens64 (int fd, const struct __timespec64 tsp64[2])
 {
   if (fd < 0)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EBADF);
+    return __syscall_error (-EBADF);
 
   return __utimensat64_helper (fd, NULL, &tsp64[0], 0);
 }
diff --git a/sysdeps/unix/sysv/linux/fxstat.c b/sysdeps/unix/sysv/linux/fxstat.c
index 649bb95252..fabf8e66f8 100644
--- a/sysdeps/unix/sysv/linux/fxstat.c
+++ b/sysdeps/unix/sysv/linux/fxstat.c
@@ -52,7 +52,7 @@ __fxstat (int vers, int fd, struct stat *buf)
     default:
       {
 # if STAT_IS_KERNEL_STAT
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+	return __syscall_error (-EINVAL);
 # else
 	struct stat64 buf64;
 	int r = INLINE_SYSCALL_CALL (fstat64, fd, &buf64);
diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c
index 4bd926bf01..5a81f87e2a 100644
--- a/sysdeps/unix/sysv/linux/fxstat64.c
+++ b/sysdeps/unix/sysv/linux/fxstat64.c
@@ -50,7 +50,7 @@ ___fxstat64 (int vers, int fd, struct stat64 *buf)
      and x86_64.  */
   if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
     return INLINE_SYSCALL_CALL (fstat, fd, buf);
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 # else
   /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32.  */
   struct statx tmp;
diff --git a/sysdeps/unix/sysv/linux/fxstatat.c b/sysdeps/unix/sysv/linux/fxstatat.c
index 2083e18eac..b3a1750e1b 100644
--- a/sysdeps/unix/sysv/linux/fxstatat.c
+++ b/sysdeps/unix/sysv/linux/fxstatat.c
@@ -41,7 +41,7 @@ __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
       int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, st, flag);
       return r ?: stat_overflow (st);
     }
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 #else
   /* Old kABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32,
      microblaze, s390, sh, powerpc32, and sparc32.  */
diff --git a/sysdeps/unix/sysv/linux/fxstatat64.c b/sysdeps/unix/sysv/linux/fxstatat64.c
index 8a505451d9..a0bdb137f1 100644
--- a/sysdeps/unix/sysv/linux/fxstatat64.c
+++ b/sysdeps/unix/sysv/linux/fxstatat64.c
@@ -63,7 +63,7 @@ __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
   if (vers == _STAT_VER_LINUX)
     return INLINE_SYSCALL_CALL (fstatat64, fd, file, st, flag);
 #endif
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 }
 
 compat_symbol (libc, __fxstatat64, __fxstatat64, GLIBC_2_4);
diff --git a/sysdeps/unix/sysv/linux/getdents.c b/sysdeps/unix/sysv/linux/getdents.c
index a76be2e5e7..a5041e4ebb 100644
--- a/sysdeps/unix/sysv/linux/getdents.c
+++ b/sysdeps/unix/sysv/linux/getdents.c
@@ -98,7 +98,7 @@ __getdents (int fd, void *buf0, size_t nbytes)
               __lseek64 (fd, last_offset, SEEK_SET);
               return outp->b - buf;
             }
-	  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	  return __syscall_error (-EOVERFLOW);
         }
 
       last_offset = d_off;
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.c b/sysdeps/unix/sysv/linux/hppa/sysdep.c
index 8f05bfc9c9..8c06b6fc80 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep.c
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep.c
@@ -15,8 +15,6 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <stdarg.h>
-#include <sysdep.h>
 #include <errno.h>
 
 /* This routine is jumped to by all the syscall handlers, to stash
diff --git a/sysdeps/unix/sysv/linux/i386/brk.c b/sysdeps/unix/sysv/linux/i386/brk.c
index 021b6d37a0..900fb0a031 100644
--- a/sysdeps/unix/sysv/linux/i386/brk.c
+++ b/sysdeps/unix/sysv/linux/i386/brk.c
@@ -39,7 +39,7 @@ __brk (void *addr)
   void *newbrk = (void *) INTERNAL_SYSCALL_CALL (brk, addr);
   __curbrk = newbrk;
   if (newbrk < addr)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOMEM);
+    return __syscall_error (-ENOMEM);
   return 0;
 }
 weak_alias (__brk, brk)
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.c b/sysdeps/unix/sysv/linux/i386/sysdep.c
index 0a9058d505..e6228406dd 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.c
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.c
@@ -16,7 +16,6 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <sysdep.h>
 
 /* This routine is jumped to by all the syscall handlers, to stash
    an error number into errno.  ERROR is the negative error number
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index bfb5de3b45..4680013de4 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -236,9 +236,6 @@
 
 #else	/* !__ASSEMBLER__ */
 
-extern int __syscall_error (int)
-  attribute_hidden __attribute__ ((__regparm__ (1)));
-
 #ifndef OPTIMIZE_FOR_GCC_5
 /* We need some help from the assembler to generate optimal code.  We
    define some macros here which later will be used.  */
diff --git a/sysdeps/unix/sysv/linux/lxstat.c b/sysdeps/unix/sysv/linux/lxstat.c
index 913618eab9..c86cfb349a 100644
--- a/sysdeps/unix/sysv/linux/lxstat.c
+++ b/sysdeps/unix/sysv/linux/lxstat.c
@@ -53,7 +53,7 @@ __lxstat (int vers, const char *name, struct stat *buf)
     default:
       {
 # if STAT_IS_KERNEL_STAT
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+	return __syscall_error (-EINVAL);
 # else
 	struct stat64 buf64;
 	int r = INLINE_SYSCALL_CALL (lstat64, name, &buf64);
diff --git a/sysdeps/unix/sysv/linux/lxstat64.c b/sysdeps/unix/sysv/linux/lxstat64.c
index 277b54b305..3e0fb8b25d 100644
--- a/sysdeps/unix/sysv/linux/lxstat64.c
+++ b/sysdeps/unix/sysv/linux/lxstat64.c
@@ -81,7 +81,7 @@ ___lxstat64 (int vers, const char *name, struct stat64 *buf)
 # endif /* STAT_IS_KERNEL_STAT  */
 #endif /* XSTAT_IS_XSTAT64  */
 
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 }
 
 #if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/fxstatat64.c b/sysdeps/unix/sysv/linux/mips/mips64/fxstatat64.c
index f40a2c5aa8..6bea711cd0 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/fxstatat64.c
+++ b/sysdeps/unix/sysv/linux/mips/mips64/fxstatat64.c
@@ -35,7 +35,7 @@ __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
       int r = INLINE_SYSCALL_CALL (newfstatat, fd, file, &kst, flag);;
       return r ?: __xstat64_conv (vers, &kst, st);
     }
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 }
 
 compat_symbol (libc, __fxstatat64, __fxstatat64, GLIBC_2_4);
diff --git a/sysdeps/unix/sysv/linux/mknodat.c b/sysdeps/unix/sysv/linux/mknodat.c
index 279a4404f5..aa298483d5 100644
--- a/sysdeps/unix/sysv/linux/mknodat.c
+++ b/sysdeps/unix/sysv/linux/mknodat.c
@@ -28,7 +28,7 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev)
      32-bit.  */
   unsigned int k_dev = dev;
   if (k_dev != dev)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   return INLINE_SYSCALL_CALL (mknodat, fd, path, mode, k_dev);
 }
diff --git a/sysdeps/unix/sysv/linux/mmap.c b/sysdeps/unix/sysv/linux/mmap.c
index 22f276bb14..9952625219 100644
--- a/sysdeps/unix/sysv/linux/mmap.c
+++ b/sysdeps/unix/sysv/linux/mmap.c
@@ -36,7 +36,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
   MMAP_CHECK_PAGE_UNIT ();
 
   if (offset & MMAP_OFF_LOW_MASK)
-    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return (void *) __syscall_error (-EINVAL);
 
 #ifdef __NR_mmap2
   return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd,
diff --git a/sysdeps/unix/sysv/linux/mmap64.c b/sysdeps/unix/sysv/linux/mmap64.c
index 8074deb466..0eed429e48 100644
--- a/sysdeps/unix/sysv/linux/mmap64.c
+++ b/sysdeps/unix/sysv/linux/mmap64.c
@@ -49,7 +49,7 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
   MMAP_CHECK_PAGE_UNIT ();
 
   if (offset & MMAP_OFF_MASK)
-    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return (void *) __syscall_error (-EINVAL);
 
   MMAP_PREPARE (addr, len, prot, flags, fd, offset);
 #ifdef __NR_mmap2
diff --git a/sysdeps/unix/sysv/linux/mq_open.c b/sysdeps/unix/sysv/linux/mq_open.c
index c88dc580e4..542f9b7097 100644
--- a/sysdeps/unix/sysv/linux/mq_open.c
+++ b/sysdeps/unix/sysv/linux/mq_open.c
@@ -33,7 +33,7 @@ mqd_t
 __mq_open (const char *name, int oflag, ...)
 {
   if (name[0] != '/')
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   mode_t mode = 0;
   struct mq_attr *attr = NULL;
diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c
index 701bc86438..741c4e5776 100644
--- a/sysdeps/unix/sysv/linux/mq_unlink.c
+++ b/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -24,7 +24,7 @@ int
 mq_unlink (const char *name)
 {
   if (name[0] != '/')
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   int ret = INTERNAL_SYSCALL_CALL (mq_unlink, name + 1);
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.c b/sysdeps/unix/sysv/linux/powerpc/sysdep.c
index 37f0f1f53e..1bf5ea6f62 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.c
@@ -15,7 +15,6 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
 #include <errno.h>
 
 /* This routine is jumped to by all the syscall handlers, to stash
diff --git a/sysdeps/unix/sysv/linux/prlimit.c b/sysdeps/unix/sysv/linux/prlimit.c
index e12eb4e9bc..0a8e6a519e 100644
--- a/sysdeps/unix/sysv/linux/prlimit.c
+++ b/sysdeps/unix/sysv/linux/prlimit.c
@@ -58,7 +58,7 @@ prlimit (__pid_t pid, enum __rlimit_resource resource,
 	{
 	  if ((new_rlimit == NULL)
 	      && (old_rlimit64_mem.rlim_cur != RLIM64_INFINITY))
-	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	    return __syscall_error (-EOVERFLOW);
 	  old_rlimit->rlim_cur = RLIM_INFINITY;
 	}
       old_rlimit->rlim_max = old_rlimit64_mem.rlim_max;
@@ -66,7 +66,7 @@ prlimit (__pid_t pid, enum __rlimit_resource resource,
 	{
 	  if ((new_rlimit == NULL)
 	      && (old_rlimit64_mem.rlim_max != RLIM64_INFINITY))
-	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	    return __syscall_error (-EOVERFLOW);
 	  old_rlimit->rlim_max = RLIM_INFINITY;
 	}
     }
diff --git a/sysdeps/unix/sysv/linux/setegid.c b/sysdeps/unix/sysv/linux/setegid.c
index ce8bead278..ea135b9084 100644
--- a/sysdeps/unix/sysv/linux/setegid.c
+++ b/sysdeps/unix/sysv/linux/setegid.c
@@ -26,7 +26,7 @@ setegid (gid_t gid)
   int result;
 
   if (gid == (gid_t) ~0)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
 #ifdef __NR_setresgid32
   result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
diff --git a/sysdeps/unix/sysv/linux/seteuid.c b/sysdeps/unix/sysv/linux/seteuid.c
index 4519ac2db6..5259adee85 100644
--- a/sysdeps/unix/sysv/linux/seteuid.c
+++ b/sysdeps/unix/sysv/linux/seteuid.c
@@ -26,7 +26,7 @@ seteuid (uid_t uid)
   int result;
 
   if (uid == (uid_t) ~0)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
 #ifdef __NR_setresuid32
   result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
diff --git a/sysdeps/unix/sysv/linux/shmat.c b/sysdeps/unix/sysv/linux/shmat.c
index 98291fe972..3a1f483f09 100644
--- a/sysdeps/unix/sysv/linux/shmat.c
+++ b/sysdeps/unix/sysv/linux/shmat.c
@@ -36,7 +36,7 @@ shmat (int shmid, const void *shmaddr, int shmflg)
   resultvar = INTERNAL_SYSCALL_CALL (ipc, IPCOP_shmat, shmid, shmflg,
 				     &raddr, shmaddr);
   if (syscall_error (resultvar))
-    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (-resultvar);
+    return (void *) __syscall_error (resultvar);
 
   return raddr;
 #endif
diff --git a/sysdeps/unix/sysv/linux/speed.c b/sysdeps/unix/sysv/linux/speed.c
index d7d74ddb67..9df2f250c6 100644
--- a/sysdeps/unix/sysv/linux/speed.c
+++ b/sysdeps/unix/sysv/linux/speed.c
@@ -56,7 +56,7 @@ cfsetospeed (struct termios *termios_p, speed_t speed)
 {
   if ((speed & ~CBAUD) != 0
       && (speed < B57600 || speed > __MAX_BAUD))
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
 #if _HAVE_STRUCT_TERMIOS_C_OSPEED
   termios_p->c_ospeed = speed;
@@ -78,7 +78,7 @@ cfsetispeed (struct termios *termios_p, speed_t speed)
 {
   if ((speed & ~CBAUD) != 0
       && (speed < B57600 || speed > __MAX_BAUD))
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
 #if _HAVE_STRUCT_TERMIOS_C_ISPEED
   termios_p->c_ispeed = speed;
diff --git a/sysdeps/unix/sysv/linux/syscall_error.c b/sysdeps/unix/sysv/linux/syscall_error.c
new file mode 100644
index 0000000000..e7818a36da
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/syscall_error.c
@@ -0,0 +1,30 @@
+/* Linux wrappers for setting errno.
+   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
+   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>
+
+#ifdef SYSCALL_ERROR_FUNC
+long int
+SYSCALL_ERROR_FUNC_ATTR
+__syscall_error (long int error)
+{
+  __set_errno (-error);
+  return -1L;
+}
+#endif
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 66bac892a5..6c0d1f9f6f 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -30,14 +30,34 @@ syscall_error (unsigned long int val)
   return val > -4096UL;
 }
 
+/* The errno setting might be set either inline or with a helper function.
+   For some ABIs (x86_64 for instance), handling it inline might generate
+   less code; while for others (i686) a function call is preferable.
+
+   To use the helper function the ABI must define SYSCALL_ERROR_FUNC, it will
+   build a hidden function on each shared object that issue direct syscall
+   with {INLINE,INTERNAL}_SYSCALL_CALL.  */
+
+#ifdef SYSCALL_ERROR_FUNC
+# ifndef SYSCALL_ERROR_FUNC_ATTR
+#  define SYSCALL_ERROR_FUNC_ATTR
+# endif
+long int __syscall_error (long int err) attribute_hidden
+  SYSCALL_ERROR_FUNC_ATTR;
+#else
+static inline long int
+__syscall_error (long int err)
+{
+  __set_errno (-err);
+  return -1L;
+}
+#endif
+
 static inline long int
 syscall_ret (unsigned long int val)
 {
   if (syscall_error (val))
-    {
-      __set_errno (-val);
-      return -1;
-    }
+    return __syscall_error (val);
   return val;
 }
 
@@ -49,15 +69,6 @@ syscall_ret (unsigned long int val)
   syscall_ret (INTERNAL_SYSCALL (__VA_ARGS__))
 #endif
 
-/* Set error number and return -1.  A target may choose to return the
-   internal function, __syscall_error, which sets errno and returns -1.
-   We use -1l, instead of -1, so that it can be casted to (void *).  */
-#define INLINE_SYSCALL_ERROR_RETURN_VALUE(err)  \
-  ({						\
-    __set_errno (err);				\
-    -1l;					\
-  })
-
 /* Provide a dummy argument that can be used to force register
    alignment for register pairs if required by the syscall ABI.  */
 #ifdef __ASSUME_ALIGNED_REGISTER_PAIRS
diff --git a/sysdeps/unix/sysv/linux/tcsendbrk.c b/sysdeps/unix/sysv/linux/tcsendbrk.c
index 5d81d86bb2..d77acd064d 100644
--- a/sysdeps/unix/sysv/linux/tcsendbrk.c
+++ b/sysdeps/unix/sysv/linux/tcsendbrk.c
@@ -39,6 +39,6 @@ tcsendbreak (int fd, int duration)
   /* ioctl can't send a break of any other duration for us.
      This could be changed to use trickery (e.g. lower speed and
      send a '\0') to send the break, but for now just return an error.  */
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 #endif
 }
diff --git a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c
index 50b2b0af8a..978e182e17 100644
--- a/sysdeps/unix/sysv/linux/tcsetattr.c
+++ b/sysdeps/unix/sysv/linux/tcsetattr.c
@@ -58,7 +58,7 @@ __tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
       cmd = TCSETSF;
       break;
     default:
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+      return __syscall_error (-EINVAL);
     }
 
   k_termios.c_iflag = termios_p->c_iflag & ~IBAUD0;
diff --git a/sysdeps/unix/sysv/linux/ustat.c b/sysdeps/unix/sysv/linux/ustat.c
index e38b792705..1df6f28794 100644
--- a/sysdeps/unix/sysv/linux/ustat.c
+++ b/sysdeps/unix/sysv/linux/ustat.c
@@ -31,7 +31,7 @@
     unsigned long long int k_dev;				\
     k_dev = dev & ((1ULL << 32) - 1);				\
     if (k_dev != dev)						\
-     return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);		\
+     return __syscall_error (-EINVAL);		\
     (unsigned int) k_dev;					\
   })
 # endif
@@ -50,7 +50,7 @@ __old_ustat (dev_t dev, struct ustat *ubuf)
 # ifdef __NR_ustat
   return INLINE_SYSCALL_CALL (ustat, DEV_TO_KDEV (dev), ubuf);
 # else
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOSYS);
+  return __syscall_error (-ENOSYS);
 # endif
 }
 compat_symbol (libc, __old_ustat, ustat, GLIBC_2_0);
diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c
index aef34916e8..15a40a6174 100644
--- a/sysdeps/unix/sysv/linux/utimensat.c
+++ b/sysdeps/unix/sysv/linux/utimensat.c
@@ -71,7 +71,7 @@ __utimensat64 (int fd, const char *file, const struct __timespec64 tsp64[2],
                int flags)
 {
   if (file == NULL)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   return __utimensat64_helper (fd, file, &tsp64[0], flags);
 }
diff --git a/sysdeps/unix/sysv/linux/xmknod.c b/sysdeps/unix/sysv/linux/xmknod.c
index 10e874a514..c3b31f9c97 100644
--- a/sysdeps/unix/sysv/linux/xmknod.c
+++ b/sysdeps/unix/sysv/linux/xmknod.c
@@ -31,7 +31,7 @@ attribute_compat_text_section
 __xmknod (int vers, const char *path, mode_t mode, dev_t *dev)
 {
   if (vers != _MKNOD_VER)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   return __mknodat (AT_FDCWD, path, mode, *dev);
 }
diff --git a/sysdeps/unix/sysv/linux/xmknodat.c b/sysdeps/unix/sysv/linux/xmknodat.c
index 17ffea16c9..9b2bdd872f 100644
--- a/sysdeps/unix/sysv/linux/xmknodat.c
+++ b/sysdeps/unix/sysv/linux/xmknodat.c
@@ -28,7 +28,7 @@ int
 __xmknodat (int vers, int fd, const char *file, mode_t mode, dev_t *dev)
 {
   if (vers != _MKNOD_VER)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    return __syscall_error (-EINVAL);
 
   return __mknodat (fd, file, mode, *dev);
 }
diff --git a/sysdeps/unix/sysv/linux/xstat.c b/sysdeps/unix/sysv/linux/xstat.c
index 3eb2d8c51b..1394d6235c 100644
--- a/sysdeps/unix/sysv/linux/xstat.c
+++ b/sysdeps/unix/sysv/linux/xstat.c
@@ -52,7 +52,7 @@ __xstat (int vers, const char *name, struct stat *buf)
     default:
       {
 # if STAT_IS_KERNEL_STAT
-	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+	return __syscall_error (-EINVAL);
 # else
 	struct stat64 buf64;
 	int r = INLINE_SYSCALL_CALL (stat64, name, &buf64);
diff --git a/sysdeps/unix/sysv/linux/xstat64.c b/sysdeps/unix/sysv/linux/xstat64.c
index dd4f808c7a..06579c9d63 100644
--- a/sysdeps/unix/sysv/linux/xstat64.c
+++ b/sysdeps/unix/sysv/linux/xstat64.c
@@ -78,7 +78,7 @@ ___xstat64 (int vers, const char *name, struct stat64 *buf)
 # endif /* STAT_IS_KERNEL_STAT  */
 #endif /* XSTAT_IS_XSTAT64  */
 
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+  return __syscall_error (-EINVAL);
 }
 
 #if XSTAT_IS_XSTAT64
diff --git a/sysdeps/unix/sysv/linux/xstatconv.c b/sysdeps/unix/sysv/linux/xstatconv.c
index b100e07783..552e762fda 100644
--- a/sysdeps/unix/sysv/linux/xstatconv.c
+++ b/sysdeps/unix/sysv/linux/xstatconv.c
@@ -96,7 +96,7 @@ __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
       break;
 
     default:
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+      return __syscall_error (-EINVAL);
     }
 
   return 0;
@@ -169,7 +169,7 @@ __xstat64_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
 	 _STAT_VER_KERNEL does not make sense.  */
     case _STAT_VER_KERNEL:
     default:
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+      return __syscall_error (-EINVAL);
     }
 
   return 0;
@@ -192,7 +192,7 @@ __xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf)
 	buf->st_ino = kbuf->st_ino;
 	if (sizeof (buf->st_ino) != sizeof (kbuf->st_ino)
 	    && buf->st_ino != kbuf->st_ino)
-	  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	  return __syscall_error (-EOVERFLOW);
 	buf->st_mode = kbuf->st_mode;
 	buf->st_nlink = kbuf->st_nlink;
 	buf->st_uid = kbuf->st_uid;
@@ -205,13 +205,13 @@ __xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf)
 	/* Check for overflow.  */
 	if (sizeof (buf->st_size) != sizeof (kbuf->st_size)
 	    && buf->st_size != kbuf->st_size)
-	  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	  return __syscall_error (-EOVERFLOW);
 	buf->st_blksize = kbuf->st_blksize;
 	buf->st_blocks = kbuf->st_blocks;
 	/* Check for overflow.  */
 	if (sizeof (buf->st_blocks) != sizeof (kbuf->st_blocks)
 	    && buf->st_blocks != kbuf->st_blocks)
-	  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+	  return __syscall_error (-EOVERFLOW);
 #ifdef _HAVE_STAT_NSEC
 	buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
 	buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
@@ -247,7 +247,7 @@ __xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf)
 	 _STAT_VER_KERNEL does not make sense.  */
     case _STAT_VER_KERNEL:
     default:
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+      return __syscall_error (-EINVAL);
     }
 
   return 0;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 06/23] linux: Use generic __syscall_error for aarch64
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (4 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 07/23] linux: Use generic __syscall_error for i386 Adhemerval Zanella
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The auto-generated syscalls calls the __syscall_error, although setting
using inline function generates slight less code:

--- sizes-aarch64-linux-gnu.outline
+++ sizes-aarch64-linux-gnu.inline
    text           data     bss     dec     hex filename
 1388874          19096   14520 1422490  15b49a libc.so
- 138509           7136     344  145989   23a45 elf/ld.so
-  98439           1636   16656  116731   1c7fb nptl/libpthread.so
-  23942           1236     248   25426    6352 rt/librt.so
+ 138449           7136     344  145929   23a09 elf/ld.so
+  98567           1636   16656  116859   1c87b nptl/libpthread.so
+  23918           1236     248   25402    633a rt/librt.so

Checked on aarch64-linux-gnu.
---
 sysdeps/unix/sysv/linux/aarch64/sysdep.c | 32 ------------------------
 sysdeps/unix/sysv/linux/aarch64/sysdep.h |  2 ++
 2 files changed, 2 insertions(+), 32 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/aarch64/sysdep.c

diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.c b/sysdeps/unix/sysv/linux/aarch64/sysdep.c
deleted file mode 100644
index 6b88f3484f..0000000000
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (C) 2011-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>
-
-long __syscall_error (long err);
-hidden_proto (__syscall_error)
-
-/* This routine is jumped to by all the syscall handlers, to stash
-   an error number into errno.  */
-long
-__syscall_error (long err)
-{
-  __set_errno (- err);
-  return -1;
-}
-hidden_def (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 319a7c7ac5..e1cda79449 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_AARCH64_SYSDEP_H
 #define _LINUX_AARCH64_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/aarch64/sysdep.h>
 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 07/23] linux: Use generic __syscall_error for i386
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (5 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 06/23] linux: Use generic __syscall_error for aarch64 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-10 12:49   ` Florian Weimer
  2020-11-09 20:18 ` [PATCH 08/23] linux: Use generic __syscall_error for arc Adhemerval Zanella
                   ` (15 subsequent siblings)
  22 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: 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.

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

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>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 08/23] linux: Use generic __syscall_error for arc
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (6 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 07/23] linux: Use generic __syscall_error for i386 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 09/23] linux: Use generic __syscall_error for powerpc Adhemerval Zanella
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Moving to intra DSO calls generates slight better code and avoid
a GLIBC_PRIVATE symbol (only librt increases because it issues
syscalls only in specific places).

--- sizes-arc-linux-gnuhf.before
+++ sizes-arc-linux-gnuhf.after
    text           data     bss     dec     hex filename
- 962196           9400    8116  979712   ef300 libc.so
- 110145           3724     192  114061   1bd8d elf/ld.so
-  75099            796    8348   84243   14913 nptl/libpthread.so
-  18882            600     156   19638    4cb6 rt/librt.so
+ 961186           9400    8116  978702   eef0e libc.so
+ 109745           3724     192  113661   1bbfd elf/ld.so
+  75463            796    8348   84607   14a7f nptl/libpthread.so
+  18704            596     156   19456    4c00 rt/librt.so

Checked with build for arc-linux-gnuabihf.
---
 sysdeps/arc/Versions                 |  3 ---
 sysdeps/unix/sysv/linux/arc/sysdep.c | 33 ----------------------------
 sysdeps/unix/sysv/linux/arc/sysdep.h | 14 +++---------
 3 files changed, 3 insertions(+), 47 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/arc/sysdep.c

diff --git a/sysdeps/arc/Versions b/sysdeps/arc/Versions
index 6ac7b8e495..ff157421a5 100644
--- a/sysdeps/arc/Versions
+++ b/sysdeps/arc/Versions
@@ -2,7 +2,4 @@ libc {
   GLIBC_2.32 {
     __mcount;
   }
-  GLIBC_PRIVATE {
-    __syscall_error;
-  }
 }
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.c b/sysdeps/unix/sysv/linux/arc/sysdep.c
deleted file mode 100644
index fe904d723b..0000000000
--- a/sysdeps/unix/sysv/linux/arc/sysdep.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ARC wrapper for setting errno.
-   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
-   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>
-
-extern long int __syscall_error (long int);
-libc_hidden_proto (__syscall_error)
-
-/* All syscall handlers land here to avoid generated code bloat due to
-   GOT reference  to errno_location or it's equivalent.  */
-long int
-__syscall_error (long int err_no)
-{
-  __set_errno (-err_no);
-  return -1;
-}
-
-libc_hidden_def (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
index 4ab44f6925..9e43399f1e 100644
--- a/sysdeps/unix/sysv/linux/arc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_ARC_SYSDEP_H
 #define _LINUX_ARC_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/arc/sysdep.h>
 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
 
@@ -103,22 +105,12 @@
 # define PSEUDO_END_ERRVAL(name)				\
   END (name)
 
-
-/* To reduce the code footprint, we confine the actual errno access
-   to single place in __syscall_error().
-   This takes raw kernel error value, sets errno and returns -1.  */
-# if IS_IN (libc)
-#  define CALL_ERRNO_SETTER_C	bl     PLTJMP(HIDDEN_JUMPTARGET(__syscall_error))
-# else
-#  define CALL_ERRNO_SETTER_C	bl     PLTJMP(__syscall_error)
-# endif
-
 # define SYSCALL_ERROR_HANDLER				\
 L (call_syscall_err):			ASM_LINE_SEP	\
     push_s   blink			ASM_LINE_SEP	\
     cfi_adjust_cfa_offset (4)		ASM_LINE_SEP	\
     cfi_rel_offset (blink, 0)		ASM_LINE_SEP	\
-    CALL_ERRNO_SETTER_C			ASM_LINE_SEP	\
+    bl __syscall_error			ASM_LINE_SEP	\
     pop_s  blink			ASM_LINE_SEP	\
     cfi_adjust_cfa_offset (-4)		ASM_LINE_SEP	\
     cfi_restore (blink)			ASM_LINE_SEP	\
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 09/23] linux: Use generic __syscall_error for powerpc
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (7 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 08/23] linux: Use generic __syscall_error for arc Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 10/23] linux: Use generic __syscall_error for sparc Adhemerval Zanella
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The powerpc kABI returns a positive value on 'r3' register for failure
case (the syscall error is signaled on CR0), different than usual Linux
kABI with return a negative value in range of [-4096,0).  The arch
specific__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 an inline function for __syscall_error is slight better for
powerpc64{le} and only a small code increase on powerpc32:

--- sizes-powerpc-linux-gnu.outline
+++ sizes-powerpc-linux-gnu.inline
@@ -1,8 +1,8 @@
    text           data     bss     dec     hex filename
-1759918          19900    9348 1789166  1b4cee libc.so
- 176605           7516     188  184309   2cff5 elf/ld.so
- 131959           1776    8352  142087   22b07 nptl/libpthread.so
-  32058            872     160   33090    8142 rt/librt.so
+1767602          19900    9348 1796850  1b6af2 libc.so
+ 177221           7516     188  184925   2d25d elf/ld.so
+ 132575           1776    8352  142703   22d6f nptl/libpthread.so
+  32350            872     160   33382    8266 rt/librt.so

--- sizes-powerpc64-linux-gnu.outline
+++ sizes-powerpc64-linux-gnu.inline
@@ -1,8 +1,8 @@
    text           data     bss     dec     hex filename
-2035762          95184   15048 2145994  20beca libc.so
- 258573          13104     504  272181   42735 elf/ld.so
- 154913           8240   18656  181809   2c631 nptl/libpthread.so
-  36875           2404    3704   42983    a7e7 rt/librt.so
+2031758          95184   15048 2141990  20af26 libc.so
+ 257881          13104     504  271489   42481 elf/ld.so
+ 154349           8240   18656  181245   2c3fd nptl/libpthread.so
+  36511           2404    3704   42619    a67b rt/librt.so

--- sizes-powerpc64le-linux-gnu.outline
+++ sizes-powerpc64le-linux-gnu.inline
@@ -1,8 +1,8 @@
    text           data     bss     dec     hex filename
-2031374          22464   14872 2068710  1f90e6 libc.so
- 208066           7832     416  216314   34cfa elf/ld.so
- 137717           1248   17328  156293   26285 nptl/libpthread.so
-  31918            716     728   33362    8252 rt/librt.so
+2027838          22464   14872 2065174  1f8316 libc.so
+ 207426           7832     416  215674   34a7a elf/ld.so
+ 137149           1248   17328  155725   2604d nptl/libpthread.so
+  31490            716     728   32934    80a6 rt/librt.so

Checked on powerpc-linux-gnu, powerpc64-linux-gnu, and
powerpc64le-linux-gnu.
---
 sysdeps/powerpc/powerpc32/sysdep.h            |  1 +
 sysdeps/powerpc/powerpc64/sysdep.h            |  7 +++--
 sysdeps/unix/sysv/linux/powerpc/Makefile      |  7 -----
 .../unix/sysv/linux/powerpc/powerpc32/brk.S   |  1 +
 .../unix/sysv/linux/powerpc/powerpc32/clone.S |  3 +-
 .../sysv/linux/powerpc/powerpc32/getcontext.S |  2 ++
 .../linux/powerpc/powerpc32/makecontext.S     |  2 +-
 .../powerpc/powerpc32/nofpu/getcontext.S      |  2 +-
 .../powerpc/powerpc32/nofpu/setcontext.S      |  2 +-
 .../powerpc/powerpc32/nofpu/swapcontext.S     |  2 +-
 .../sysv/linux/powerpc/powerpc32/setcontext.S |  3 +-
 .../linux/powerpc/powerpc32/swapcontext.S     |  3 +-
 sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c   |  1 -
 sysdeps/unix/sysv/linux/powerpc/sysdep.c      | 27 ------------------
 sysdeps/unix/sysv/linux/powerpc/sysdep.h      |  2 ++
 sysdeps/unix/sysv/linux/sparc/sysdep.c        | 28 ++++++++++++++++++-
 16 files changed, 48 insertions(+), 45 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/sysdep.c

diff --git a/sysdeps/powerpc/powerpc32/sysdep.h b/sysdeps/powerpc/powerpc32/sysdep.h
index 829eec266a..47d3aa4339 100644
--- a/sysdeps/powerpc/powerpc32/sysdep.h
+++ b/sysdeps/powerpc/powerpc32/sysdep.h
@@ -113,6 +113,7 @@ GOT_LABEL:			;					      \
 
 #define PSEUDO_RET							      \
     bnslr+;								      \
+    neg 3,3;								      \
     b __syscall_error@local
 #define ret PSEUDO_RET
 
diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h
index d557098898..e7496a979a 100644
--- a/sysdeps/powerpc/powerpc64/sysdep.h
+++ b/sysdeps/powerpc/powerpc64/sysdep.h
@@ -277,13 +277,13 @@ LT_LABELSUFFIX(name,_name_end): ; \
   DO_CALL (SYS_ify (syscall_name))
 
 #ifdef SHARED
-#define TAIL_CALL_SYSCALL_ERROR \
+#define _TAIL_CALL_SYSCALL_ERROR \
     b JUMPTARGET (NOTOC (__syscall_error))
 #else
 /* Static version might be linked into a large app with a toc exceeding
    64k.  We can't put a toc adjusting stub on a plain branch, so can't
    tail call __syscall_error.  */
-#define TAIL_CALL_SYSCALL_ERROR \
+#define _TAIL_CALL_SYSCALL_ERROR \
     .ifdef .Local_syscall_error; \
     b .Local_syscall_error; \
     .else; \
@@ -303,6 +303,9 @@ LT_LABELSUFFIX(name,_name_end): ; \
     blr; \
     .endif
 #endif
+#define TAIL_CALL_SYSCALL_ERROR \
+    neg 3,3; \
+    _TAIL_CALL_SYSCALL_ERROR
 
 #define PSEUDO_RET \
     bnslr+; \
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
index cc2f804d86..9610edd305 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -3,11 +3,6 @@ abi-32-condition := __WORDSIZE == 32
 abi-64-v1-condition := __WORDSIZE == 64 && _CALL_ELF != 2
 abi-64-v2-condition := __WORDSIZE == 64 && _CALL_ELF == 2
 
-ifeq ($(subdir),rt)
-librt-routines += rt-sysdep
-librt-shared-only-routines += rt-sysdep
-endif
-
 ifeq ($(subdir),stdlib)
 gen-as-const-headers += ucontext_i.sym
 endif
@@ -31,8 +26,6 @@ tests += test-powerpc-linux-sysconf
 endif
 
 ifeq ($(subdir),nptl)
-libpthread-routines += sysdep
 libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \
 			      elision-trylock
-libpthread-shared-only-routines += sysdep
 endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S
index f3b960795e..8cbe17ef1e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S
@@ -46,6 +46,7 @@ ENTRY (__brk)
 	li	r3,0
 	blelr+
 	li      r3,ENOMEM
+	neg	r3,r3
 	b	__syscall_error@local
 END (__brk)
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
index ba0faaf69c..41e5e5fe2e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
@@ -83,10 +83,11 @@ L(parent):
 	lmw	r28,16(r1)
 	addi	r1,r1,32
 	bnslr+
+	neg	r3,r3
 	b	__syscall_error@local
 
 L(badargs):
-	li	r3,EINVAL
+	li	r3,-EINVAL
 	b	__syscall_error@local
 
 	cfi_startproc
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
index 9f65033b7e..c7c78d63c5 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
@@ -41,6 +41,7 @@ ENTRY (__getcontext)
 	li	r3,0
 	blr
 1:
+	neg	r3,r3
 	b	__syscall_error@local
 END(__getcontext)
 
@@ -69,6 +70,7 @@ compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3_3)
 	compat_text_section
 ENTRY (__getcontext_stub)
 	li	r3,ENOSYS
+	neg	r3,r3
 	b	__syscall_error@local
 END (__getcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
index 873edf14a8..43cc88cb9f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
@@ -216,7 +216,7 @@ compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__makecontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__makecontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/getcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/getcontext.S
index 3cbbd32c31..a2126f4627 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/getcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/getcontext.S
@@ -48,7 +48,7 @@ compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__getcontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__getcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/setcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/setcontext.S
index 5adf7fb5ba..b9f9c21b66 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/setcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/setcontext.S
@@ -48,7 +48,7 @@ compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__setcontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__setcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/swapcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/swapcontext.S
index e4aec0ff96..d7263e5fb8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/swapcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/swapcontext.S
@@ -48,7 +48,7 @@ compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__swapcontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__swapcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
index 7bcb2d990b..3cb5021917 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
@@ -42,6 +42,7 @@ ENTRY (__setcontext)
 	li	r3,0
 	blr
 1:
+	neg	r3,r3
 	b	__syscall_error@local
 END(__setcontext)
 
@@ -70,7 +71,7 @@ compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__setcontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__setcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
index cd359d4a8a..53190028c5 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
@@ -40,6 +40,7 @@ ENTRY (__swapcontext)
 	li	r3,0
 	blr
 1:
+	neg	r3,r3
 	b	__syscall_error@local
 END(__swapcontext)
 
@@ -68,7 +69,7 @@ compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3_3)
 
 	compat_text_section
 ENTRY (__swapcontext_stub)
-	li	r3,ENOSYS
+	li	r3,-ENOSYS
 	b	__syscall_error@local
 END (__swapcontext_stub)
 	.previous
diff --git a/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c b/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
deleted file mode 100644
index 3ff55952e2..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdep.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.c b/sysdeps/unix/sysv/linux/powerpc/sysdep.c
deleted file mode 100644
index 1bf5ea6f62..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (C) 1997-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.  */
-int
-__syscall_error (int err_no)
-{
-  __set_errno (err_no);
-  return -1;
-}
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
index b2bca598b9..31fa148ded 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_POWERPC_SYSDEP_H
 #define _LINUX_POWERPC_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/powerpc/sysdep.h>
 #include <tls.h>
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep.c b/sysdeps/unix/sysv/linux/sparc/sysdep.c
index f86414570d..1bf5ea6f62 100644
--- a/sysdeps/unix/sysv/linux/sparc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/sparc/sysdep.c
@@ -1 +1,27 @@
-#include <sysdeps/unix/sysv/linux/powerpc/sysdep.c>
+/* Copyright (C) 1997-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.  */
+int
+__syscall_error (int err_no)
+{
+  __set_errno (err_no);
+  return -1;
+}
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 10/23] linux: Use generic __syscall_error for sparc
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (8 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 09/23] linux: Use generic __syscall_error for powerpc Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 11/23] linux: Use generic __syscall_error for hppa Adhemerval Zanella
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

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 +
 .../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 +
 .../unix/sysv/linux/sparc/sparc64/sysdep.h    |  1 +
 sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S |  1 +
 sysdeps/unix/sysv/linux/sparc/sysdep.c        | 27 -------------------
 sysdeps/unix/sysv/linux/sparc/sysdep.h        |  2 ++
 12 files changed, 12 insertions(+), 35 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sysdep.c

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/sysdep.c
deleted file mode 100644
index 1bf5ea6f62..0000000000
--- a/sysdeps/unix/sysv/linux/sparc/sysdep.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (C) 1997-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.  */
-int
-__syscall_error (int err_no)
-{
-  __set_errno (err_no);
-  return -1;
-}
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sysdep.h
index aec4326cc9..8970ecc1ae 100644
--- a/sysdeps/unix/sysv/linux/sparc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sparc/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_SPARC_SYSDEP_H
 #define _LINUX_SPARC_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/sparc/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 11/23] linux: Use generic __syscall_error for hppa
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (9 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 10/23] linux: Use generic __syscall_error for sparc Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 12/23] linux: Use generic __syscall_error for arm Adhemerval Zanella
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

HPPA issues inline error handling for auto-generated syscall,
the __syscall_error is used solely on clone implementation and
it differs from generic implementation by passing positive errno
numbers.

Also, inline error handling does not really produce the most
compat code.

--- sizes-hppa-linux-gnu.outline
+++ sizes-hppa-linux-gnu.inline
    text           data     bss     dec     hex filename
-1576515          22028    9424 1607967  18891f libc.so
- 174755          15524     448  190727   2e907 elf/ld.so
- 132799           1296    8364  142459   22c7b nptl/libpthread.so
-  30993            788     236   32017    7d11 rt/librt.so
+1579367          22028    9424 1610819  189443 libc.so
+ 174835          15524     448  190807   2e957 elf/ld.so
+ 133055           1296    8364  142715   22d7b nptl/libpthread.so
+  31297            788     236   32321    7e41 rt/librt.so

Checked on hppa-linux-gnu.
---
 sysdeps/unix/sysv/linux/hppa/clone.S  |  6 ++++--
 sysdeps/unix/sysv/linux/hppa/sysdep.c | 27 ---------------------------
 sysdeps/unix/sysv/linux/hppa/sysdep.h |  2 ++
 3 files changed, 6 insertions(+), 29 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/hppa/sysdep.c

diff --git a/sysdeps/unix/sysv/linux/hppa/clone.S b/sysdeps/unix/sysv/linux/hppa/clone.S
index 4eda812dd0..fcfafe1d2b 100644
--- a/sysdeps/unix/sysv/linux/hppa/clone.S
+++ b/sysdeps/unix/sysv/linux/hppa/clone.S
@@ -124,7 +124,8 @@ ENTRY(__clone)
 .LerrorRest:
 	/* Something bad happened -- no child created */
 	bl	__syscall_error, %rp
-	sub     %r0, %ret0, %arg0
+	 copy    %ret0, %arg0
+
 	ldw	-84(%sp), %rp
 	/* Return after setting errno, ret0 is set to -1 by __syscall_error. */
 	bv	%r0(%rp)
@@ -133,7 +134,8 @@ ENTRY(__clone)
 .LerrorSanity:
 	/* Sanity checks failed, return -1, and set errno to EINVAL. */
 	bl	__syscall_error, %rp
-	ldi     EINVAL, %arg0
+	 ldi     -EINVAL, %arg0
+
 	ldw	-84(%sp), %rp
 	bv	%r0(%rp)
 	ldwm	-64(%sp), %r4
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.c b/sysdeps/unix/sysv/linux/hppa/sysdep.c
deleted file mode 100644
index 8c06b6fc80..0000000000
--- a/sysdeps/unix/sysv/linux/hppa/sysdep.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (C) 1997-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.  */
-int
-__syscall_error (int err_no)
-{
-  __set_errno (err_no);
-  return -1;
-}
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.h b/sysdeps/unix/sysv/linux/hppa/sysdep.h
index 531fe2beed..a1165da81e 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep.h
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep.h
@@ -21,6 +21,8 @@
 #ifndef _LINUX_HPPA_SYSDEP_H
 #define _LINUX_HPPA_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/hppa/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 12/23] linux: Use generic __syscall_error for arm
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (10 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 11/23] linux: Use generic __syscall_error for hppa Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 13/23] linux: Use generic __syscall_error for x86_64 Adhemerval Zanella
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The auto-generated syscalls issue the __syscall_erro and the ARM
resulting binary using inline __syscall_error results in a large
code size:

--- sizes-arm-linux-gnueabihf.outline
+++ sizes-arm-linux-gnueabihf.inline
@@ -1,5 +1,5 @@
    text           data     bss     dec     hex filename
-1260061           9912    9256 1279229  1384fd libc.so
- 143107           4336     208  147651   240c3 elf/ld.so
-  97335            844    8352  106531   1a023 nptl/libpthread.so
-  22516            656     160   23332    5b24 rt/librt.so
+1265565           9912    9256 1284733  139a7d libc.so
+ 143491           4336     208  148035   24243 elf/ld.so
+  98103            844    8352  107299   1a323 nptl/libpthread.so
+  22996            656     160   23812    5d04 rt/librt.so

The assembly sysdep.S is replaced the by the generic syscall_error.c.

Checked on arm-linux-gnueabihf.
---
 sysdeps/unix/arm/sysdep.S            | 62 ----------------------------
 sysdeps/unix/sysv/linux/arm/sysdep.S | 33 ---------------
 sysdeps/unix/sysv/linux/arm/sysdep.h |  2 +
 3 files changed, 2 insertions(+), 95 deletions(-)
 delete mode 100644 sysdeps/unix/arm/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/arm/sysdep.S

diff --git a/sysdeps/unix/arm/sysdep.S b/sysdeps/unix/arm/sysdep.S
deleted file mode 100644
index 5c9022a869..0000000000
--- a/sysdeps/unix/arm/sysdep.S
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Copyright (C) 1991-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>
-
-#if IS_IN (rtld)
-# include <dl-sysdep.h>			/* Defines RTLD_PRIVATE_ERRNO.  */
-#endif
-
-#include <tls.h>
-
-#undef 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	r0, $EWOULDBLOCK_sys /* Is it the old EWOULDBLOCK?  */
-	it	eq
-	moveq	r0, $EAGAIN	/* Yes; translate it to EAGAIN.  */
-#endif
-
-#if !IS_IN (rtld)
-	mov	r1, r0
-	GET_TLS (r2)
-	ldr	r2, 1f
-#ifdef __thumb__
-2:	add	r2, r2, pc
-	ldr	r2, [r2]
-#else
-2:	ldr	r2, [pc, r2]
-#endif
-	str	r1, [r0, r2]
-	mvn	r0, #0
-	DO_RET(lr)
-
-1:	.word errno(gottpoff) + (. - 2b - PC_OFS)
-#elif RTLD_PRIVATE_ERRNO
-	LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno))
-	mvn	r0, #0
-	DO_RET(r14)
-#else
-#error "Unsupported non-TLS case"
-#endif
-
-#undef	__syscall_error
-END (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.S b/sysdeps/unix/sysv/linux/arm/sysdep.S
deleted file mode 100644
index 94c877b31d..0000000000
--- a/sysdeps/unix/sysv/linux/arm/sysdep.S
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright (C) 1995-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>
-
-	.text
-
-/* 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 R0 is negated.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers R0.  */
-
-ENTRY (__syscall_error)
-	rsb r0, r0, $0
-
-#define __syscall_error __syscall_error_1
-#include <sysdeps/unix/arm/sysdep.S>
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h
index e2985cffd7..b771db4508 100644
--- a/sysdeps/unix/sysv/linux/arm/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arm/sysdep.h
@@ -20,6 +20,8 @@
 #ifndef _LINUX_ARM_SYSDEP_H
 #define _LINUX_ARM_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/arm/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 13/23] linux: Use generic __syscall_error for x86_64
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (11 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 12/23] linux: Use generic __syscall_error for arm Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 14/23] linux: Use generic __syscall_error for s390 Adhemerval Zanella
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

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


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 14/23] linux: Use generic __syscall_error for s390
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (12 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 13/23] linux: Use generic __syscall_error for x86_64 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 15/23] linux: Use generic __syscall_error for sh Adhemerval Zanella
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The auto-generated syscalls issue the __syscall_error only for
static objects, so an arch specific syscall_error is added.  However
the size of using inline __syscall_error is slight better even for
static case:

--- size-fstatat64.inline
+++ size-fstatat64.outline
@@ -1,2 +1,2 @@
    text           data     bss     dec     hex filename
-    120              0       0     120      78 io/fstatat64.o
+    128              0       0     128      80 io/fstatat64.o

For shared objects the inline syscall generates slight large code
(specially for libc.so).

--- sizes-s390x-linux-gnu.outline
+++ sizes-s390x-linux-gnu.inline
    text           data     bss     dec     hex filename
-1755806          20232   14544 1790582  1b5276 libc.so
- 169705           6696     336  176737   2b261 elf/ld.so
- 111982           1664   16680  130326   1fd16 nptl/libpthread.so
-  29703           1132    2296   33131    816b rt/librt.so
+1756334          20232   14544 1791110  1b5486 libc.so
+ 169385           6696     336  176417   2b121 elf/ld.so
+ 112198           1664   16680  130542   1fdee nptl/libpthread.so
+  29719           1132    2296   33147    817b rt/librt.so

Checked on s390x-linux-gnu and s390-linux-gnu.
---
 sysdeps/s390/nptl/Makefile                    |  5 --
 sysdeps/unix/sysv/linux/s390/Makefile         |  5 --
 sysdeps/unix/sysv/linux/s390/rt-sysdep.S      |  1 -
 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S | 74 ------------------
 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S | 75 -------------------
 sysdeps/unix/sysv/linux/s390/syscall_error.c  |  5 ++
 6 files changed, 5 insertions(+), 160 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/s390/rt-sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/s390/syscall_error.c

diff --git a/sysdeps/s390/nptl/Makefile b/sysdeps/s390/nptl/Makefile
index d34cb27699..7869dd571c 100644
--- a/sysdeps/s390/nptl/Makefile
+++ b/sysdeps/s390/nptl/Makefile
@@ -18,8 +18,3 @@
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
-
-ifeq ($(subdir),nptl)
-libpthread-routines += sysdep
-libpthread-shared-only-routines += sysdep
-endif
diff --git a/sysdeps/unix/sysv/linux/s390/Makefile b/sysdeps/unix/sysv/linux/s390/Makefile
index d9db1b5422..0d88f8d7ff 100644
--- a/sysdeps/unix/sysv/linux/s390/Makefile
+++ b/sysdeps/unix/sysv/linux/s390/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),stdlib)
 gen-as-const-headers += ucontext_i.sym
 endif
diff --git a/sysdeps/unix/sysv/linux/s390/rt-sysdep.S b/sysdeps/unix/sysv/linux/s390/rt-sysdep.S
deleted file mode 100644
index f966bf1e59..0000000000
--- a/sysdeps/unix/sysv/linux/s390/rt-sysdep.S
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdep.S>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
deleted file mode 100644
index f8a6b7901d..0000000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
-   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 <tls.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.  */
-
-/* The syscall stubs jump here when they detect an error.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT
-
-	.text
-ENTRY(__syscall_error)
-#ifndef PIC
-# if IS_IN (libc)
-#  define SYSCALL_ERROR_ERRNO __libc_errno
-# else
-#  define SYSCALL_ERROR_ERRNO errno
-# endif
-	basr	%r1,0
-0:	l	%r1,1f-0b(%r1)
-	ear	%r3,%a0
-	lcr	%r2,%r2
-	st	%r2,0(%r1,%r3)
-	lhi	%r2,-1
-	br	%r14
-1:	.long	SYSCALL_ERROR_ERRNO@ntpoff
-#else
-# if RTLD_PRIVATE_ERRNO
-	basr	%r1,0
-0:	al	%r1,1f-0b(%r1)
-	lcr	%r2,%r2
-	st	%r2,0(%r1)
-	lhi	%r2,-1
-	br	%r14
-1:	.long	rtld_errno - 0b
-# else
-#  if IS_IN (libc)
-#   define SYSCALL_ERROR_ERRNO __libc_errno
-#  else
-#   define SYSCALL_ERROR_ERRNO errno
-#  endif
-	basr	%r1,0
-0:	al	%r1,1f-0b(%r1)
-	ear	%r3,%a0
-	l	%r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1)
-	lcr	%r2,%r2
-	st	%r2,0(%r1,%r3)
-	lhi	%r2,-1
-	br	%r14
-1:	.long	_GLOBAL_OFFSET_TABLE_-0b
-# endif
-#endif
-
-END (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
deleted file mode 100644
index 98c8dd3913..0000000000
--- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (C) 2001-2020 Free Software Foundation, Inc.
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
-   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 <tls.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.  */
-
-/* The syscall stubs jump here when they detect an error.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT
-
-.text
-ENTRY(__syscall_error)
-#ifndef PIC
-# if IS_IN (libc)
-#  define SYSCALL_ERROR_ERRNO __libc_errno
-# else
-#  define SYSCALL_ERROR_ERRNO errno
-# endif
-	basr	%r1,0
-0:	lg	%r1,1f-0b(%r1)
-	ear	%r3,%a0
-	sllg	%r3,%r3,32
-	ear	%r3,%a1
-	lcr	%r2,%r2
-	st	%r2,0(%r1,%r3)
-	lghi	%r2,-1
-	br	%r14
-1:	.quad	SYSCALL_ERROR_ERRNO@ntpoff
-#else
-# if RTLD_PRIVATE_ERRNO
-	larl	%r1,rtld_errno
-	lcr	%r2,%r2
-	st	%r2,0(%r1)
-	lghi	%r2,-1
-	br	%r14
-# else
-#  if IS_IN (libc)
-#   define SYSCALL_ERROR_ERRNO __libc_errno
-#  else
-#   define SYSCALL_ERROR_ERRNO errno
-#  endif
-	larl	%r1,_GLOBAL_OFFSET_TABLE_
-	lg	%r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1)
-	ear	%r3,%a0
-	sllg	%r3,%r3,32
-	ear	%r3,%a1
-	lcr	%r2,%r2
-	st	%r2,0(%r1,%r3)
-	lghi	%r2,-1
-	br	%r14
-# endif
-#endif
-
-END (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/s390/syscall_error.c b/sysdeps/unix/sysv/linux/s390/syscall_error.c
new file mode 100644
index 0000000000..40528f8ae9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/s390/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>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 15/23] linux: Use generic __syscall_error for sh
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (13 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 14/23] linux: Use generic __syscall_error for s390 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 16/23] linux: Use generic __syscall_error for microblaze Adhemerval Zanella
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Although the auto-generated syscall sets errno directly for dynamic
case, using a function call generates more compact code:

--- sizes-sh4-linux-gnu.outline
+++ sizes-sh4-linux-gnu.inline

    text           data     bss     dec     hex filename
-1242446           9948    9240 1261634  134042 libc.so
- 122480           3764     176  126420   1edd4 elf/ld.so
-  91548            804    8348  100700   1895c nptl/libpthread.so
-  23613            608     160   24381    5f3d rt/librt.so
+1244638           9948    9240 1263826  1348d2 libc.so
+ 122416           3764     176  126356   1ed94 elf/ld.so
+  91460            804    8348  100612   18904 nptl/libpthread.so
+  23805            608     160   24573    5ffd rt/librt.so

It also removes the PLT call done by the generic unix syscall.S
which calls __errno_location instead of the accessing it directly
(as done by C implementation through syscall_error.c).

Checked with some basic tests to see if errno is set correctly
on both static and dynamic binaries with auto-generated syscals
and C implementation (which uses INTERNAL_SYSCALL_CALL).
---
 sysdeps/unix/sh/sysdep.S                 | 115 -----------------------
 sysdeps/unix/sysv/linux/sh/localplt.data |   1 -
 sysdeps/unix/sysv/linux/sh/sysdep.S      |  32 -------
 sysdeps/unix/sysv/linux/sh/sysdep.h      |   2 +
 4 files changed, 2 insertions(+), 148 deletions(-)
 delete mode 100644 sysdeps/unix/sh/sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/sh/sysdep.S

diff --git a/sysdeps/unix/sh/sysdep.S b/sysdeps/unix/sh/sysdep.S
deleted file mode 100644
index dc9a230ee0..0000000000
--- a/sysdeps/unix/sh/sysdep.S
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (C) 1999-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>
-
-ENTRY(__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.  */
-	mov.l	.L1, r1
-	cmp/eq	r1, r0
-	bf	skip
-	nop
-	mov.l	.L2, r0
-skip:
-#endif
-	/* Store it in errno... */
-#ifndef SHARED
-#ifndef _LIBC_REENTRANT
-	mov.l	.L3, r1
-	mov.l	r0, @r1
-#else
-	mov.l	.L3, r1
-	sts.l	pr, @-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (pr, 0)
-	mov.l	r0, @-r15
-	cfi_adjust_cfa_offset (4)
-	jsr	@r1
-	 nop
-	mov.l	@r15+, r1
-	cfi_adjust_cfa_offset (-4)
-	lds.l	@r15+, pr
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (pr)
-	mov.l	r1, @r0
-#endif
-#else
-	mov.l	r12, @-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (r12, 0)
-#ifndef _LIBC_REENTRANT
-	mov	r0, r2
-        mov.l	0f, r12
-	mova	0f, r0
-	add	r0, r12
-	mov.l	.L3, r0
-	mov.l	@(r0,r12), r1
-	mov.l	r2, @r1
-#else
-	mov.l	r0, @-r15
-	cfi_adjust_cfa_offset (4)
-	sts.l	pr, @-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (pr, 0)
-        mov.l	0f, r12
-	mova	0f, r0
-	add	r0, r12
-	mov.l	.L3, r1
-	mova	.L3, r0
-	add	r0, r1
-	jsr	@r1
-	 nop
-	lds.l	@r15+, pr
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (pr)
-	mov.l	@r15+, r1
-	cfi_adjust_cfa_offset (-4)
-	mov.l	r1, @r0
-#endif
-	mov.l	@r15+, r12
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (r12)
-#endif
-	/* And just kick back a -1.  */
-	rts
-	 mov	#-1, r0
-
-	.align	2
-#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
-.L1:	.long	EWOULDBLOCK_sys
-.L2:	.long	EAGAIN
-#endif
-#ifndef SHARED
-#ifndef _LIBC_REENTRANT
-.L3:	.long	C_SYMBOL_NAME(errno)
-#else
-.L3:	.long	C_SYMBOL_NAME(__errno_location)
-#endif
-#else
-0:
-	.long	_GLOBAL_OFFSET_TABLE_
-#ifndef _LIBC_REENTRANT
-.L3:	.long	C_SYMBOL_NAME(errno@GOT)
-#else
-.L3:	.long	C_SYMBOL_NAME(__errno_location@PLT)
-#endif
-#endif
-END(__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/sh/localplt.data b/sysdeps/unix/sysv/linux/sh/localplt.data
index 3225177c50..9d8154648b 100644
--- a/sysdeps/unix/sysv/linux/sh/localplt.data
+++ b/sysdeps/unix/sysv/linux/sh/localplt.data
@@ -8,7 +8,6 @@ libc.so: memalign
 libc.so: realloc
 libc.so: _Unwind_Find_FDE
 libc.so: _exit
-libc.so: __errno_location
 libm.so: matherr
 # Generated by the compiler because there is no trap insn pattern.
 libc.so: abort ?
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep.S b/sysdeps/unix/sysv/linux/sh/sysdep.S
deleted file mode 100644
index 85ff3f900e..0000000000
--- a/sysdeps/unix/sysv/linux/sh/sysdep.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (C) 1995-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 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 R0 is negated.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers R0.  */
-
-ENTRY (__syscall_error)
-	neg r4, r0
-	cfi_endproc
-
-#define __syscall_error __syscall_error_1
-#include <sysdeps/unix/sh/sysdep.S>
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep.h b/sysdeps/unix/sysv/linux/sh/sysdep.h
index 60a5032ce4..511406b5dc 100644
--- a/sysdeps/unix/sysv/linux/sh/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sh/sysdep.h
@@ -20,6 +20,8 @@
 #ifndef _LINUX_SH_SYSDEP_H
 #define _LINUX_SH_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/sh/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 16/23] linux: Use generic __syscall_error for microblaze
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (14 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 15/23] linux: Use generic __syscall_error for sh Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 17/23] linux: Use generic __syscall_error for ia64 Adhemerval Zanella
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Although the auto-generated syscall sets errno directly for dynamic
case, using a function call generates more compact code:

--- sizes-microblaze-linux-gnu.inline
+++ sizes-microblaze-linux-gnu.outline
    text           data     bss     dec     hex filename
-1835305          52738    9216 1897259  1cf32b libc.so
- 188644           7236     176  196056   2fdd8 elf/ld.so
- 121772           5872    8356  136000   21340 nptl/libpthread.so
-  30836           1724     160   32720    7fd0 rt/librt.so
+1831025          52714    9216 1892955  1ce25b libc.so
+ 188904           7240     176  196320   2fee0 elf/ld.so
+ 121540           5864    8356  135760   21250 nptl/libpthread.so
+  30640           1720     160   32520    7f08 rt/librt.so

Checked with a cross make check for microblaze-linux-gnu.
---
 sysdeps/unix/sysv/linux/microblaze/Makefile |  6 ----
 sysdeps/unix/sysv/linux/microblaze/sysdep.S | 39 ---------------------
 sysdeps/unix/sysv/linux/microblaze/sysdep.h |  2 ++
 3 files changed, 2 insertions(+), 45 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/microblaze/sysdep.S

diff --git a/sysdeps/unix/sysv/linux/microblaze/Makefile b/sysdeps/unix/sysv/linux/microblaze/Makefile
index d178bc6f34..614553204f 100644
--- a/sysdeps/unix/sysv/linux/microblaze/Makefile
+++ b/sysdeps/unix/sysv/linux/microblaze/Makefile
@@ -1,9 +1,3 @@
 ifeq ($(subdir),resource)
 sysdep_routines += backtrace_linux
 endif
-
-ifeq ($(subdir),nptl)
-# pull in __syscall_error routine
-libpthread-routines += sysdep
-libpthread-shared-only-routines += sysdep
-endif
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.S b/sysdeps/unix/sysv/linux/microblaze/sysdep.S
deleted file mode 100644
index c3157880d8..0000000000
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep.S
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (C) 2009-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.  */
-
-# undef CALL_MCOUNT
-# define CALL_MCOUNT /* Don't insert the profiling call, it clobbers %d0.  */
-
-	.text
-ENTRY (__syscall_error)
-	rsubk	r3,r3,r0
-	rtsd	r15,8
-	addik	r3,r0,-1	/* delay slot.  */
-END (__syscall_error)
-#endif /* PIC.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
index 6fd96adbf0..2beaba9247 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_MICROBLAZE_SYSDEP_H
 #define _LINUX_MICROBLAZE_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/microblaze/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 17/23] linux: Use generic __syscall_error for ia64
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (15 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 16/23] linux: Use generic __syscall_error for microblaze Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 18/23] linux: Use generic __syscall_error for m68k Adhemerval Zanella
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Although the auto-generated syscall issues __syscall_errno, using
an inline function generates much more compact code:

--- sizes-ia64-linux-gnu.inline
+++ sizes-ia64-linux-gnu.outline
    text           data     bss     dec     hex filename
-2940053          20776   14424 2975253  2d6615 libc.so
- 301887          23190    1968  327045   4fd85 elf/ld.so
- 203203           2472   16640  222315   3646b nptl/libpthread.so
-  47153           1764    2272   51189    c7f5 rt/librt.so
+2947445          20776   14424 2982645  2d82f5 libc.so
+ 302591          23190    1968  327749   50045 elf/ld.so
+ 204987           2472   16640  224099   36b63 nptl/libpthread.so
+  47609           1764    2272   51645    c9bd rt/librt.so

Checked with a cross make check for ia64-linux-gnu.
---
 sysdeps/ia64/nptl/Makefile                   |  5 --
 sysdeps/unix/sysv/linux/ia64/Makefile        |  5 --
 sysdeps/unix/sysv/linux/ia64/rt-sysdep.S     |  1 -
 sysdeps/unix/sysv/linux/ia64/syscall_error.c |  3 +
 sysdeps/unix/sysv/linux/ia64/sysdep.S        | 58 --------------------
 5 files changed, 3 insertions(+), 69 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_error.c
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/sysdep.S

diff --git a/sysdeps/ia64/nptl/Makefile b/sysdeps/ia64/nptl/Makefile
index d34cb27699..7869dd571c 100644
--- a/sysdeps/ia64/nptl/Makefile
+++ b/sysdeps/ia64/nptl/Makefile
@@ -18,8 +18,3 @@
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
-
-ifeq ($(subdir),nptl)
-libpthread-routines += sysdep
-libpthread-shared-only-routines += sysdep
-endif
diff --git a/sysdeps/unix/sysv/linux/ia64/Makefile b/sysdeps/unix/sysv/linux/ia64/Makefile
index 97fc7df0b1..57917e78db 100644
--- a/sysdeps/unix/sysv/linux/ia64/Makefile
+++ b/sysdeps/unix/sysv/linux/ia64/Makefile
@@ -17,11 +17,6 @@ ifeq ($(subdir),elf)
 sysdep-dl-routines += dl-static
 endif
 
-ifeq ($(subdir),rt)
-librt-routines += rt-sysdep
-librt-shared-only-routines += rt-sysdep
-endif
-
 ifeq ($(subdir),nptl)
 libpthread-sysdep_routines += __ia64_longjmp unwind_longjmp __sigstack_longjmp
 endif
diff --git a/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S b/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
deleted file mode 100644
index f966bf1e59..0000000000
--- a/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdep.S>
diff --git a/sysdeps/unix/sysv/linux/ia64/syscall_error.c b/sysdeps/unix/sysv/linux/ia64/syscall_error.c
new file mode 100644
index 0000000000..60fa99a158
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ia64/syscall_error.c
@@ -0,0 +1,3 @@
+/* The auto-generated syscalls calls __syscall_error.  */
+#define SYSCALL_ERROR_FUNC
+#include <sysdeps/unix/sysv/linux/syscall_error.c>
diff --git a/sysdeps/unix/sysv/linux/ia64/sysdep.S b/sysdeps/unix/sysv/linux/ia64/sysdep.S
deleted file mode 100644
index 75fc3d6456..0000000000
--- a/sysdeps/unix/sysv/linux/ia64/sysdep.S
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Copyright (C) 1999-2020 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
-
-   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 <features.h>
-#include <tls.h>
-
-ENTRY(__syscall_error)
-#if RTLD_PRIVATE_ERRNO
-	/*
-	 * Note that the gp has to be set properly for this to work.
-	 * As long as all syscalls are in the same load unit
-	 * (executable or shared library) as this routine, we should
-	 * be fine.  Otherwise, we would have to first load the global
-	 * pointer register from __gp.
-	 */
-	addl	r2=@gprel(rtld_errno),gp
-	;;
-	st4	[r2]=r8
-	mov	r8=-1
-#else
-# if IS_IN (libc)
-#  define SYSCALL_ERROR_ERRNO __libc_errno
-# else
-#  define SYSCALL_ERROR_ERRNO errno
-# endif
-	addl	r2=@ltoff(@tprel(SYSCALL_ERROR_ERRNO)), gp;;
-	ld8	r2=[r2]
-	mov	r3=r8;;
-	mov	r8=-1
-	add	r2=r2,r13;;
-	st4	[r2]=r3
-#endif
-	ret			// ret is #define'd in syscall.h!
-END(__syscall_error)
-
-ENTRY(__ia64_syscall)
-	mov r15=r37		/* syscall number */
-	break __IA64_BREAK_SYSCALL
-	cmp.eq p6,p0=-1,r10	/* r10 = -1 on error */
-(p6)	br.cond.spnt.few __syscall_error
-	ret
-PSEUDO_END(__ia64_syscall)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 18/23] linux: Use generic __syscall_error for m68k
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (16 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 17/23] linux: Use generic __syscall_error for ia64 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 19/23] linux: Use generic __syscall_error for csky Adhemerval Zanella
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Although the auto-generated syscall sets errno directly for dynamic
case, using a function call generates more compact code:

--- sizes-m68k-linux-gnu.inline
+++ sizes-m68k-linux-gnu.outline
    text           data     bss     dec     hex filename
-1283686          20376    9304 1313366  140a56 libc.so
- 119206           5960     184  125350   1e9a6 elf/ld.so
-  87078           1456    8360   96894   17a7e nptl/libpthread.so
-  23918            888     160   24966    6186 rt/librt.so
+1277602          20376    9304 1307282  13f292 libc.so
+ 119174           5960     184  125318   1e986 elf/ld.so
+  86314           1456    8360   96130   17782 nptl/libpthread.so
+  23562            888     160   24610    6022 rt/librt.so

Checked with some basic tests to see if errno is set correctly
on both static and dynamic binaries with auto-generated syscals
and C implementation (which uses INTERNAL_SYSCALL_CALL).
---
 sysdeps/unix/sysv/linux/m68k/sysdep.S | 50 ---------------------------
 sysdeps/unix/sysv/linux/m68k/sysdep.h | 11 +++---
 2 files changed, 6 insertions(+), 55 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/m68k/sysdep.S

diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep.S b/sysdeps/unix/sysv/linux/m68k/sysdep.S
deleted file mode 100644
index 1313ab17c3..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/sysdep.S
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright (C) 1996-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.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers %d0.  */
-
-	.text
-ENTRY (__syscall_error)
-	neg.l %d0
-#ifndef _LIBC_REENTRANT
-	move.l %d0, errno
-#else
-	move.l %d0, -(%sp)
-	cfi_adjust_cfa_offset (4)
-	jbsr __errno_location
-	move.l (%sp)+, (%a0)
-	cfi_adjust_cfa_offset (-4)
-#endif
-	move.l #-1, %d0
-	/* Copy return value to %a0 for syscalls that are declared to
-	   return a pointer.  */
-	move.l %d0, %a0
-	rts
-END (__syscall_error)
-#endif /* PIC */
diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep.h b/sysdeps/unix/sysv/linux/m68k/sysdep.h
index 3e0ab605de..2f59c0a2f4 100644
--- a/sysdeps/unix/sysv/linux/m68k/sysdep.h
+++ b/sysdeps/unix/sysv/linux/m68k/sysdep.h
@@ -17,6 +17,8 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <tls.h>
 
@@ -45,11 +47,7 @@
 /* We don't want the label for the error handler to be visible in the symbol
    table when we define it here.  */
 #undef SYSCALL_ERROR_LABEL
-#ifdef PIC
 #define SYSCALL_ERROR_LABEL .Lsyscall_error
-#else
-#define SYSCALL_ERROR_LABEL __syscall_error
-#endif
 
 #undef PSEUDO
 #define	PSEUDO(name, syscall_name, args)				      \
@@ -137,7 +135,10 @@ SYSCALL_ERROR_LABEL:							      \
     rts;
 # endif /* _LIBC_REENTRANT */
 #else
-# define SYSCALL_ERROR_HANDLER	/* Nothing here; code in sysdep.S is used.  */
+# define SYSCALL_ERROR_HANDLER						      \
+SYSCALL_ERROR_LABEL:							      \
+    move.l %d0,4(%sp);							      \
+    bra.l __syscall_error
 #endif /* PIC */
 
 /* Linux takes system call arguments in registers:
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 19/23] linux: Use generic __syscall_error for csky
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (17 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 18/23] linux: Use generic __syscall_error for m68k Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 20/23] linux: Use generic __syscall_error for riscv Adhemerval Zanella
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Although the auto-generated syscall issue __syscall_error, using
an inline function generates slight more compact code:

--- sizes-csky-linux-gnuabiv2-soft.outline
+++ sizes-csky-linux-gnuabiv2-soft.inline
    text           data     bss     dec     hex filename
-1210010          10408    9212 1229630  12c33e libc.so
- 121439           3876     184  125499   1ea3b elf/ld.so
-  93074            920    8348  102342   18fc6 nptl/libpthread.so
-  24971            648     156   25775    64af rt/librt.so
+1209202          10408    9212 1228822  12c016 libc.so
+ 121171           3876     184  125231   1e92f elf/ld.so
+  93630            920    8348  102898   191f2 nptl/libpthread.so
+  24967            648     156   25771    64ab rt/librt.so

Checked with a cross make check for csky-linux-gnuabiv2-soft.
---
 sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S | 65 ---------------------
 sysdeps/unix/sysv/linux/csky/sysdep.h       |  2 +
 2 files changed, 2 insertions(+), 65 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S

diff --git a/sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S b/sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S
deleted file mode 100644
index fe6b600bdc..0000000000
--- a/sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S
+++ /dev/null
@@ -1,65 +0,0 @@
-/* syscall error handlers.  C-SKY ABIV2 version.
-   Copyright (C) 2018-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 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 R0 is negated.  */
-
-#undef CALL_MCOUNT
-#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers R0.  */
-
-	.text
-ENTRY (__syscall_error)
-	movi	a1, 0
-	rsub	a0, a0, a1
-
-#if !IS_IN (rtld)
-	mov	a1, a0
-	mov	a0, tls
-
-	grs	t1, .Lgetpc1
-.Lgetpc1:
-	lrw	t0, errno@gottpoff
-	add	t1, t1, t0
-	ldw	t1, (t1)
-	add	t1, a0
-	stw	a1, (t1)
-	bmaski	a0, 0
-	rts
-#elif RTLD_PRIVATE_ERRNO /* !IS_IN (rtld) */
-# ifdef  __PIC__
-	grs	t1, .Lgetpc2
-.Lgetpc2:
-	lrw	t0, .Lgetpc2@GOTPC
-	addu	t1, t1, t0
-	lrw	t0, rtld_errno@PLT
-	ldr.w	t0, (t1, t0 << 0)
-# else
-	lrw	t0, rtld_errno
-# endif /* __PIC__ */
-	stw	a0, (t0)
-	bmaski	a0, 0
-	rts
-#else
-# error "Unsupported non-TLS case"
-#endif /* RTLD_PRIVATE_ERRNO */
-
-#undef __syscall_error
-END (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/csky/sysdep.h b/sysdeps/unix/sysv/linux/csky/sysdep.h
index 7e8e89dd42..c8a7dd77ad 100644
--- a/sysdeps/unix/sysv/linux/csky/sysdep.h
+++ b/sysdeps/unix/sysv/linux/csky/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_CSKY_SYSDEP_H
 #define _LINUX_CSKY_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
 #include <sysdeps/unix/sysv/linux/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 20/23] linux: Use generic __syscall_error for riscv
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (18 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 19/23] linux: Use generic __syscall_error for csky Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 21/23] linux: Use generic __syscall_error for nios2 Adhemerval Zanella
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The outline __syscall_error already generate the most compact
code for riscv64 and riscv32:

--- sizes-riscv32-linux-gnu-rv32imafdc-ilp32d.outline
+++ sizes-riscv32-linux-gnu-rv32imafdc-ilp32d.inline
    text           data     bss     dec     hex filename
- 973220           9460    8840  991520   f2120 libc.so
-  98209           4124     176  102509   1906d elf/ld.so
-  71063            800    8348   80211   13953 nptl/libpthread.so
-  17011            608     168   17787    457b rt/librt.so
+ 974466           9460    8840  992766   f25fe libc.so
+  98331           4124     176  102631   190e7 elf/ld.so
+  70939            800    8348   80087   138d7 nptl/libpthread.so
+  17095            608     168   17871    45cf rt/librt.so

--- sizes-riscv64-linux-gnu-rv64imafdc-lp64d.outline
+++ sizes-riscv64-linux-gnu-rv64imafdc-lp64d.inline
    text           data     bss     dec     hex filename
-1030902          18632   14472 1064006  103c46 libc.so
-  98320           6232     336  104888   199b8 elf/ld.so
-  76588           1596   16664   94848   17280 nptl/libpthread.so
-  18016           1156     232   19404    4bcc rt/librt.so
+1031680          18632   14472 1064784  103f50 libc.so
+  98374           6232     336  104942   199ee elf/ld.so
+  76544           1596   16664   94804   17254 nptl/libpthread.so
+  18106           1156     232   19494    4c26 rt/librt.so

Checked with some basic tests to see if errno is set correctly
on both static and dynamic binaries with auto-generated syscals
and C implementation (which uses INTERNAL_SYSCALL_CALL).
---
 sysdeps/riscv/nptl/Makefile            |  5 ---
 sysdeps/riscv/nptl/nptl-sysdep.S       |  2 -
 sysdeps/unix/sysv/linux/riscv/sysdep.S | 51 --------------------------
 sysdeps/unix/sysv/linux/riscv/sysdep.h |  2 +
 4 files changed, 2 insertions(+), 58 deletions(-)
 delete mode 100644 sysdeps/riscv/nptl/nptl-sysdep.S
 delete mode 100644 sysdeps/unix/sysv/linux/riscv/sysdep.S

diff --git a/sysdeps/riscv/nptl/Makefile b/sysdeps/riscv/nptl/Makefile
index 1af6fa6a55..3f6428b0de 100644
--- a/sysdeps/riscv/nptl/Makefile
+++ b/sysdeps/riscv/nptl/Makefile
@@ -19,8 +19,3 @@
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
-
-ifeq ($(subdir),nptl)
-libpthread-sysdep_routines += nptl-sysdep
-libpthread-shared-only-routines += nptl-sysdep
-endif
diff --git a/sysdeps/riscv/nptl/nptl-sysdep.S b/sysdeps/riscv/nptl/nptl-sysdep.S
deleted file mode 100644
index 3f5c2a364a..0000000000
--- a/sysdeps/riscv/nptl/nptl-sysdep.S
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Pull in __syscall_error.  */
-#include <sysdep.S>
diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.S b/sysdeps/unix/sysv/linux/riscv/sysdep.S
deleted file mode 100644
index 64daa84aac..0000000000
--- a/sysdeps/unix/sysv/linux/riscv/sysdep.S
+++ /dev/null
@@ -1,51 +0,0 @@
-/* syscall error handlers
-   Copyright (C) 2011-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>
-
-#if IS_IN (libc)
-# define errno __libc_errno
-#endif
-
-ENTRY (__syscall_error)
-	mv t0, ra
-	/* Fall through to __syscall_set_errno.  */
-END (__syscall_error)
-
-/* Non-standard calling convention: argument in a0, return address in t0,
-   and clobber only t1.  */
-ENTRY (__syscall_set_errno)
-	/* We got here because a0 < 0, but only codes in the range [-4095, -1]
-	  represent errors.  Otherwise, just return the result normally.  */
-	li t1, -4096
-	bleu a0, t1, 1f
-	neg a0, a0
-#if RTLD_PRIVATE_ERRNO
-	sw a0, rtld_errno, t1
-#elif defined(__PIC__)
-	la.tls.ie t1, errno
-	add t1, t1, tp
-	sw a0, 0(t1)
-#else
-	lui t1, %tprel_hi(errno)
-	add t1, t1, tp, %tprel_add(errno)
-	sw a0, %tprel_lo(errno)(t1)
-#endif
-	li a0, -1
-1:	jr t0
-END (__syscall_set_errno)
diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
index e94afbf106..1bcd942e31 100644
--- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
+++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_RISCV_SYSDEP_H
 #define _LINUX_RISCV_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
 #include <tls.h>
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 21/23] linux: Use generic __syscall_error for nios2
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (19 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 20/23] linux: Use generic __syscall_error for riscv Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 22/23] linux: Use generic __syscall_error for alpha Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 23/23] linux: Use generic __syscall_error for mips Adhemerval Zanella
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The usage of __syscall_error function on dynamic objects only
increases the total size slightly:

--- sizes-nios2-linux-gnu.inline
+++ sizes-nios2-linux-gnu.outline
    text           data     bss     dec     hex filename
-1425296          78844    9224 1513364  171794 libc.so
- 143824           8138     184  152146   25252 elf/ld.so
- 101762           9260    8356  119378   1d252 nptl/libpthread.so
-  26183           2392     160   28735    703f rt/librt.so
+1425592          80724    9224 1515540  172014 libc.so
+ 143960           8142     184  152286   252de elf/ld.so
+ 102278          10552    8356  121186   1d962 nptl/libpthread.so
+  26175           2396     160   28731    703b rt/librt.so

And since the port already issues the function call for static
object it simplifies the implementation since it avoid add an
arch-specific syscall_error.c.

Checked with cross make check for nios2-linux-gnu.
---
 sysdeps/unix/sysv/linux/nios2/sysdep.S | 50 --------------------------
 sysdeps/unix/sysv/linux/nios2/sysdep.h |  2 ++
 2 files changed, 2 insertions(+), 50 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/nios2/sysdep.S

diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.S b/sysdeps/unix/sysv/linux/nios2/sysdep.S
deleted file mode 100644
index 6efbb5aff6..0000000000
--- a/sysdeps/unix/sysv/linux/nios2/sysdep.S
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Static library error handling code fragment for Nios II.
-   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 <sysdep.h>
-
-/* The following code is only used in the static library. In the shared
-   library, the error handling code is at the end of each function.  */
-
-#ifndef	PIC
-
-/* In the static library, the syscall stubs jump here when they detect
-   an error.  */
-
-# undef CALL_MCOUNT
-# define CALL_MCOUNT /* Don't insert the profiling call, it clobbers r2.  */
-
-# if IS_IN (libc)
-#  define SYSCALL_ERROR_ERRNO __libc_errno
-# else
-#  define SYSCALL_ERROR_ERRNO errno
-# endif
-	.text
-ENTRY (__syscall_error)
-	nextpc	r3
-1:
-	movhi	r8, %hiadj(_gp_got - 1b)
-	addi	r8, r8, %lo(_gp_got - 1b)
-	add	r3, r3, r8
-	ldw	r3, %tls_ie(SYSCALL_ERROR_ERRNO)(r3)
-	add	r3, r23, r3
-	stw	r2, 0(r3)
-	movi	r2, -1
-	ret
-END (__syscall_error)
-#endif
diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.h b/sysdeps/unix/sysv/linux/nios2/sysdep.h
index 520c9460a2..882762785b 100644
--- a/sysdeps/unix/sysv/linux/nios2/sysdep.h
+++ b/sysdeps/unix/sysv/linux/nios2/sysdep.h
@@ -19,6 +19,8 @@
 #ifndef _LINUX_NIOS2_SYSDEP_H
 #define _LINUX_NIOS2_SYSDEP_H 1
 
+#define SYSCALL_ERROR_FUNC
+
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/nios2/sysdep.h>
 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 22/23] linux: Use generic __syscall_error for alpha
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (20 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 21/23] linux: Use generic __syscall_error for nios2 Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  2020-11-09 20:18 ` [PATCH 23/23] linux: Use generic __syscall_error for mips Adhemerval Zanella
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

Alpha __syscall_error uses an optimization to avoid load de GP
register and assumes small code size (-fpic).  Its implementation
is moved to arch-specific one (syscall_error_asm.S) to avoid
rewritting the inline asm wrapper to call the generic
__syscall_error.

Checked on alpha-linux-gnu.
---
 sysdeps/unix/alpha/Makefile                          | 8 ++++++--
 sysdeps/unix/alpha/rt-sysdep.S                       | 1 -
 sysdeps/unix/alpha/{sysdep.S => syscall_error_asm.S} | 8 ++++----
 sysdeps/unix/sysv/linux/alpha/Makefile               | 3 +--
 sysdeps/unix/sysv/linux/alpha/sysdep.h               | 4 ++--
 5 files changed, 13 insertions(+), 11 deletions(-)
 delete mode 100644 sysdeps/unix/alpha/rt-sysdep.S
 rename sysdeps/unix/alpha/{sysdep.S => syscall_error_asm.S} (94%)

diff --git a/sysdeps/unix/alpha/Makefile b/sysdeps/unix/alpha/Makefile
index 0660847f15..823ff2d90f 100644
--- a/sysdeps/unix/alpha/Makefile
+++ b/sysdeps/unix/alpha/Makefile
@@ -1,4 +1,8 @@
+ifeq ($(subdir),csu)
+sysdep_routines += syscall_error_asm
+endif
+
 ifeq ($(subdir),rt)
-librt-sysdep_routines += rt-sysdep
-librt-shared-only-routines += rt-sysdep
+librt-routines += syscall_error_asm
+librt-shared-only-routines += syscall_error_asm
 endif
diff --git a/sysdeps/unix/alpha/rt-sysdep.S b/sysdeps/unix/alpha/rt-sysdep.S
deleted file mode 100644
index f966bf1e59..0000000000
--- a/sysdeps/unix/alpha/rt-sysdep.S
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdep.S>
diff --git a/sysdeps/unix/alpha/sysdep.S b/sysdeps/unix/alpha/syscall_error_asm.S
similarity index 94%
rename from sysdeps/unix/alpha/sysdep.S
rename to sysdeps/unix/alpha/syscall_error_asm.S
index 67968623ac..ddc86c56d6 100644
--- a/sysdeps/unix/alpha/sysdep.S
+++ b/sysdeps/unix/alpha/syscall_error_asm.S
@@ -35,9 +35,9 @@
 #endif
 
 	.align 4
-	.globl	__syscall_error
-	.ent	__syscall_error
-__syscall_error:
+	.globl	__syscall_error_asm
+	.ent	__syscall_error_asm
+__syscall_error_asm:
 	/* When building a shared library, we branch here without having
 	   loaded the GP.  Nor, since it was a direct branch, have we
 	   loaded PV with our address.
@@ -62,4 +62,4 @@ __syscall_error:
 	stl	t0, 0(t1)
 	ret
 
-	.end __syscall_error
+	.end __syscall_error_asm
diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
index 92484bbe65..20c673b644 100644
--- a/sysdeps/unix/sysv/linux/alpha/Makefile
+++ b/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -31,8 +31,7 @@ libm-routines += multc3 divtc3
 endif   # math
 
 ifeq ($(subdir),nptl)
-# pull in __syscall_error routine, sigaction stubs.
-libpthread-routines += sysdep rt_sigaction
+libpthread-routines += rt_sigaction
 libpthread-shared-only-routines += sysdep rt_sigaction
 endif
 
diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep.h b/sysdeps/unix/sysv/linux/alpha/sysdep.h
index 7daf445068..86bab2ed4c 100644
--- a/sysdeps/unix/sysv/linux/alpha/sysdep.h
+++ b/sysdeps/unix/sysv/linux/alpha/sysdep.h
@@ -102,14 +102,14 @@ $syscall_error:					\
 	ret
 # define SYSCALL_ERROR_FALLTHRU
 #elif defined(PIC)
-# define SYSCALL_ERROR_LABEL		__syscall_error !samegp
+# define SYSCALL_ERROR_LABEL		__syscall_error_asm !samegp
 # define SYSCALL_ERROR_HANDLER
 # define SYSCALL_ERROR_FALLTHRU		br SYSCALL_ERROR_LABEL
 #else
 # define SYSCALL_ERROR_LABEL		$syscall_error
 # define SYSCALL_ERROR_HANDLER			\
 $syscall_error:					\
-	jmp $31, __syscall_error
+	jmp $31, __syscall_error_asm
 # define SYSCALL_ERROR_FALLTHRU
 #endif /* RTLD_PRIVATE_ERRNO */
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 23/23] linux: Use generic __syscall_error for mips
  2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
                   ` (21 preceding siblings ...)
  2020-11-09 20:18 ` [PATCH 22/23] linux: Use generic __syscall_error for alpha Adhemerval Zanella
@ 2020-11-09 20:18 ` Adhemerval Zanella
  22 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-09 20:18 UTC (permalink / raw)
  To: libc-alpha

The mips kABI returns a positive value on 'v0 ($2)' register
for failure case, different than usual Linux kABI with return
a negative value in range of [-4096,0).  To adjust mips to use
the generic __syscall_error requires to change both the inline
syscall and some assembly implementation that call __syscall_error
directly.

Also, using an extern call to __syscall_error on mips results in
more code size:

--- sizes-mips64-linux-gnu.inline
+++ sizes-mips64-linux-gnu.outline
    text           data     bss     dec     hex filename
-1706692          39428   15584 1761704  1ae1a8 libc.so
- 164384           7904     396  172684   2a28c elf/ld.so
- 126357           1912   16720  144989   2365d nptl/libpthread.so
-  30260            988     272   31520    7b20 rt/librt.so
+1708116          39436   15584 1763136  1ae740 libc.so
+ 164592           7904     396  172892   2a35c elf/ld.so
+ 127093           1920   16720  145733   23945 nptl/libpthread.so
+  30380            988     272   31640    7b98 rt/librt.so

--- sizes-mips-linux-gnu.inline
+++ sizes-mips-linux-gnu.outline
    text           data     bss     dec     hex filename
-1644339          21129   10824 1676292  199404 libc.so
- 173460           4856     264  178580   2b994 elf/ld.so
- 120945           1016    8420  130381   1fd4d nptl/libpthread.so
-  30822            560     192   31574    7b56 rt/librt.so
+1644411          21137   10824 1676372  199454 libc.so
+ 173652           4856     264  178772   2ba54 elf/ld.so
+ 121357           1020    8420  130797   1feed nptl/libpthread.so
+  30830            560     192   31582    7b5e rt/librt.so

The inline __syscall_error is used on C syscall implementations
and a arch-specific syscall_error.c is added to handle the
auto-generated ones.

Checked on mips64-linux-gnu and mips-linux-gnu.
---
 sysdeps/mips/Makefile                         |  5 -
 sysdeps/mips/nptl/Makefile                    |  5 -
 sysdeps/mips/nptl/nptl-sysdep.S               |  2 -
 sysdeps/unix/mips/mips32/sysdep.h             |  5 +-
 sysdeps/unix/mips/mips64/sysdep.h             |  3 +-
 sysdeps/unix/mips/rt-sysdep.S                 |  1 -
 sysdeps/unix/mips/sysdep.S                    | 99 -------------------
 sysdeps/unix/sysv/linux/mips/clone.S          |  1 +
 sysdeps/unix/sysv/linux/mips/getcontext.S     |  1 +
 .../unix/sysv/linux/mips/mips64/n64/ioctl.S   |  3 +-
 sysdeps/unix/sysv/linux/mips/mips64/syscall.S |  3 +-
 sysdeps/unix/sysv/linux/mips/setcontext.S     |  1 +
 sysdeps/unix/sysv/linux/mips/swapcontext.S    |  1 +
 sysdeps/unix/sysv/linux/mips/syscall_error.c  |  3 +
 sysdeps/unix/sysv/linux/mips/vfork.S          |  1 +
 15 files changed, 17 insertions(+), 117 deletions(-)
 delete mode 100644 sysdeps/mips/nptl/nptl-sysdep.S
 delete mode 100644 sysdeps/unix/mips/rt-sysdep.S
 delete mode 100644 sysdeps/unix/mips/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/mips/syscall_error.c

diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index 6ad69e9ef9..70c599ec95 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -7,11 +7,6 @@ ifeq ($(subdir),setjmp)
 sysdep_routines += setjmp_aux
 endif
 
-ifeq ($(subdir),rt)
-librt-sysdep_routines += rt-sysdep
-librt-shared-only-routines += rt-sysdep
-endif
-
 ifeq ($(subdir),csu)
 CPPFLAGS-crti.S += $(pic-ccflag)
 CPPFLAGS-crtn.S += $(pic-ccflag)
diff --git a/sysdeps/mips/nptl/Makefile b/sysdeps/mips/nptl/Makefile
index e9d279a530..eb5d51c450 100644
--- a/sysdeps/mips/nptl/Makefile
+++ b/sysdeps/mips/nptl/Makefile
@@ -18,8 +18,3 @@
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
-
-ifeq ($(subdir),nptl)
-libpthread-sysdep_routines += nptl-sysdep
-libpthread-shared-only-routines += nptl-sysdep
-endif
diff --git a/sysdeps/mips/nptl/nptl-sysdep.S b/sysdeps/mips/nptl/nptl-sysdep.S
deleted file mode 100644
index 3f5c2a364a..0000000000
--- a/sysdeps/mips/nptl/nptl-sysdep.S
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Pull in __syscall_error.  */
-#include <sysdep.S>
diff --git a/sysdeps/unix/mips/mips32/sysdep.h b/sysdeps/unix/mips/mips32/sysdep.h
index b09367347e..8f3d561abf 100644
--- a/sysdeps/unix/mips/mips32/sysdep.h
+++ b/sysdeps/unix/mips/mips32/sysdep.h
@@ -26,7 +26,8 @@
   .align 2;								      \
   .set nomips16;							      \
   cfi_startproc;							      \
-  99: la t9,__syscall_error;						      \
+  99: subu a0, zero, v0;						      \
+  la t9,__syscall_error;						      \
   jr t9;								      \
   cfi_endproc;								      \
   ENTRY(name)								      \
@@ -44,7 +45,7 @@ L(syse1):
   .align 2;								      \
   cfi_startproc;							      \
   99: j __syscall_error;						      \
-  nop;									      \
+   subu a0, zero, v0;							      \
   cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
diff --git a/sysdeps/unix/mips/mips64/sysdep.h b/sysdeps/unix/mips/mips64/sysdep.h
index fb5f27daf3..ff14bcceec 100644
--- a/sysdeps/unix/mips/mips64/sysdep.h
+++ b/sysdeps/unix/mips/mips64/sysdep.h
@@ -30,6 +30,7 @@
   .set nomips16;							      \
   cfi_startproc;							      \
   99:;									      \
+  dsubu a0, zero, v0;							      \
   .set noat;								      \
   .cpsetup t9, $1, name;						      \
   cfi_register (gp, $1);						      \
@@ -51,7 +52,7 @@ L(syse1):
   .set nomips16;							      \
   cfi_startproc;							      \
   99: j __syscall_error;						      \
-  nop;                                                                        \
+   dsubu a0, zero, v0;							      \
   cfi_endproc;								      \
   ENTRY(name)								      \
   .set noreorder;							      \
diff --git a/sysdeps/unix/mips/rt-sysdep.S b/sysdeps/unix/mips/rt-sysdep.S
deleted file mode 100644
index f966bf1e59..0000000000
--- a/sysdeps/unix/mips/rt-sysdep.S
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdep.S>
diff --git a/sysdeps/unix/mips/sysdep.S b/sysdeps/unix/mips/sysdep.S
deleted file mode 100644
index 744d1620b3..0000000000
--- a/sysdeps/unix/mips/sysdep.S
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Brendan Kehoe (brendan@zen.org).
-
-   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 <sys/asm.h>
-
-	.set	nomips16
-
-#ifdef _LIBC_REENTRANT
-
-LOCALSZ= 3
-FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
-RAOFF= FRAMESZ-(1*SZREG)
-GPOFF= FRAMESZ-(2*SZREG)
-V0OFF= FRAMESZ-(3*SZREG)
-
-ENTRY(__syscall_error)
-#ifdef __PIC__
-	.set noat
-	SETUP_GPX (AT)
-	.set at
-#endif
-	PTR_SUBU sp, FRAMESZ
-	.set noat
-	SETUP_GPX64(GPOFF,AT)
-	.set at
-#ifdef __PIC__
-	SAVE_GP(GPOFF)
-#endif
-	REG_S	v0, V0OFF(sp)
-	REG_S	ra, RAOFF(sp)
-
-#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.  */
-	bne	v0, EWOULDBLOCK_sys, L(skip)
-	nop
-	li	v0, EAGAIN
-L(skip):
-#endif
-	/* Find our per-thread errno address  */
-	jal	__errno_location
-
-	/* Store the error value.  */
-	REG_L	t0, V0OFF(sp)
-	sw	t0, 0(v0)
-
-	/* And just kick back a -1.  */
-	REG_L	ra, RAOFF(sp)
-	RESTORE_GP64
-	PTR_ADDU sp, FRAMESZ
-	li	v0, -1
-	j	ra
-	END(__syscall_error)
-
-#else /* _LIBC_REENTRANT */
-
-
-ENTRY(__syscall_error)
-#ifdef __PIC__
-	SETUP_GPX (AT)
-#endif
-	SETUP_GPX64 (t9, AT)
-
-#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.  */
-	bne v0, EWOULDBLOCK_sys, L(skip)
-	li v0, EAGAIN
-L(skip):
-#endif
-	/* Store it in errno... */
-	sw v0, errno
-
-	/* And just kick back a -1.  */
-	li v0, -1
-
-	RESTORE_GP64
-	j ra
-	END(__syscall_error)
-#endif  /* _LIBC_REENTRANT  */
diff --git a/sysdeps/unix/sysv/linux/mips/clone.S b/sysdeps/unix/sysv/linux/mips/clone.S
index 6a5ec84870..3dd181b6f9 100644
--- a/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/sysdeps/unix/sysv/linux/mips/clone.S
@@ -102,6 +102,7 @@ NESTED(__clone,4*SZREG,sp)
 	/* Something bad happened -- no child created */
 L(error):
 	cfi_restore_state
+	INT_SUBU	a0, zero, v0
 #ifdef __PIC__
 	PTR_LA		t9,__syscall_error
 	RESTORE_GP64_STACK
diff --git a/sysdeps/unix/sysv/linux/mips/getcontext.S b/sysdeps/unix/sysv/linux/mips/getcontext.S
index 69f62d4a75..edb5063647 100644
--- a/sysdeps/unix/sysv/linux/mips/getcontext.S
+++ b/sysdeps/unix/sysv/linux/mips/getcontext.S
@@ -140,6 +140,7 @@ NESTED (__getcontext, FRAMESZ, ra)
 
 99:
 	cfi_restore_state
+	INT_SUBU a0, zero, v0
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64_STACK
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S b/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
index ed58abe7e9..c911abee2a 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
@@ -31,7 +31,8 @@ ENTRY (__ioctl)
 	ret
 
 L(error):
-	SETUP_GP64_REG (a0, __ioctl)
+	INT_SUBU a0, zero, v0
+	SETUP_GP64_REG (v0, __ioctl)
 	PTR_LA t9, __syscall_error
 	RESTORE_GP64_REG
 	jr t9
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscall.S b/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
index a9baff3c17..8fc6caea71 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
+++ b/sysdeps/unix/sysv/linux/mips/mips64/syscall.S
@@ -55,7 +55,8 @@ NESTED (syscall, SZREG, ra)
 	ret
 
 L(error):
-	SETUP_GP64_REG (a0, syscall)
+	INT_SUBU a0, zero, v0
+	SETUP_GP64_REG (v0, syscall)
 	PTR_LA t9, __syscall_error
 	RESTORE_GP64_REG
 	jr t9
diff --git a/sysdeps/unix/sysv/linux/mips/setcontext.S b/sysdeps/unix/sysv/linux/mips/setcontext.S
index 3609af7780..cd058c4390 100644
--- a/sysdeps/unix/sysv/linux/mips/setcontext.S
+++ b/sysdeps/unix/sysv/linux/mips/setcontext.S
@@ -149,6 +149,7 @@ NESTED (__setcontext, FRAMESZ, ra)
 	jr	t9
 
 99:
+	INT_SUBU a0, zero, v0
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64_STACK
diff --git a/sysdeps/unix/sysv/linux/mips/swapcontext.S b/sysdeps/unix/sysv/linux/mips/swapcontext.S
index bcc66be068..ca3bcddfb7 100644
--- a/sysdeps/unix/sysv/linux/mips/swapcontext.S
+++ b/sysdeps/unix/sysv/linux/mips/swapcontext.S
@@ -200,6 +200,7 @@ NESTED (__swapcontext, FRAMESZ, ra)
 	jr	t9
 
 99:
+	INT_SUBU a0, zero, v0;
 #ifdef __PIC__
 	PTR_LA	t9, JUMPTARGET (__syscall_error)
 	RESTORE_GP64_STACK
diff --git a/sysdeps/unix/sysv/linux/mips/syscall_error.c b/sysdeps/unix/sysv/linux/mips/syscall_error.c
new file mode 100644
index 0000000000..ee8b2e9f0d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/syscall_error.c
@@ -0,0 +1,3 @@
+/* The auto-generated syscalls call __syscall_error.  */
+#define SYSCALL_ERROR_FUNC
+#include <sysdeps/unix/sysv/linux/syscall_error.c>
diff --git a/sysdeps/unix/sysv/linux/mips/vfork.S b/sysdeps/unix/sysv/linux/mips/vfork.S
index ba3c64ae1e..f579ffe46f 100644
--- a/sysdeps/unix/sysv/linux/mips/vfork.S
+++ b/sysdeps/unix/sysv/linux/mips/vfork.S
@@ -76,6 +76,7 @@ NESTED(__libc_vfork,FRAMESZ,sp)
 	/* Something bad happened -- no child created.  */
 L(error):
 	cfi_restore_state
+	INT_SUBU	a0, zero, v0
 #ifdef __PIC__
 	PTR_LA		t9, __syscall_error
 	RESTORE_GP64_REG
-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error
  2020-11-09 20:18 ` [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error Adhemerval Zanella
@ 2020-11-09 22:14   ` Joseph Myers
  2020-11-11 16:31     ` Adhemerval Zanella
  0 siblings, 1 reply; 33+ messages in thread
From: Joseph Myers @ 2020-11-09 22:14 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Mon, 9 Nov 2020, Adhemerval Zanella via Libc-alpha wrote:

> +/* The errno setting might be set either inline or with a helper function.
> +   For some ABIs (x86_64 for instance), handling it inline might generate
> +   less code; while for others (i686) a function call is preferable.
> +
> +   To use the helper function the ABI must define SYSCALL_ERROR_FUNC, it will
> +   build a hidden function on each shared object that issue direct syscall
> +   with {INLINE,INTERNAL}_SYSCALL_CALL.  */
> +
> +#ifdef SYSCALL_ERROR_FUNC

The current convention would be to have SYSCALL_ERROR_FUNC always defined 
and make the choice using #if not #ifdef.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 03/23] Remove tls.h inclusion from internal errno.h
  2020-11-09 20:18 ` [PATCH 03/23] Remove tls.h inclusion from internal errno.h Adhemerval Zanella
@ 2020-11-10 10:45   ` Florian Weimer
  0 siblings, 0 replies; 33+ messages in thread
From: Florian Weimer @ 2020-11-10 10:45 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> The tls.h inclusion is not really required and limits possible
> definition on more arch specific headers.
>
> This is a cleanup to allow inline functions on sysdep.h, more
> specifically on i386 and ia64 which requires to access some tls
> definitions its own.
>
> No semantic changes expected, checked with a build against all
> affected ABIs.

Looks reasonable, thanks.

Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO
  2020-11-09 20:18 ` [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO Adhemerval Zanella
@ 2020-11-10 11:11   ` Florian Weimer
  2020-11-11 16:21     ` Adhemerval Zanella
  0 siblings, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2020-11-10 11:11 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> diff --git a/sysdeps/unix/sysv/linux/posix_fadvise.c b/sysdeps/unix/sysv/linux/posix_fadvise.c
> index bada96b697..1191ab3db5 100644
> --- a/sysdeps/unix/sysv/linux/posix_fadvise.c
> +++ b/sysdeps/unix/sysv/linux/posix_fadvise.c
> @@ -60,8 +60,6 @@ posix_fadvise (int fd, off_t offset, off_t len, int advise)
>  				   SYSCALL_LL (len), advise);
>  #  endif
>  # endif
> -  if (INTERNAL_SYSCALL_ERROR_P (ret))
> -    return INTERNAL_SYSCALL_ERRNO (ret);
> -  return 0;
> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>  }
>  #endif /* __OFF_T_MATCHES_OFF64_T  */
> diff --git a/sysdeps/unix/sysv/linux/posix_fadvise64.c b/sysdeps/unix/sysv/linux/posix_fadvise64.c
> index 9787ab4c7c..e3726a6a8a 100644
> --- a/sysdeps/unix/sysv/linux/posix_fadvise64.c
> +++ b/sysdeps/unix/sysv/linux/posix_fadvise64.c
> @@ -48,9 +48,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
>  				   __ALIGNMENT_ARG SYSCALL_LL64 (offset),
>  				   SYSCALL_LL64 (len), advise);
>  #endif
> -  if (!INTERNAL_SYSCALL_ERROR_P (ret))
> -    return 0;
> -  return INTERNAL_SYSCALL_ERRNO (ret);
> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>  }
>  
>  /* The type of the len argument was changed from size_t to off_t in

These two could just use -ret, I think.  The kernel returns 0 for
success, right?

> diff --git a/sysdeps/unix/sysv/linux/posix_fallocate.c b/sysdeps/unix/sysv/linux/posix_fallocate.c
> index 7238b00038..87532668cd 100644
> --- a/sysdeps/unix/sysv/linux/posix_fallocate.c
> +++ b/sysdeps/unix/sysv/linux/posix_fallocate.c
> @@ -30,7 +30,7 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
>  				   SYSCALL_LL (offset), SYSCALL_LL (len));
>    if (! INTERNAL_SYSCALL_ERROR_P (res))
>      return 0;
> -  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
> -    return INTERNAL_SYSCALL_ERRNO (res);
> +  if (res != -EOPNOTSUPP)
> +    return -res;
>    return internal_fallocate (fd, offset, len);
>  }
> diff --git a/sysdeps/unix/sysv/linux/posix_fallocate64.c b/sysdeps/unix/sysv/linux/posix_fallocate64.c
> index 2de63ac277..0340357e57 100644
> --- a/sysdeps/unix/sysv/linux/posix_fallocate64.c
> +++ b/sysdeps/unix/sysv/linux/posix_fallocate64.c
> @@ -32,8 +32,8 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
>  				   SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
>    if (! INTERNAL_SYSCALL_ERROR_P (res))
>      return 0;
> -  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
> -    return INTERNAL_SYSCALL_ERRNO (res);
> +  if (-res != EOPNOTSUPP)
> +    return -res;
>    return internal_fallocate64 (fd, offset, len);
>  }
>  libc_hidden_def (__posix_fallocate64_l64)

-res == EOPNOTSUPP is inconsistent with the rest of the patch.

> diff --git a/sysdeps/unix/sysv/linux/pthread_sigqueue.c b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
> index 4b32be2d64..fbbd9fee20 100644
> --- a/sysdeps/unix/sysv/linux/pthread_sigqueue.c
> +++ b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
> @@ -63,8 +63,7 @@ pthread_sigqueue (pthread_t threadid, int signo, const union sigval value)
>    /* We have a special syscall to do the work.  */
>    int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo,
>  				   &info);
> -  return (INTERNAL_SYSCALL_ERROR_P (val)
> -	  ? INTERNAL_SYSCALL_ERRNO (val) : 0);
> +  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
>  #else
>    return ENOSYS;
>  #endif

This could use plain -val.

> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
> index b556a6caae..6199589307 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
> @@ -43,9 +43,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
>    parameters.len = len;
>    parameters.advise = advise;
>    int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, &parameters);
> -  if (!INTERNAL_SYSCALL_ERROR_P (ret))
> -    return 0;
> -  return INTERNAL_SYSCALL_ERRNO (ret);
> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>  }
>  
>  #include <shlib-compat.h>

See above, plain -ret should be okay.


The patch relies on a GCC extension because in the error case, -res is a
large unsigned value which cannot be represented in an int.  But I think
this is okay.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function
  2020-11-09 20:18 ` [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function Adhemerval Zanella
@ 2020-11-10 11:27   ` Florian Weimer
  2020-11-11 16:30     ` Adhemerval Zanella
  0 siblings, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2020-11-10 11:27 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

I believe this leads to a miscompilation of lseek on x86-64 x32.  The
generic syscall_error will ignore top half of the lseek system call
result there.

I suspect that many of the conditions could be changed to ret == 0 or
ret < 0 (using a signed type for ret, i.e. not what comes from
INTERNAL_SYSCALL_CALL), resulting in better code.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 07/23] linux: Use generic __syscall_error for i386
  2020-11-09 20:18 ` [PATCH 07/23] linux: Use generic __syscall_error for i386 Adhemerval Zanella
@ 2020-11-10 12:49   ` Florian Weimer
  2020-11-11 16:41     ` Adhemerval Zanella
  0 siblings, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2020-11-10 12:49 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

* 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
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO
  2020-11-10 11:11   ` Florian Weimer
@ 2020-11-11 16:21     ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-11 16:21 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 10/11/2020 08:11, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> diff --git a/sysdeps/unix/sysv/linux/posix_fadvise.c b/sysdeps/unix/sysv/linux/posix_fadvise.c
>> index bada96b697..1191ab3db5 100644
>> --- a/sysdeps/unix/sysv/linux/posix_fadvise.c
>> +++ b/sysdeps/unix/sysv/linux/posix_fadvise.c
>> @@ -60,8 +60,6 @@ posix_fadvise (int fd, off_t offset, off_t len, int advise)
>>  				   SYSCALL_LL (len), advise);
>>  #  endif
>>  # endif
>> -  if (INTERNAL_SYSCALL_ERROR_P (ret))
>> -    return INTERNAL_SYSCALL_ERRNO (ret);
>> -  return 0;
>> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>>  }
>>  #endif /* __OFF_T_MATCHES_OFF64_T  */
>> diff --git a/sysdeps/unix/sysv/linux/posix_fadvise64.c b/sysdeps/unix/sysv/linux/posix_fadvise64.c
>> index 9787ab4c7c..e3726a6a8a 100644
>> --- a/sysdeps/unix/sysv/linux/posix_fadvise64.c
>> +++ b/sysdeps/unix/sysv/linux/posix_fadvise64.c
>> @@ -48,9 +48,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
>>  				   __ALIGNMENT_ARG SYSCALL_LL64 (offset),
>>  				   SYSCALL_LL64 (len), advise);
>>  #endif
>> -  if (!INTERNAL_SYSCALL_ERROR_P (ret))
>> -    return 0;
>> -  return INTERNAL_SYSCALL_ERRNO (ret);
>> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>>  }
>>  
>>  /* The type of the len argument was changed from size_t to off_t in
> 
> These two could just use -ret, I think.  The kernel returns 0 for
> success, right?
> 

Yes, I make this change on the the subsequent patch where I remove the
INTERNAL_SYSCALL_ERROR_P macro.  

>> diff --git a/sysdeps/unix/sysv/linux/posix_fallocate.c b/sysdeps/unix/sysv/linux/posix_fallocate.c
>> index 7238b00038..87532668cd 100644
>> --- a/sysdeps/unix/sysv/linux/posix_fallocate.c
>> +++ b/sysdeps/unix/sysv/linux/posix_fallocate.c
>> @@ -30,7 +30,7 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
>>  				   SYSCALL_LL (offset), SYSCALL_LL (len));
>>    if (! INTERNAL_SYSCALL_ERROR_P (res))
>>      return 0;
>> -  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
>> -    return INTERNAL_SYSCALL_ERRNO (res);
>> +  if (res != -EOPNOTSUPP)
>> +    return -res;
>>    return internal_fallocate (fd, offset, len);
>>  }
>> diff --git a/sysdeps/unix/sysv/linux/posix_fallocate64.c b/sysdeps/unix/sysv/linux/posix_fallocate64.c
>> index 2de63ac277..0340357e57 100644
>> --- a/sysdeps/unix/sysv/linux/posix_fallocate64.c
>> +++ b/sysdeps/unix/sysv/linux/posix_fallocate64.c
>> @@ -32,8 +32,8 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
>>  				   SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
>>    if (! INTERNAL_SYSCALL_ERROR_P (res))
>>      return 0;
>> -  if (INTERNAL_SYSCALL_ERRNO (res) != EOPNOTSUPP)
>> -    return INTERNAL_SYSCALL_ERRNO (res);
>> +  if (-res != EOPNOTSUPP)
>> +    return -res;
>>    return internal_fallocate64 (fd, offset, len);
>>  }
>>  libc_hidden_def (__posix_fallocate64_l64)
> 
> -res == EOPNOTSUPP is inconsistent with the rest of the patch.

Do you mean change to 'res == -EOPNOTSUPP) ?

> 
>> diff --git a/sysdeps/unix/sysv/linux/pthread_sigqueue.c b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
>> index 4b32be2d64..fbbd9fee20 100644
>> --- a/sysdeps/unix/sysv/linux/pthread_sigqueue.c
>> +++ b/sysdeps/unix/sysv/linux/pthread_sigqueue.c
>> @@ -63,8 +63,7 @@ pthread_sigqueue (pthread_t threadid, int signo, const union sigval value)
>>    /* We have a special syscall to do the work.  */
>>    int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo,
>>  				   &info);
>> -  return (INTERNAL_SYSCALL_ERROR_P (val)
>> -	  ? INTERNAL_SYSCALL_ERRNO (val) : 0);
>> +  return INTERNAL_SYSCALL_ERROR_P (val) ? -val : 0;
>>  #else
>>    return ENOSYS;
>>  #endif
> 
> This could use plain -val.
> 
>> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
>> index b556a6caae..6199589307 100644
>> --- a/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
>> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
>> @@ -43,9 +43,7 @@ __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
>>    parameters.len = len;
>>    parameters.advise = advise;
>>    int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, &parameters);
>> -  if (!INTERNAL_SYSCALL_ERROR_P (ret))
>> -    return 0;
>> -  return INTERNAL_SYSCALL_ERRNO (ret);
>> +  return INTERNAL_SYSCALL_ERROR_P (ret) ? -ret : 0;
>>  }
>>  
>>  #include <shlib-compat.h>
> 
> See above, plain -ret should be okay.
> 
> 
> The patch relies on a GCC extension because in the error case, -res is a
> large unsigned value which cannot be represented in an int.  But I think
> this is okay.

I think with subsequent patches where it moves towards inline functions with
a more well typed interface should make the internal syscall interface more
well-defined.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function
  2020-11-10 11:27   ` Florian Weimer
@ 2020-11-11 16:30     ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-11 16:30 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 10/11/2020 08:27, Florian Weimer wrote:
> I believe this leads to a miscompilation of lseek on x86-64 x32.  The
> generic syscall_error will ignore top half of the lseek system call
> result there.

The x32 lseek is provided by the arch-specific inloine assembly:

  sysdeps/unix/sysv/linux/x86_64/x32/lseek.S

I have a patchset that moves a lot of assembly implementations that issues
syscalls to C counter-parts and I think since lseek is an outlier it would
be better to provide a arch-specific implementation than parametrize
the generic internal syscall interface to return a 64-bit value for x32
(which might pessimize code generation).

> 
> I suspect that many of the conditions could be changed to ret == 0 or
> ret < 0 (using a signed type for ret, i.e. not what comes from
> INTERNAL_SYSCALL_CALL), resulting in better code.

I do agree and I was doubtful that syscall_error is indeed useful.
In the end I decided to make this change more mechanical and thus
add a direct replacement for INTERNAL_YSCALL_ERROR_P.

Maybe it would be better to just check for 'ret' value directly
instead of using an auxiliary value.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error
  2020-11-09 22:14   ` Joseph Myers
@ 2020-11-11 16:31     ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-11 16:31 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha



On 09/11/2020 19:14, Joseph Myers wrote:
> On Mon, 9 Nov 2020, Adhemerval Zanella via Libc-alpha wrote:
> 
>> +/* The errno setting might be set either inline or with a helper function.
>> +   For some ABIs (x86_64 for instance), handling it inline might generate
>> +   less code; while for others (i686) a function call is preferable.
>> +
>> +   To use the helper function the ABI must define SYSCALL_ERROR_FUNC, it will
>> +   build a hidden function on each shared object that issue direct syscall
>> +   with {INLINE,INTERNAL}_SYSCALL_CALL.  */
>> +
>> +#ifdef SYSCALL_ERROR_FUNC
> 
> The current convention would be to have SYSCALL_ERROR_FUNC always defined 
> and make the choice using #if not #ifdef.
> 

Right, I think it would be better to move it to auxiliary header then.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 07/23] linux: Use generic __syscall_error for i386
  2020-11-10 12:49   ` Florian Weimer
@ 2020-11-11 16:41     ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2020-11-11 16:41 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



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


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-11-11 16:41 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 20:18 [PATCH 00/23] Simplify internal Linux syscall Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 01/23] linux: Remove INTERNAL_SYSCALL_ERRNO Adhemerval Zanella
2020-11-10 11:11   ` Florian Weimer
2020-11-11 16:21     ` Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 02/23] linux: Replace INTERNAL_SYSCALL_ERROR_P macro with a inline function Adhemerval Zanella
2020-11-10 11:27   ` Florian Weimer
2020-11-11 16:30     ` Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 03/23] Remove tls.h inclusion from internal errno.h Adhemerval Zanella
2020-11-10 10:45   ` Florian Weimer
2020-11-09 20:18 ` [PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 05/23] linux: Replace INLINE_SYSCALL_ERROR_RETURN_VALUE with __syscall_error Adhemerval Zanella
2020-11-09 22:14   ` Joseph Myers
2020-11-11 16:31     ` Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 06/23] linux: Use generic __syscall_error for aarch64 Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 07/23] linux: Use generic __syscall_error for i386 Adhemerval Zanella
2020-11-10 12:49   ` Florian Weimer
2020-11-11 16:41     ` Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 08/23] linux: Use generic __syscall_error for arc Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 09/23] linux: Use generic __syscall_error for powerpc Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 10/23] linux: Use generic __syscall_error for sparc Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 11/23] linux: Use generic __syscall_error for hppa Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 12/23] linux: Use generic __syscall_error for arm Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 13/23] linux: Use generic __syscall_error for x86_64 Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 14/23] linux: Use generic __syscall_error for s390 Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 15/23] linux: Use generic __syscall_error for sh Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 16/23] linux: Use generic __syscall_error for microblaze Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 17/23] linux: Use generic __syscall_error for ia64 Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 18/23] linux: Use generic __syscall_error for m68k Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 19/23] linux: Use generic __syscall_error for csky Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 20/23] linux: Use generic __syscall_error for riscv Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 21/23] linux: Use generic __syscall_error for nios2 Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 22/23] linux: Use generic __syscall_error for alpha Adhemerval Zanella
2020-11-09 20:18 ` [PATCH 23/23] linux: Use generic __syscall_error for mips Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).