diff mbox

[v3,2/4] Consolidate lseek/lseek64/llseek implementations

Message ID 1474383714-15187-3-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show

Commit Message

Adhemerval Zanella Netto Sept. 20, 2016, 3:01 p.m. UTC
Changes from previous version:

  - lseek64 logic to define which syscall to use depends only of
    __NR__llseek and __NR_lseek avaliability (instead of relying on
    __OFF_T_MATCHES_OFF64_T).  This is make new ports that might
    define __OFF_T_MATCHES_OFF64_T, but still use the __NR__llseek
    (such as aarch64 ilp32).

  - Add a guard while defining __NR__llseek only if __NR_llseek is
    also defined.

  - Rebase for new pthread compat wrappers Makefile changes.

--

This patch consolidates all Linux lseek/lseek64/llseek implementation
in on on sysdeps/unix/sysv/linux/lseek{64}.c.  It also removes the llseek
file and instead consolidate the LFS lseek implementation on lseek64.c
as for other LFS symbols implementations.

The general idea is:

  - lseek: ABIs that not define __OFF_T_MATCHES_OFF64_T will preferable
  use __NR__llseek if kernel supports it, otherwise they will use __NR_lseek.
  ABIs that defines __OFF_T_MATCHES_OFF64_T won't produce any symbol.

  - lseek64: ABIs with __OFF_T_MATCHES_OFF64_T will preferable use __NR_lseek
  (since it will use 64-bit arguments without low/high splitting) and
  __NR__llseek if __NR_lseek is not defined (for some ILP32 ports).

  - llseek: files will be removed and symbols will be aliased ot lseek64.

ABI without __OFF_T_MATCHES_OFF64_T and without __NR_llseek (basically MIPS64n32
so far) are covered by building lseek with off_t as expected and lseek64
using __NR_lseek (as expected for off64_t being passed using 64-bit registers).

For this consolidation I mantained the x32 assembly specific implementation
because to correctly fix this it would required both the x32 fix for
{INLINE,INTERNAL}_SYSCALL [1] and a wrapper to correctly subscribe it to
return 64 bits instead of default 32 bits (as for times).  It could a future
cleanup.

It is based on my previous {INTERNAL,INLINE}_SYSCALL_CALL macro [2],
although it is mainly for simplification.

Tested on x86_64, i686, aarch64, armhf, and powerpc64le.

	* nptl/Makefile (pthread-compat-wrappers): Remove llseek and add
	lseek64.
	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Remove llseek.
	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdeps_routines):
	Likewise.
	* sysdeps/unix/sysv/linux/generic/sysdep.h (__NR__llseek): Define iff
	__NR_llseek is defined.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: Remove file.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: Remove file.
	* sysdeps/unix/sysv/linux/mips/mips64/llseek.c: Likewise.
	* sysdeps/unix/sysv/linux/llseek.c: Remove file.
	* sysdeps/unix/sysv/linux/lseek.c: New file.
	* sysdeps/unix/sysv/linux/lseek64.c: Add default Linux implementation.
	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list: Remove lseek and
	__libc_lseek64 from auto-generation.
	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S: New file.

[1] https://sourceware.org/ml/libc-alpha/2016-08/msg00443.html
[2] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
---
 nptl/Makefile                                      |  2 +-
 sysdeps/unix/sysv/linux/Makefile                   |  2 +-
 sysdeps/unix/sysv/linux/alpha/Makefile             |  2 +-
 sysdeps/unix/sysv/linux/generic/sysdep.h           |  4 +-
 .../unix/sysv/linux/generic/wordsize-32/llseek.c   | 46 ------------------
 .../unix/sysv/linux/generic/wordsize-32/lseek.c    | 38 ---------------
 sysdeps/unix/sysv/linux/llseek.c                   | 46 ------------------
 sysdeps/unix/sysv/linux/lseek.c                    | 56 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/lseek64.c                  | 54 ++++++++++++++++++++-
 sysdeps/unix/sysv/linux/mips/mips64/llseek.c       |  1 -
 sysdeps/unix/sysv/linux/mips/mips64/syscalls.list  |  2 -
 sysdeps/unix/sysv/linux/wordsize-64/syscalls.list  |  3 --
 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S       |  1 +
 13 files changed, 116 insertions(+), 141 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c
 delete mode 100644 sysdeps/unix/sysv/linux/llseek.c
 create mode 100644 sysdeps/unix/sysv/linux/lseek.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/llseek.c
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

-- 
2.7.4

Comments

Adhemerval Zanella Netto Oct. 11, 2016, 2:39 p.m. UTC | #1
Ping.

On 20/09/2016 12:01, Adhemerval Zanella wrote:
> Changes from previous version:

> 

>   - lseek64 logic to define which syscall to use depends only of

>     __NR__llseek and __NR_lseek avaliability (instead of relying on

>     __OFF_T_MATCHES_OFF64_T).  This is make new ports that might

>     define __OFF_T_MATCHES_OFF64_T, but still use the __NR__llseek

>     (such as aarch64 ilp32).

> 

>   - Add a guard while defining __NR__llseek only if __NR_llseek is

>     also defined.

> 

>   - Rebase for new pthread compat wrappers Makefile changes.

> 

> --

> 

> This patch consolidates all Linux lseek/lseek64/llseek implementation

> in on on sysdeps/unix/sysv/linux/lseek{64}.c.  It also removes the llseek

> file and instead consolidate the LFS lseek implementation on lseek64.c

> as for other LFS symbols implementations.

> 

> The general idea is:

> 

>   - lseek: ABIs that not define __OFF_T_MATCHES_OFF64_T will preferable

>   use __NR__llseek if kernel supports it, otherwise they will use __NR_lseek.

>   ABIs that defines __OFF_T_MATCHES_OFF64_T won't produce any symbol.

> 

>   - lseek64: ABIs with __OFF_T_MATCHES_OFF64_T will preferable use __NR_lseek

>   (since it will use 64-bit arguments without low/high splitting) and

>   __NR__llseek if __NR_lseek is not defined (for some ILP32 ports).

> 

>   - llseek: files will be removed and symbols will be aliased ot lseek64.

> 

> ABI without __OFF_T_MATCHES_OFF64_T and without __NR_llseek (basically MIPS64n32

> so far) are covered by building lseek with off_t as expected and lseek64

> using __NR_lseek (as expected for off64_t being passed using 64-bit registers).

> 

> For this consolidation I mantained the x32 assembly specific implementation

> because to correctly fix this it would required both the x32 fix for

> {INLINE,INTERNAL}_SYSCALL [1] and a wrapper to correctly subscribe it to

> return 64 bits instead of default 32 bits (as for times).  It could a future

> cleanup.

> 

> It is based on my previous {INTERNAL,INLINE}_SYSCALL_CALL macro [2],

> although it is mainly for simplification.

> 

> Tested on x86_64, i686, aarch64, armhf, and powerpc64le.

> 

> 	* nptl/Makefile (pthread-compat-wrappers): Remove llseek and add

> 	lseek64.

> 	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Remove llseek.

> 	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdeps_routines):

> 	Likewise.

> 	* sysdeps/unix/sysv/linux/generic/sysdep.h (__NR__llseek): Define iff

> 	__NR_llseek is defined.

> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: Remove file.

> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: Remove file.

> 	* sysdeps/unix/sysv/linux/mips/mips64/llseek.c: Likewise.

> 	* sysdeps/unix/sysv/linux/llseek.c: Remove file.

> 	* sysdeps/unix/sysv/linux/lseek.c: New file.

> 	* sysdeps/unix/sysv/linux/lseek64.c: Add default Linux implementation.

> 	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list: Remove lseek and

> 	__libc_lseek64 from auto-generation.

> 	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.

> 	* sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S: New file.

> 

> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00443.html

> [2] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html

> ---

>  nptl/Makefile                                      |  2 +-

>  sysdeps/unix/sysv/linux/Makefile                   |  2 +-

>  sysdeps/unix/sysv/linux/alpha/Makefile             |  2 +-

>  sysdeps/unix/sysv/linux/generic/sysdep.h           |  4 +-

>  .../unix/sysv/linux/generic/wordsize-32/llseek.c   | 46 ------------------

>  .../unix/sysv/linux/generic/wordsize-32/lseek.c    | 38 ---------------

>  sysdeps/unix/sysv/linux/llseek.c                   | 46 ------------------

>  sysdeps/unix/sysv/linux/lseek.c                    | 56 ++++++++++++++++++++++

>  sysdeps/unix/sysv/linux/lseek64.c                  | 54 ++++++++++++++++++++-

>  sysdeps/unix/sysv/linux/mips/mips64/llseek.c       |  1 -

>  sysdeps/unix/sysv/linux/mips/mips64/syscalls.list  |  2 -

>  sysdeps/unix/sysv/linux/wordsize-64/syscalls.list  |  3 --

>  sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S       |  1 +

>  13 files changed, 116 insertions(+), 141 deletions(-)

>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>  delete mode 100644 sysdeps/unix/sysv/linux/llseek.c

>  create mode 100644 sysdeps/unix/sysv/linux/lseek.c

>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>  create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

> 

> diff --git a/nptl/Makefile b/nptl/Makefile

> index e9485df..ee828fe 100644

> --- a/nptl/Makefile

> +++ b/nptl/Makefile

> @@ -38,7 +38,7 @@ shared-only-routines = forward

>  pthread-compat-wrappers = \

>  		      write read close fcntl accept \

>  		      connect recv recvfrom send \

> -		      sendto fsync lseek llseek \

> +		      sendto fsync lseek lseek64 \

>  		      msync nanosleep open open64 pause \

>  		      pread pread64 pwrite pwrite64 \

>  		      tcdrain wait waitpid msgrcv msgsnd \

> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile

> index 9a0423e..16a61cb 100644

> --- a/sysdeps/unix/sysv/linux/Makefile

> +++ b/sysdeps/unix/sysv/linux/Makefile

> @@ -14,7 +14,7 @@ endif

>  ifeq ($(subdir),misc)

>  include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))

>  

> -sysdep_routines += clone llseek umount umount2 readahead \

> +sysdep_routines += clone umount umount2 readahead \

>  		   setfsuid setfsgid epoll_pwait signalfd \

>  		   eventfd eventfd_read eventfd_write prlimit \

>  		   personality

> diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile

> index 1e858ce..45941b0 100644

> --- a/sysdeps/unix/sysv/linux/alpha/Makefile

> +++ b/sysdeps/unix/sysv/linux/alpha/Makefile

> @@ -10,7 +10,7 @@ ifeq ($(subdir),misc)

>  sysdep_headers += alpha/ptrace.h alpha/regdef.h sys/io.h

>  

>  sysdep_routines += ieee_get_fp_control ieee_set_fp_control \

> -		   ioperm llseek

> +		   ioperm

>  

>  # Support old timeval32 entry points

>  sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \

> diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h

> index b0422ff..6d379cc 100644

> --- a/sysdeps/unix/sysv/linux/generic/sysdep.h

> +++ b/sysdeps/unix/sysv/linux/generic/sysdep.h

> @@ -22,7 +22,9 @@

>  #include <sysdeps/unix/sysv/linux/sysdep.h>

>  

>  /* Provide the common name to allow more code reuse.  */

> -#define __NR__llseek __NR_llseek

> +#ifdef __NR_llseek

> +# define __NR__llseek __NR_llseek

> +#endif

>  

>  #if __WORDSIZE == 64

>  /* By defining the older names, glibc will build syscall wrappers for

> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

> deleted file mode 100644

> index 458964c..0000000

> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

> +++ /dev/null

> @@ -1,46 +0,0 @@

> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

> -   This file is part of the GNU C Library.

> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

> -

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

> -   <http://www.gnu.org/licenses/>.  */

> -

> -#include <errno.h>

> -#include <sys/types.h>

> -

> -#include <sysdep.h>

> -#include <sys/syscall.h>

> -

> -/* Seek to OFFSET on FD, starting from WHENCE.  */

> -extern loff_t __llseek (int fd, loff_t offset, int whence);

> -

> -loff_t

> -__llseek (int fd, loff_t offset, int whence)

> -{

> -  loff_t retval;

> -

> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

> -				   (off_t) (offset & 0xffffffff),

> -				   &retval, whence) ?: retval);

> -}

> -weak_alias (__llseek, llseek)

> -strong_alias (__llseek, __libc_lseek64)

> -strong_alias (__llseek, __lseek64)

> -weak_alias (__llseek, lseek64)

> -

> -/* llseek doesn't have a prototype.  Since the second parameter is a

> -   64bit type, this results in wrong behaviour if no prototype is

> -   provided.  */

> -link_warning (llseek, "\

> -the `llseek' function may be dangerous; use `lseek64' instead.")

> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

> deleted file mode 100644

> index dbf0b26..0000000

> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

> +++ /dev/null

> @@ -1,38 +0,0 @@

> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

> -   This file is part of the GNU C Library.

> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

> -

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

> -   <http://www.gnu.org/licenses/>.  */

> -

> -#include <errno.h>

> -#include <unistd.h>

> -#include <sys/types.h>

> -

> -#include <sysdep.h>

> -#include <sys/syscall.h>

> -

> -#include "overflow.h"

> -

> -off_t

> -__lseek (int fd, off_t offset, int whence)

> -{

> -  loff_t res;

> -  int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31),

> -                           (off_t) offset, &res, whence);

> -  return rc ?: lseek_overflow (res);

> -}

> -libc_hidden_def (__lseek)

> -weak_alias (__lseek, lseek)

> -strong_alias (__lseek, __libc_lseek)

> diff --git a/sysdeps/unix/sysv/linux/llseek.c b/sysdeps/unix/sysv/linux/llseek.c

> deleted file mode 100644

> index b6f3ea5..0000000

> --- a/sysdeps/unix/sysv/linux/llseek.c

> +++ /dev/null

> @@ -1,46 +0,0 @@

> -/* Long-long seek operation.

> -   Copyright (C) 1996-2016 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

> -   <http://www.gnu.org/licenses/>.  */

> -

> -#include <errno.h>

> -#include <sys/types.h>

> -

> -#include <sysdep.h>

> -#include <sys/syscall.h>

> -

> -/* Seek to OFFSET on FD, starting from WHENCE.  */

> -extern loff_t __llseek (int fd, loff_t offset, int whence);

> -

> -loff_t

> -__llseek (int fd, loff_t offset, int whence)

> -{

> -  loff_t retval;

> -

> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

> -				   (off_t) (offset & 0xffffffff),

> -				   &retval, whence) ?: retval);

> -}

> -weak_alias (__llseek, llseek)

> -strong_alias (__llseek, __libc_lseek64)

> -strong_alias (__llseek, __lseek64)

> -weak_alias (__llseek, lseek64)

> -

> -/* llseek doesn't have a prototype.  Since the second parameter is a

> -   64bit type, this results in wrong behaviour if no prototype is

> -   provided.  */

> -link_warning (llseek, "\

> -the `llseek' function may be dangerous; use `lseek64' instead.")

> diff --git a/sysdeps/unix/sysv/linux/lseek.c b/sysdeps/unix/sysv/linux/lseek.c

> new file mode 100644

> index 0000000..568df01

> --- /dev/null

> +++ b/sysdeps/unix/sysv/linux/lseek.c

> @@ -0,0 +1,56 @@

> +/* Copyright (C) 2016 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

> +   <http://www.gnu.org/licenses/>.  */

> +

> +#include <unistd.h>

> +#include <stdint.h>

> +#include <sys/types.h>

> +#include <sysdep.h>

> +#include <errno.h>

> +

> +#ifndef __OFF_T_MATCHES_OFF64_T

> +

> +/* 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

> +   only expose the low 32 bits of some fields.  */

> +

> +static inline off_t lseek_overflow (loff_t res)

> +{

> +  off_t retval = (off_t) res;

> +  if (retval == res)

> +    return retval;

> +

> +  __set_errno (EOVERFLOW);

> +  return (off_t) -1;

> +}

> +

> +off_t

> +__lseek (int fd, off_t offset, int whence)

> +{

> +# ifdef __NR__llseek

> +  loff_t res;

> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

> +				(long) (((uint64_t) (offset)) >> 32),

> +				(long) offset, &res, whence);

> +  return rc ?: lseek_overflow (res);

> +# else

> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

> +# endif

> +}

> +libc_hidden_def (__lseek)

> +weak_alias (__lseek, lseek)

> +strong_alias (__lseek, __libc_lseek)

> +#endif /* __OFF_T_MATCHES_OFF64_T  */

> diff --git a/sysdeps/unix/sysv/linux/lseek64.c b/sysdeps/unix/sysv/linux/lseek64.c

> index d81e98f..7e1ff23 100644

> --- a/sysdeps/unix/sysv/linux/lseek64.c

> +++ b/sysdeps/unix/sysv/linux/lseek64.c

> @@ -1 +1,53 @@

> -/* We don't need a definition since the llseek function is what we need.  */

> +/* Copyright (C) 2016 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

> +   <http://www.gnu.org/licenses/>.  */

> +

> +#include <unistd.h>

> +#include <stdint.h>

> +#include <sys/types.h>

> +#include <sysdep.h>

> +#include <errno.h>

> +

> +off64_t

> +__lseek64 (int fd, off64_t offset, int whence)

> +{

> +#ifdef __NR__llseek

> +  loff_t res;

> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

> +				(long) (((uint64_t) (offset)) >> 32),

> +				(long) offset, &res, whence);

> +  return rc ?: res;

> +#else

> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

> +#endif

> +}

> +

> +#ifdef  __OFF_T_MATCHES_OFF64_T

> +weak_alias (__lseek64, lseek)

> +weak_alias (__lseek64, __lseek)

> +strong_alias (__lseek64, __libc_lseek)

> +libc_hidden_def (__lseek)

> +#endif

> +

> +strong_alias (__lseek64, __libc_lseek64)

> +weak_alias (__lseek64, lseek64)

> +

> +/* llseek doesn't have a prototype.  Since the second parameter is a

> +   64bit type, this results in wrong behaviour if no prototype is

> +   provided.  */

> +weak_alias (__lseek64, llseek)

> +link_warning (llseek, "\

> +the `llseek' function may be dangerous; use `lseek64' instead.")

> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c b/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

> deleted file mode 100644

> index 24013a8..0000000

> --- a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

> +++ /dev/null

> @@ -1 +0,0 @@

> -/* lseek() is 64-bit capable already.  */

> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

> index 66cc687..d2d851e 100644

> --- a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

> +++ b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

> @@ -1,7 +1,5 @@

>  # File name	Caller	Syscall name	Args	Strong name	Weak names

>  

> -lseek		-	lseek		i:iii	__libc_lseek	__lseek lseek __llseek llseek __libc_lseek64 __lseek64 lseek64

> -

>  ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64

>  truncate	-	truncate	i:si	truncate	truncate64

>  

> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

> index 2eb9419..3f3569f 100644

> --- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

> +++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

> @@ -1,8 +1,5 @@

>  # File name	Caller	Syscall name	# args	Strong name	Weak names

>  

> -# Whee! 64-bit systems naturally implement llseek.

> -llseek		EXTRA	lseek		i:iii	__libc_lseek	__lseek lseek __libc_lseek64 __llseek llseek __lseek64 lseek64

> -lseek		llseek	-

>  fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs fstatfs64 __fstatfs64

>  statfs		-	statfs		i:sp	__statfs	statfs statfs64

>  mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64

> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

> new file mode 100644

> index 0000000..d81e98f

> --- /dev/null

> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

> @@ -0,0 +1 @@

> +/* We don't need a definition since the llseek function is what we need.  */

>
Adhemerval Zanella Netto Oct. 25, 2016, 5:53 p.m. UTC | #2
Ping (x2).

On 11/10/2016 11:39, Adhemerval Zanella wrote:
> Ping.

> 

> On 20/09/2016 12:01, Adhemerval Zanella wrote:

>> Changes from previous version:

>>

>>   - lseek64 logic to define which syscall to use depends only of

>>     __NR__llseek and __NR_lseek avaliability (instead of relying on

>>     __OFF_T_MATCHES_OFF64_T).  This is make new ports that might

>>     define __OFF_T_MATCHES_OFF64_T, but still use the __NR__llseek

>>     (such as aarch64 ilp32).

>>

>>   - Add a guard while defining __NR__llseek only if __NR_llseek is

>>     also defined.

>>

>>   - Rebase for new pthread compat wrappers Makefile changes.

>>

>> --

>>

>> This patch consolidates all Linux lseek/lseek64/llseek implementation

>> in on on sysdeps/unix/sysv/linux/lseek{64}.c.  It also removes the llseek

>> file and instead consolidate the LFS lseek implementation on lseek64.c

>> as for other LFS symbols implementations.

>>

>> The general idea is:

>>

>>   - lseek: ABIs that not define __OFF_T_MATCHES_OFF64_T will preferable

>>   use __NR__llseek if kernel supports it, otherwise they will use __NR_lseek.

>>   ABIs that defines __OFF_T_MATCHES_OFF64_T won't produce any symbol.

>>

>>   - lseek64: ABIs with __OFF_T_MATCHES_OFF64_T will preferable use __NR_lseek

>>   (since it will use 64-bit arguments without low/high splitting) and

>>   __NR__llseek if __NR_lseek is not defined (for some ILP32 ports).

>>

>>   - llseek: files will be removed and symbols will be aliased ot lseek64.

>>

>> ABI without __OFF_T_MATCHES_OFF64_T and without __NR_llseek (basically MIPS64n32

>> so far) are covered by building lseek with off_t as expected and lseek64

>> using __NR_lseek (as expected for off64_t being passed using 64-bit registers).

>>

>> For this consolidation I mantained the x32 assembly specific implementation

>> because to correctly fix this it would required both the x32 fix for

>> {INLINE,INTERNAL}_SYSCALL [1] and a wrapper to correctly subscribe it to

>> return 64 bits instead of default 32 bits (as for times).  It could a future

>> cleanup.

>>

>> It is based on my previous {INTERNAL,INLINE}_SYSCALL_CALL macro [2],

>> although it is mainly for simplification.

>>

>> Tested on x86_64, i686, aarch64, armhf, and powerpc64le.

>>

>> 	* nptl/Makefile (pthread-compat-wrappers): Remove llseek and add

>> 	lseek64.

>> 	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Remove llseek.

>> 	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdeps_routines):

>> 	Likewise.

>> 	* sysdeps/unix/sysv/linux/generic/sysdep.h (__NR__llseek): Define iff

>> 	__NR_llseek is defined.

>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: Remove file.

>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: Remove file.

>> 	* sysdeps/unix/sysv/linux/mips/mips64/llseek.c: Likewise.

>> 	* sysdeps/unix/sysv/linux/llseek.c: Remove file.

>> 	* sysdeps/unix/sysv/linux/lseek.c: New file.

>> 	* sysdeps/unix/sysv/linux/lseek64.c: Add default Linux implementation.

>> 	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list: Remove lseek and

>> 	__libc_lseek64 from auto-generation.

>> 	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.

>> 	* sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S: New file.

>>

>> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00443.html

>> [2] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html

>> ---

>>  nptl/Makefile                                      |  2 +-

>>  sysdeps/unix/sysv/linux/Makefile                   |  2 +-

>>  sysdeps/unix/sysv/linux/alpha/Makefile             |  2 +-

>>  sysdeps/unix/sysv/linux/generic/sysdep.h           |  4 +-

>>  .../unix/sysv/linux/generic/wordsize-32/llseek.c   | 46 ------------------

>>  .../unix/sysv/linux/generic/wordsize-32/lseek.c    | 38 ---------------

>>  sysdeps/unix/sysv/linux/llseek.c                   | 46 ------------------

>>  sysdeps/unix/sysv/linux/lseek.c                    | 56 ++++++++++++++++++++++

>>  sysdeps/unix/sysv/linux/lseek64.c                  | 54 ++++++++++++++++++++-

>>  sysdeps/unix/sysv/linux/mips/mips64/llseek.c       |  1 -

>>  sysdeps/unix/sysv/linux/mips/mips64/syscalls.list  |  2 -

>>  sysdeps/unix/sysv/linux/wordsize-64/syscalls.list  |  3 --

>>  sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S       |  1 +

>>  13 files changed, 116 insertions(+), 141 deletions(-)

>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>>  delete mode 100644 sysdeps/unix/sysv/linux/llseek.c

>>  create mode 100644 sysdeps/unix/sysv/linux/lseek.c

>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>>  create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>>

>> diff --git a/nptl/Makefile b/nptl/Makefile

>> index e9485df..ee828fe 100644

>> --- a/nptl/Makefile

>> +++ b/nptl/Makefile

>> @@ -38,7 +38,7 @@ shared-only-routines = forward

>>  pthread-compat-wrappers = \

>>  		      write read close fcntl accept \

>>  		      connect recv recvfrom send \

>> -		      sendto fsync lseek llseek \

>> +		      sendto fsync lseek lseek64 \

>>  		      msync nanosleep open open64 pause \

>>  		      pread pread64 pwrite pwrite64 \

>>  		      tcdrain wait waitpid msgrcv msgsnd \

>> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile

>> index 9a0423e..16a61cb 100644

>> --- a/sysdeps/unix/sysv/linux/Makefile

>> +++ b/sysdeps/unix/sysv/linux/Makefile

>> @@ -14,7 +14,7 @@ endif

>>  ifeq ($(subdir),misc)

>>  include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))

>>  

>> -sysdep_routines += clone llseek umount umount2 readahead \

>> +sysdep_routines += clone umount umount2 readahead \

>>  		   setfsuid setfsgid epoll_pwait signalfd \

>>  		   eventfd eventfd_read eventfd_write prlimit \

>>  		   personality

>> diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile

>> index 1e858ce..45941b0 100644

>> --- a/sysdeps/unix/sysv/linux/alpha/Makefile

>> +++ b/sysdeps/unix/sysv/linux/alpha/Makefile

>> @@ -10,7 +10,7 @@ ifeq ($(subdir),misc)

>>  sysdep_headers += alpha/ptrace.h alpha/regdef.h sys/io.h

>>  

>>  sysdep_routines += ieee_get_fp_control ieee_set_fp_control \

>> -		   ioperm llseek

>> +		   ioperm

>>  

>>  # Support old timeval32 entry points

>>  sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \

>> diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h

>> index b0422ff..6d379cc 100644

>> --- a/sysdeps/unix/sysv/linux/generic/sysdep.h

>> +++ b/sysdeps/unix/sysv/linux/generic/sysdep.h

>> @@ -22,7 +22,9 @@

>>  #include <sysdeps/unix/sysv/linux/sysdep.h>

>>  

>>  /* Provide the common name to allow more code reuse.  */

>> -#define __NR__llseek __NR_llseek

>> +#ifdef __NR_llseek

>> +# define __NR__llseek __NR_llseek

>> +#endif

>>  

>>  #if __WORDSIZE == 64

>>  /* By defining the older names, glibc will build syscall wrappers for

>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>> deleted file mode 100644

>> index 458964c..0000000

>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>> +++ /dev/null

>> @@ -1,46 +0,0 @@

>> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

>> -   This file is part of the GNU C Library.

>> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

>> -

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

>> -   <http://www.gnu.org/licenses/>.  */

>> -

>> -#include <errno.h>

>> -#include <sys/types.h>

>> -

>> -#include <sysdep.h>

>> -#include <sys/syscall.h>

>> -

>> -/* Seek to OFFSET on FD, starting from WHENCE.  */

>> -extern loff_t __llseek (int fd, loff_t offset, int whence);

>> -

>> -loff_t

>> -__llseek (int fd, loff_t offset, int whence)

>> -{

>> -  loff_t retval;

>> -

>> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

>> -				   (off_t) (offset & 0xffffffff),

>> -				   &retval, whence) ?: retval);

>> -}

>> -weak_alias (__llseek, llseek)

>> -strong_alias (__llseek, __libc_lseek64)

>> -strong_alias (__llseek, __lseek64)

>> -weak_alias (__llseek, lseek64)

>> -

>> -/* llseek doesn't have a prototype.  Since the second parameter is a

>> -   64bit type, this results in wrong behaviour if no prototype is

>> -   provided.  */

>> -link_warning (llseek, "\

>> -the `llseek' function may be dangerous; use `lseek64' instead.")

>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>> deleted file mode 100644

>> index dbf0b26..0000000

>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>> +++ /dev/null

>> @@ -1,38 +0,0 @@

>> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

>> -   This file is part of the GNU C Library.

>> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

>> -

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

>> -   <http://www.gnu.org/licenses/>.  */

>> -

>> -#include <errno.h>

>> -#include <unistd.h>

>> -#include <sys/types.h>

>> -

>> -#include <sysdep.h>

>> -#include <sys/syscall.h>

>> -

>> -#include "overflow.h"

>> -

>> -off_t

>> -__lseek (int fd, off_t offset, int whence)

>> -{

>> -  loff_t res;

>> -  int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31),

>> -                           (off_t) offset, &res, whence);

>> -  return rc ?: lseek_overflow (res);

>> -}

>> -libc_hidden_def (__lseek)

>> -weak_alias (__lseek, lseek)

>> -strong_alias (__lseek, __libc_lseek)

>> diff --git a/sysdeps/unix/sysv/linux/llseek.c b/sysdeps/unix/sysv/linux/llseek.c

>> deleted file mode 100644

>> index b6f3ea5..0000000

>> --- a/sysdeps/unix/sysv/linux/llseek.c

>> +++ /dev/null

>> @@ -1,46 +0,0 @@

>> -/* Long-long seek operation.

>> -   Copyright (C) 1996-2016 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

>> -   <http://www.gnu.org/licenses/>.  */

>> -

>> -#include <errno.h>

>> -#include <sys/types.h>

>> -

>> -#include <sysdep.h>

>> -#include <sys/syscall.h>

>> -

>> -/* Seek to OFFSET on FD, starting from WHENCE.  */

>> -extern loff_t __llseek (int fd, loff_t offset, int whence);

>> -

>> -loff_t

>> -__llseek (int fd, loff_t offset, int whence)

>> -{

>> -  loff_t retval;

>> -

>> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

>> -				   (off_t) (offset & 0xffffffff),

>> -				   &retval, whence) ?: retval);

>> -}

>> -weak_alias (__llseek, llseek)

>> -strong_alias (__llseek, __libc_lseek64)

>> -strong_alias (__llseek, __lseek64)

>> -weak_alias (__llseek, lseek64)

>> -

>> -/* llseek doesn't have a prototype.  Since the second parameter is a

>> -   64bit type, this results in wrong behaviour if no prototype is

>> -   provided.  */

>> -link_warning (llseek, "\

>> -the `llseek' function may be dangerous; use `lseek64' instead.")

>> diff --git a/sysdeps/unix/sysv/linux/lseek.c b/sysdeps/unix/sysv/linux/lseek.c

>> new file mode 100644

>> index 0000000..568df01

>> --- /dev/null

>> +++ b/sysdeps/unix/sysv/linux/lseek.c

>> @@ -0,0 +1,56 @@

>> +/* Copyright (C) 2016 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

>> +   <http://www.gnu.org/licenses/>.  */

>> +

>> +#include <unistd.h>

>> +#include <stdint.h>

>> +#include <sys/types.h>

>> +#include <sysdep.h>

>> +#include <errno.h>

>> +

>> +#ifndef __OFF_T_MATCHES_OFF64_T

>> +

>> +/* 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

>> +   only expose the low 32 bits of some fields.  */

>> +

>> +static inline off_t lseek_overflow (loff_t res)

>> +{

>> +  off_t retval = (off_t) res;

>> +  if (retval == res)

>> +    return retval;

>> +

>> +  __set_errno (EOVERFLOW);

>> +  return (off_t) -1;

>> +}

>> +

>> +off_t

>> +__lseek (int fd, off_t offset, int whence)

>> +{

>> +# ifdef __NR__llseek

>> +  loff_t res;

>> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

>> +				(long) (((uint64_t) (offset)) >> 32),

>> +				(long) offset, &res, whence);

>> +  return rc ?: lseek_overflow (res);

>> +# else

>> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

>> +# endif

>> +}

>> +libc_hidden_def (__lseek)

>> +weak_alias (__lseek, lseek)

>> +strong_alias (__lseek, __libc_lseek)

>> +#endif /* __OFF_T_MATCHES_OFF64_T  */

>> diff --git a/sysdeps/unix/sysv/linux/lseek64.c b/sysdeps/unix/sysv/linux/lseek64.c

>> index d81e98f..7e1ff23 100644

>> --- a/sysdeps/unix/sysv/linux/lseek64.c

>> +++ b/sysdeps/unix/sysv/linux/lseek64.c

>> @@ -1 +1,53 @@

>> -/* We don't need a definition since the llseek function is what we need.  */

>> +/* Copyright (C) 2016 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

>> +   <http://www.gnu.org/licenses/>.  */

>> +

>> +#include <unistd.h>

>> +#include <stdint.h>

>> +#include <sys/types.h>

>> +#include <sysdep.h>

>> +#include <errno.h>

>> +

>> +off64_t

>> +__lseek64 (int fd, off64_t offset, int whence)

>> +{

>> +#ifdef __NR__llseek

>> +  loff_t res;

>> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

>> +				(long) (((uint64_t) (offset)) >> 32),

>> +				(long) offset, &res, whence);

>> +  return rc ?: res;

>> +#else

>> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

>> +#endif

>> +}

>> +

>> +#ifdef  __OFF_T_MATCHES_OFF64_T

>> +weak_alias (__lseek64, lseek)

>> +weak_alias (__lseek64, __lseek)

>> +strong_alias (__lseek64, __libc_lseek)

>> +libc_hidden_def (__lseek)

>> +#endif

>> +

>> +strong_alias (__lseek64, __libc_lseek64)

>> +weak_alias (__lseek64, lseek64)

>> +

>> +/* llseek doesn't have a prototype.  Since the second parameter is a

>> +   64bit type, this results in wrong behaviour if no prototype is

>> +   provided.  */

>> +weak_alias (__lseek64, llseek)

>> +link_warning (llseek, "\

>> +the `llseek' function may be dangerous; use `lseek64' instead.")

>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c b/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>> deleted file mode 100644

>> index 24013a8..0000000

>> --- a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>> +++ /dev/null

>> @@ -1 +0,0 @@

>> -/* lseek() is 64-bit capable already.  */

>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>> index 66cc687..d2d851e 100644

>> --- a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>> +++ b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>> @@ -1,7 +1,5 @@

>>  # File name	Caller	Syscall name	Args	Strong name	Weak names

>>  

>> -lseek		-	lseek		i:iii	__libc_lseek	__lseek lseek __llseek llseek __libc_lseek64 __lseek64 lseek64

>> -

>>  ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64

>>  truncate	-	truncate	i:si	truncate	truncate64

>>  

>> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>> index 2eb9419..3f3569f 100644

>> --- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>> +++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>> @@ -1,8 +1,5 @@

>>  # File name	Caller	Syscall name	# args	Strong name	Weak names

>>  

>> -# Whee! 64-bit systems naturally implement llseek.

>> -llseek		EXTRA	lseek		i:iii	__libc_lseek	__lseek lseek __libc_lseek64 __llseek llseek __lseek64 lseek64

>> -lseek		llseek	-

>>  fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs fstatfs64 __fstatfs64

>>  statfs		-	statfs		i:sp	__statfs	statfs statfs64

>>  mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64

>> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>> new file mode 100644

>> index 0000000..d81e98f

>> --- /dev/null

>> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>> @@ -0,0 +1 @@

>> +/* We don't need a definition since the llseek function is what we need.  */

>>
Adhemerval Zanella Netto Nov. 4, 2016, 4:22 p.m. UTC | #3
Does anyone have any objection with this patch? If no one opposes I 
would like to push it to avoid get in late near freeze.

On 25/10/2016 15:53, Adhemerval Zanella wrote:
> Ping (x2).

> 

> On 11/10/2016 11:39, Adhemerval Zanella wrote:

>> Ping.

>>

>> On 20/09/2016 12:01, Adhemerval Zanella wrote:

>>> Changes from previous version:

>>>

>>>   - lseek64 logic to define which syscall to use depends only of

>>>     __NR__llseek and __NR_lseek avaliability (instead of relying on

>>>     __OFF_T_MATCHES_OFF64_T).  This is make new ports that might

>>>     define __OFF_T_MATCHES_OFF64_T, but still use the __NR__llseek

>>>     (such as aarch64 ilp32).

>>>

>>>   - Add a guard while defining __NR__llseek only if __NR_llseek is

>>>     also defined.

>>>

>>>   - Rebase for new pthread compat wrappers Makefile changes.

>>>

>>> --

>>>

>>> This patch consolidates all Linux lseek/lseek64/llseek implementation

>>> in on on sysdeps/unix/sysv/linux/lseek{64}.c.  It also removes the llseek

>>> file and instead consolidate the LFS lseek implementation on lseek64.c

>>> as for other LFS symbols implementations.

>>>

>>> The general idea is:

>>>

>>>   - lseek: ABIs that not define __OFF_T_MATCHES_OFF64_T will preferable

>>>   use __NR__llseek if kernel supports it, otherwise they will use __NR_lseek.

>>>   ABIs that defines __OFF_T_MATCHES_OFF64_T won't produce any symbol.

>>>

>>>   - lseek64: ABIs with __OFF_T_MATCHES_OFF64_T will preferable use __NR_lseek

>>>   (since it will use 64-bit arguments without low/high splitting) and

>>>   __NR__llseek if __NR_lseek is not defined (for some ILP32 ports).

>>>

>>>   - llseek: files will be removed and symbols will be aliased ot lseek64.

>>>

>>> ABI without __OFF_T_MATCHES_OFF64_T and without __NR_llseek (basically MIPS64n32

>>> so far) are covered by building lseek with off_t as expected and lseek64

>>> using __NR_lseek (as expected for off64_t being passed using 64-bit registers).

>>>

>>> For this consolidation I mantained the x32 assembly specific implementation

>>> because to correctly fix this it would required both the x32 fix for

>>> {INLINE,INTERNAL}_SYSCALL [1] and a wrapper to correctly subscribe it to

>>> return 64 bits instead of default 32 bits (as for times).  It could a future

>>> cleanup.

>>>

>>> It is based on my previous {INTERNAL,INLINE}_SYSCALL_CALL macro [2],

>>> although it is mainly for simplification.

>>>

>>> Tested on x86_64, i686, aarch64, armhf, and powerpc64le.

>>>

>>> 	* nptl/Makefile (pthread-compat-wrappers): Remove llseek and add

>>> 	lseek64.

>>> 	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Remove llseek.

>>> 	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdeps_routines):

>>> 	Likewise.

>>> 	* sysdeps/unix/sysv/linux/generic/sysdep.h (__NR__llseek): Define iff

>>> 	__NR_llseek is defined.

>>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: Remove file.

>>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: Remove file.

>>> 	* sysdeps/unix/sysv/linux/mips/mips64/llseek.c: Likewise.

>>> 	* sysdeps/unix/sysv/linux/llseek.c: Remove file.

>>> 	* sysdeps/unix/sysv/linux/lseek.c: New file.

>>> 	* sysdeps/unix/sysv/linux/lseek64.c: Add default Linux implementation.

>>> 	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list: Remove lseek and

>>> 	__libc_lseek64 from auto-generation.

>>> 	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.

>>> 	* sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S: New file.

>>>

>>> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00443.html

>>> [2] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html

>>> ---

>>>  nptl/Makefile                                      |  2 +-

>>>  sysdeps/unix/sysv/linux/Makefile                   |  2 +-

>>>  sysdeps/unix/sysv/linux/alpha/Makefile             |  2 +-

>>>  sysdeps/unix/sysv/linux/generic/sysdep.h           |  4 +-

>>>  .../unix/sysv/linux/generic/wordsize-32/llseek.c   | 46 ------------------

>>>  .../unix/sysv/linux/generic/wordsize-32/lseek.c    | 38 ---------------

>>>  sysdeps/unix/sysv/linux/llseek.c                   | 46 ------------------

>>>  sysdeps/unix/sysv/linux/lseek.c                    | 56 ++++++++++++++++++++++

>>>  sysdeps/unix/sysv/linux/lseek64.c                  | 54 ++++++++++++++++++++-

>>>  sysdeps/unix/sysv/linux/mips/mips64/llseek.c       |  1 -

>>>  sysdeps/unix/sysv/linux/mips/mips64/syscalls.list  |  2 -

>>>  sysdeps/unix/sysv/linux/wordsize-64/syscalls.list  |  3 --

>>>  sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S       |  1 +

>>>  13 files changed, 116 insertions(+), 141 deletions(-)

>>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>>>  delete mode 100644 sysdeps/unix/sysv/linux/llseek.c

>>>  create mode 100644 sysdeps/unix/sysv/linux/lseek.c

>>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>>>  create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>>>

>>> diff --git a/nptl/Makefile b/nptl/Makefile

>>> index e9485df..ee828fe 100644

>>> --- a/nptl/Makefile

>>> +++ b/nptl/Makefile

>>> @@ -38,7 +38,7 @@ shared-only-routines = forward

>>>  pthread-compat-wrappers = \

>>>  		      write read close fcntl accept \

>>>  		      connect recv recvfrom send \

>>> -		      sendto fsync lseek llseek \

>>> +		      sendto fsync lseek lseek64 \

>>>  		      msync nanosleep open open64 pause \

>>>  		      pread pread64 pwrite pwrite64 \

>>>  		      tcdrain wait waitpid msgrcv msgsnd \

>>> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile

>>> index 9a0423e..16a61cb 100644

>>> --- a/sysdeps/unix/sysv/linux/Makefile

>>> +++ b/sysdeps/unix/sysv/linux/Makefile

>>> @@ -14,7 +14,7 @@ endif

>>>  ifeq ($(subdir),misc)

>>>  include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))

>>>  

>>> -sysdep_routines += clone llseek umount umount2 readahead \

>>> +sysdep_routines += clone umount umount2 readahead \

>>>  		   setfsuid setfsgid epoll_pwait signalfd \

>>>  		   eventfd eventfd_read eventfd_write prlimit \

>>>  		   personality

>>> diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile

>>> index 1e858ce..45941b0 100644

>>> --- a/sysdeps/unix/sysv/linux/alpha/Makefile

>>> +++ b/sysdeps/unix/sysv/linux/alpha/Makefile

>>> @@ -10,7 +10,7 @@ ifeq ($(subdir),misc)

>>>  sysdep_headers += alpha/ptrace.h alpha/regdef.h sys/io.h

>>>  

>>>  sysdep_routines += ieee_get_fp_control ieee_set_fp_control \

>>> -		   ioperm llseek

>>> +		   ioperm

>>>  

>>>  # Support old timeval32 entry points

>>>  sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \

>>> diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h

>>> index b0422ff..6d379cc 100644

>>> --- a/sysdeps/unix/sysv/linux/generic/sysdep.h

>>> +++ b/sysdeps/unix/sysv/linux/generic/sysdep.h

>>> @@ -22,7 +22,9 @@

>>>  #include <sysdeps/unix/sysv/linux/sysdep.h>

>>>  

>>>  /* Provide the common name to allow more code reuse.  */

>>> -#define __NR__llseek __NR_llseek

>>> +#ifdef __NR_llseek

>>> +# define __NR__llseek __NR_llseek

>>> +#endif

>>>  

>>>  #if __WORDSIZE == 64

>>>  /* By defining the older names, glibc will build syscall wrappers for

>>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>>> deleted file mode 100644

>>> index 458964c..0000000

>>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c

>>> +++ /dev/null

>>> @@ -1,46 +0,0 @@

>>> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

>>> -   This file is part of the GNU C Library.

>>> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

>>> -

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

>>> -   <http://www.gnu.org/licenses/>.  */

>>> -

>>> -#include <errno.h>

>>> -#include <sys/types.h>

>>> -

>>> -#include <sysdep.h>

>>> -#include <sys/syscall.h>

>>> -

>>> -/* Seek to OFFSET on FD, starting from WHENCE.  */

>>> -extern loff_t __llseek (int fd, loff_t offset, int whence);

>>> -

>>> -loff_t

>>> -__llseek (int fd, loff_t offset, int whence)

>>> -{

>>> -  loff_t retval;

>>> -

>>> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

>>> -				   (off_t) (offset & 0xffffffff),

>>> -				   &retval, whence) ?: retval);

>>> -}

>>> -weak_alias (__llseek, llseek)

>>> -strong_alias (__llseek, __libc_lseek64)

>>> -strong_alias (__llseek, __lseek64)

>>> -weak_alias (__llseek, lseek64)

>>> -

>>> -/* llseek doesn't have a prototype.  Since the second parameter is a

>>> -   64bit type, this results in wrong behaviour if no prototype is

>>> -   provided.  */

>>> -link_warning (llseek, "\

>>> -the `llseek' function may be dangerous; use `lseek64' instead.")

>>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>>> deleted file mode 100644

>>> index dbf0b26..0000000

>>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c

>>> +++ /dev/null

>>> @@ -1,38 +0,0 @@

>>> -/* Copyright (C) 2011-2016 Free Software Foundation, Inc.

>>> -   This file is part of the GNU C Library.

>>> -   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

>>> -

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

>>> -   <http://www.gnu.org/licenses/>.  */

>>> -

>>> -#include <errno.h>

>>> -#include <unistd.h>

>>> -#include <sys/types.h>

>>> -

>>> -#include <sysdep.h>

>>> -#include <sys/syscall.h>

>>> -

>>> -#include "overflow.h"

>>> -

>>> -off_t

>>> -__lseek (int fd, off_t offset, int whence)

>>> -{

>>> -  loff_t res;

>>> -  int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31),

>>> -                           (off_t) offset, &res, whence);

>>> -  return rc ?: lseek_overflow (res);

>>> -}

>>> -libc_hidden_def (__lseek)

>>> -weak_alias (__lseek, lseek)

>>> -strong_alias (__lseek, __libc_lseek)

>>> diff --git a/sysdeps/unix/sysv/linux/llseek.c b/sysdeps/unix/sysv/linux/llseek.c

>>> deleted file mode 100644

>>> index b6f3ea5..0000000

>>> --- a/sysdeps/unix/sysv/linux/llseek.c

>>> +++ /dev/null

>>> @@ -1,46 +0,0 @@

>>> -/* Long-long seek operation.

>>> -   Copyright (C) 1996-2016 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

>>> -   <http://www.gnu.org/licenses/>.  */

>>> -

>>> -#include <errno.h>

>>> -#include <sys/types.h>

>>> -

>>> -#include <sysdep.h>

>>> -#include <sys/syscall.h>

>>> -

>>> -/* Seek to OFFSET on FD, starting from WHENCE.  */

>>> -extern loff_t __llseek (int fd, loff_t offset, int whence);

>>> -

>>> -loff_t

>>> -__llseek (int fd, loff_t offset, int whence)

>>> -{

>>> -  loff_t retval;

>>> -

>>> -  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),

>>> -				   (off_t) (offset & 0xffffffff),

>>> -				   &retval, whence) ?: retval);

>>> -}

>>> -weak_alias (__llseek, llseek)

>>> -strong_alias (__llseek, __libc_lseek64)

>>> -strong_alias (__llseek, __lseek64)

>>> -weak_alias (__llseek, lseek64)

>>> -

>>> -/* llseek doesn't have a prototype.  Since the second parameter is a

>>> -   64bit type, this results in wrong behaviour if no prototype is

>>> -   provided.  */

>>> -link_warning (llseek, "\

>>> -the `llseek' function may be dangerous; use `lseek64' instead.")

>>> diff --git a/sysdeps/unix/sysv/linux/lseek.c b/sysdeps/unix/sysv/linux/lseek.c

>>> new file mode 100644

>>> index 0000000..568df01

>>> --- /dev/null

>>> +++ b/sysdeps/unix/sysv/linux/lseek.c

>>> @@ -0,0 +1,56 @@

>>> +/* Copyright (C) 2016 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

>>> +   <http://www.gnu.org/licenses/>.  */

>>> +

>>> +#include <unistd.h>

>>> +#include <stdint.h>

>>> +#include <sys/types.h>

>>> +#include <sysdep.h>

>>> +#include <errno.h>

>>> +

>>> +#ifndef __OFF_T_MATCHES_OFF64_T

>>> +

>>> +/* 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

>>> +   only expose the low 32 bits of some fields.  */

>>> +

>>> +static inline off_t lseek_overflow (loff_t res)

>>> +{

>>> +  off_t retval = (off_t) res;

>>> +  if (retval == res)

>>> +    return retval;

>>> +

>>> +  __set_errno (EOVERFLOW);

>>> +  return (off_t) -1;

>>> +}

>>> +

>>> +off_t

>>> +__lseek (int fd, off_t offset, int whence)

>>> +{

>>> +# ifdef __NR__llseek

>>> +  loff_t res;

>>> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

>>> +				(long) (((uint64_t) (offset)) >> 32),

>>> +				(long) offset, &res, whence);

>>> +  return rc ?: lseek_overflow (res);

>>> +# else

>>> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

>>> +# endif

>>> +}

>>> +libc_hidden_def (__lseek)

>>> +weak_alias (__lseek, lseek)

>>> +strong_alias (__lseek, __libc_lseek)

>>> +#endif /* __OFF_T_MATCHES_OFF64_T  */

>>> diff --git a/sysdeps/unix/sysv/linux/lseek64.c b/sysdeps/unix/sysv/linux/lseek64.c

>>> index d81e98f..7e1ff23 100644

>>> --- a/sysdeps/unix/sysv/linux/lseek64.c

>>> +++ b/sysdeps/unix/sysv/linux/lseek64.c

>>> @@ -1 +1,53 @@

>>> -/* We don't need a definition since the llseek function is what we need.  */

>>> +/* Copyright (C) 2016 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

>>> +   <http://www.gnu.org/licenses/>.  */

>>> +

>>> +#include <unistd.h>

>>> +#include <stdint.h>

>>> +#include <sys/types.h>

>>> +#include <sysdep.h>

>>> +#include <errno.h>

>>> +

>>> +off64_t

>>> +__lseek64 (int fd, off64_t offset, int whence)

>>> +{

>>> +#ifdef __NR__llseek

>>> +  loff_t res;

>>> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd,

>>> +				(long) (((uint64_t) (offset)) >> 32),

>>> +				(long) offset, &res, whence);

>>> +  return rc ?: res;

>>> +#else

>>> +  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);

>>> +#endif

>>> +}

>>> +

>>> +#ifdef  __OFF_T_MATCHES_OFF64_T

>>> +weak_alias (__lseek64, lseek)

>>> +weak_alias (__lseek64, __lseek)

>>> +strong_alias (__lseek64, __libc_lseek)

>>> +libc_hidden_def (__lseek)

>>> +#endif

>>> +

>>> +strong_alias (__lseek64, __libc_lseek64)

>>> +weak_alias (__lseek64, lseek64)

>>> +

>>> +/* llseek doesn't have a prototype.  Since the second parameter is a

>>> +   64bit type, this results in wrong behaviour if no prototype is

>>> +   provided.  */

>>> +weak_alias (__lseek64, llseek)

>>> +link_warning (llseek, "\

>>> +the `llseek' function may be dangerous; use `lseek64' instead.")

>>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c b/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>>> deleted file mode 100644

>>> index 24013a8..0000000

>>> --- a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c

>>> +++ /dev/null

>>> @@ -1 +0,0 @@

>>> -/* lseek() is 64-bit capable already.  */

>>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>>> index 66cc687..d2d851e 100644

>>> --- a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>>> +++ b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list

>>> @@ -1,7 +1,5 @@

>>>  # File name	Caller	Syscall name	Args	Strong name	Weak names

>>>  

>>> -lseek		-	lseek		i:iii	__libc_lseek	__lseek lseek __llseek llseek __libc_lseek64 __lseek64 lseek64

>>> -

>>>  ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64

>>>  truncate	-	truncate	i:si	truncate	truncate64

>>>  

>>> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>>> index 2eb9419..3f3569f 100644

>>> --- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>>> +++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list

>>> @@ -1,8 +1,5 @@

>>>  # File name	Caller	Syscall name	# args	Strong name	Weak names

>>>  

>>> -# Whee! 64-bit systems naturally implement llseek.

>>> -llseek		EXTRA	lseek		i:iii	__libc_lseek	__lseek lseek __libc_lseek64 __llseek llseek __lseek64 lseek64

>>> -lseek		llseek	-

>>>  fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs fstatfs64 __fstatfs64

>>>  statfs		-	statfs		i:sp	__statfs	statfs statfs64

>>>  mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64

>>> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>>> new file mode 100644

>>> index 0000000..d81e98f

>>> --- /dev/null

>>> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

>>> @@ -0,0 +1 @@

>>> +/* We don't need a definition since the llseek function is what we need.  */

>>>
Steve Ellcey Nov. 8, 2016, 7:02 p.m. UTC | #4
On Fri, 2016-11-04 at 14:22 -0200, Adhemerval Zanella wrote:
> Does anyone have any objection with this patch? If no one opposes I 

> would like to push it to avoid get in late near freeze.


I am not a subcomponent maintainer or anything but I have tested the
patch on x86 and aarch64 and had no regressions with it.  I think it
looks good.

Steve Ellcey
sellcey@caviumnetworks.com
diff mbox

Patch

diff --git a/nptl/Makefile b/nptl/Makefile
index e9485df..ee828fe 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -38,7 +38,7 @@  shared-only-routines = forward
 pthread-compat-wrappers = \
 		      write read close fcntl accept \
 		      connect recv recvfrom send \
-		      sendto fsync lseek llseek \
+		      sendto fsync lseek lseek64 \
 		      msync nanosleep open open64 pause \
 		      pread pread64 pwrite pwrite64 \
 		      tcdrain wait waitpid msgrcv msgsnd \
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 9a0423e..16a61cb 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -14,7 +14,7 @@  endif
 ifeq ($(subdir),misc)
 include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 
-sysdep_routines += clone llseek umount umount2 readahead \
+sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality
diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
index 1e858ce..45941b0 100644
--- a/sysdeps/unix/sysv/linux/alpha/Makefile
+++ b/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -10,7 +10,7 @@  ifeq ($(subdir),misc)
 sysdep_headers += alpha/ptrace.h alpha/regdef.h sys/io.h
 
 sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
-		   ioperm llseek
+		   ioperm
 
 # Support old timeval32 entry points
 sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \
diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h
index b0422ff..6d379cc 100644
--- a/sysdeps/unix/sysv/linux/generic/sysdep.h
+++ b/sysdeps/unix/sysv/linux/generic/sysdep.h
@@ -22,7 +22,9 @@ 
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 
 /* Provide the common name to allow more code reuse.  */
-#define __NR__llseek __NR_llseek
+#ifdef __NR_llseek
+# define __NR__llseek __NR_llseek
+#endif
 
 #if __WORDSIZE == 64
 /* By defining the older names, glibc will build syscall wrappers for
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c
deleted file mode 100644
index 458964c..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c
+++ /dev/null
@@ -1,46 +0,0 @@ 
-/* Copyright (C) 2011-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   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
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/types.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Seek to OFFSET on FD, starting from WHENCE.  */
-extern loff_t __llseek (int fd, loff_t offset, int whence);
-
-loff_t
-__llseek (int fd, loff_t offset, int whence)
-{
-  loff_t retval;
-
-  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),
-				   (off_t) (offset & 0xffffffff),
-				   &retval, whence) ?: retval);
-}
-weak_alias (__llseek, llseek)
-strong_alias (__llseek, __libc_lseek64)
-strong_alias (__llseek, __lseek64)
-weak_alias (__llseek, lseek64)
-
-/* llseek doesn't have a prototype.  Since the second parameter is a
-   64bit type, this results in wrong behaviour if no prototype is
-   provided.  */
-link_warning (llseek, "\
-the `llseek' function may be dangerous; use `lseek64' instead.")
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c
deleted file mode 100644
index dbf0b26..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c
+++ /dev/null
@@ -1,38 +0,0 @@ 
-/* Copyright (C) 2011-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   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
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-#include "overflow.h"
-
-off_t
-__lseek (int fd, off_t offset, int whence)
-{
-  loff_t res;
-  int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31),
-                           (off_t) offset, &res, whence);
-  return rc ?: lseek_overflow (res);
-}
-libc_hidden_def (__lseek)
-weak_alias (__lseek, lseek)
-strong_alias (__lseek, __libc_lseek)
diff --git a/sysdeps/unix/sysv/linux/llseek.c b/sysdeps/unix/sysv/linux/llseek.c
deleted file mode 100644
index b6f3ea5..0000000
--- a/sysdeps/unix/sysv/linux/llseek.c
+++ /dev/null
@@ -1,46 +0,0 @@ 
-/* Long-long seek operation.
-   Copyright (C) 1996-2016 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
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/types.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Seek to OFFSET on FD, starting from WHENCE.  */
-extern loff_t __llseek (int fd, loff_t offset, int whence);
-
-loff_t
-__llseek (int fd, loff_t offset, int whence)
-{
-  loff_t retval;
-
-  return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),
-				   (off_t) (offset & 0xffffffff),
-				   &retval, whence) ?: retval);
-}
-weak_alias (__llseek, llseek)
-strong_alias (__llseek, __libc_lseek64)
-strong_alias (__llseek, __lseek64)
-weak_alias (__llseek, lseek64)
-
-/* llseek doesn't have a prototype.  Since the second parameter is a
-   64bit type, this results in wrong behaviour if no prototype is
-   provided.  */
-link_warning (llseek, "\
-the `llseek' function may be dangerous; use `lseek64' instead.")
diff --git a/sysdeps/unix/sysv/linux/lseek.c b/sysdeps/unix/sysv/linux/lseek.c
new file mode 100644
index 0000000..568df01
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/lseek.c
@@ -0,0 +1,56 @@ 
+/* Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <errno.h>
+
+#ifndef __OFF_T_MATCHES_OFF64_T
+
+/* 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
+   only expose the low 32 bits of some fields.  */
+
+static inline off_t lseek_overflow (loff_t res)
+{
+  off_t retval = (off_t) res;
+  if (retval == res)
+    return retval;
+
+  __set_errno (EOVERFLOW);
+  return (off_t) -1;
+}
+
+off_t
+__lseek (int fd, off_t offset, int whence)
+{
+# ifdef __NR__llseek
+  loff_t res;
+  int rc = INLINE_SYSCALL_CALL (_llseek, fd,
+				(long) (((uint64_t) (offset)) >> 32),
+				(long) offset, &res, whence);
+  return rc ?: lseek_overflow (res);
+# else
+  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);
+# endif
+}
+libc_hidden_def (__lseek)
+weak_alias (__lseek, lseek)
+strong_alias (__lseek, __libc_lseek)
+#endif /* __OFF_T_MATCHES_OFF64_T  */
diff --git a/sysdeps/unix/sysv/linux/lseek64.c b/sysdeps/unix/sysv/linux/lseek64.c
index d81e98f..7e1ff23 100644
--- a/sysdeps/unix/sysv/linux/lseek64.c
+++ b/sysdeps/unix/sysv/linux/lseek64.c
@@ -1 +1,53 @@ 
-/* We don't need a definition since the llseek function is what we need.  */
+/* Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <errno.h>
+
+off64_t
+__lseek64 (int fd, off64_t offset, int whence)
+{
+#ifdef __NR__llseek
+  loff_t res;
+  int rc = INLINE_SYSCALL_CALL (_llseek, fd,
+				(long) (((uint64_t) (offset)) >> 32),
+				(long) offset, &res, whence);
+  return rc ?: res;
+#else
+  return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);
+#endif
+}
+
+#ifdef  __OFF_T_MATCHES_OFF64_T
+weak_alias (__lseek64, lseek)
+weak_alias (__lseek64, __lseek)
+strong_alias (__lseek64, __libc_lseek)
+libc_hidden_def (__lseek)
+#endif
+
+strong_alias (__lseek64, __libc_lseek64)
+weak_alias (__lseek64, lseek64)
+
+/* llseek doesn't have a prototype.  Since the second parameter is a
+   64bit type, this results in wrong behaviour if no prototype is
+   provided.  */
+weak_alias (__lseek64, llseek)
+link_warning (llseek, "\
+the `llseek' function may be dangerous; use `lseek64' instead.")
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c b/sysdeps/unix/sysv/linux/mips/mips64/llseek.c
deleted file mode 100644
index 24013a8..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/llseek.c
+++ /dev/null
@@ -1 +0,0 @@ 
-/* lseek() is 64-bit capable already.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
index 66cc687..d2d851e 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
@@ -1,7 +1,5 @@ 
 # File name	Caller	Syscall name	Args	Strong name	Weak names
 
-lseek		-	lseek		i:iii	__libc_lseek	__lseek lseek __llseek llseek __libc_lseek64 __lseek64 lseek64
-
 ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64
 truncate	-	truncate	i:si	truncate	truncate64
 
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
index 2eb9419..3f3569f 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
@@ -1,8 +1,5 @@ 
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
-# Whee! 64-bit systems naturally implement llseek.
-llseek		EXTRA	lseek		i:iii	__libc_lseek	__lseek lseek __libc_lseek64 __llseek llseek __lseek64 lseek64
-lseek		llseek	-
 fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs fstatfs64 __fstatfs64
 statfs		-	statfs		i:sp	__statfs	statfs statfs64
 mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
new file mode 100644
index 0000000..d81e98f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
@@ -0,0 +1 @@ 
+/* We don't need a definition since the llseek function is what we need.  */