public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations
  2016-09-20 15:02 [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH 1/4] Add INTERNAL_SYSCALL_CALL Adhemerval Zanella
@ 2016-09-20 15:02 ` Adhemerval Zanella
  2016-10-11 14:40   ` Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH 4/4] Consolidate Linux truncate implementations Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH 3/4] Consolidate Linux ftruncate implementations Adhemerval Zanella
  3 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-20 15:02 UTC (permalink / raw)
  To: libc-alpha

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.  */
-- 
2.7.4

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

* [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-09-20 15:02 [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation Adhemerval Zanella
                   ` (2 preceding siblings ...)
  2016-09-20 15:02 ` [PATCH 4/4] Consolidate Linux truncate implementations Adhemerval Zanella
@ 2016-09-20 15:02 ` Adhemerval Zanella
  2016-10-11 14:41   ` Adhemerval Zanella
  2016-11-09 15:33   ` Andreas Schwab
  3 siblings, 2 replies; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-20 15:02 UTC (permalink / raw)
  To: libc-alpha

THis patch consolidates all Linux ftruncate implementation on
sysdeps/unix/sysv/linux/ftruncate{64}.c.  It is based on
{INTERNAL,INLINE}_SYSCALL patch [1] to simplify the syscall construction.

General idea is to build ftruncate iff __OFF_T_MATCHES_OFF64_T is not
defined, otherwise ftruncate64 will be build and ftruncate will be an
alias.  The fallocate will use old compat syscall and pass 32-bit off_t
argument, while fallocate64 will handle the correct off64_t passing using
__ALIGNMENT_ARG and SYSCALL_LL64 macros.

Tested on x86_64, i386, aarch64, and armhf.

	* posix/tst-truncate-common.c: New file.
	* posix/tst-truncate.c: Use tst-truncate-common.c.
	* posix/tst-truncate64.c: Likewise and add LFS tests.
	* sysdeps/unix/sysv/linux/arm/ftruncate64.c: Remove file.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c: Likewise.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/ftruncate.c: New file.
	* sysdeps/unix/sysv/linux/ftruncate64.c (__ftruncate64): Use
	INLINE_SYSCALL_CALL, __ALIGNMENT_ARG and SYSCALL_LL64 macros.
	[__OFF_T_MATCHES_OFF64_T] (ftruncate): Add alias.

[1] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
---
 posix/tst-truncate-common.c                        |  88 ++++++++++++++++
 posix/tst-truncate.c                               | 114 +--------------------
 posix/tst-truncate64.c                             |  21 +++-
 sysdeps/unix/sysv/linux/arm/ftruncate64.c          |  36 -------
 sysdeps/unix/sysv/linux/ftruncate.c                |  35 +++++++
 sysdeps/unix/sysv/linux/ftruncate64.c              |  21 ++--
 .../sysv/linux/generic/wordsize-32/ftruncate.c     |  31 ------
 .../sysv/linux/generic/wordsize-32/ftruncate64.c   |  32 ------
 sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c  |  36 -------
 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c  |   1 -
 .../sysv/linux/powerpc/powerpc32/ftruncate64.c     |  36 -------
 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c  |   1 -
 12 files changed, 156 insertions(+), 296 deletions(-)
 create mode 100644 posix/tst-truncate-common.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/ftruncate64.c
 create mode 100644 sysdeps/unix/sysv/linux/ftruncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c

diff --git a/posix/tst-truncate-common.c b/posix/tst-truncate-common.c
new file mode 100644
index 0000000..80bf277
--- /dev/null
+++ b/posix/tst-truncate-common.c
@@ -0,0 +1,88 @@
+/* Common f{truncate} tests definitions.
+   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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static void do_prepare (void);
+#define PREPARE(argc, argv)     do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION           do_test ()
+
+#include <test-skeleton.c>
+
+static char *temp_filename;
+static int temp_fd;
+
+static void
+do_prepare (void)
+{
+  temp_fd = create_temp_file ("tst-trucate.", &temp_filename);
+  if (temp_fd == -1)
+    {
+      printf ("cannot create temporary file: %m\n");
+      exit (1);
+    }
+}
+
+#define FAIL(str) \
+  do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0)
+
+static int
+do_test_with_offset (off_t offset)
+{
+  struct stat st;
+  char buf[1000];
+
+  memset (buf, 0xcf, sizeof (buf));
+
+  if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf))
+    FAIL ("write failed");
+  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf)))
+    FAIL ("initial size wrong");
+
+  if (ftruncate (temp_fd, offset + 800) < 0)
+    FAIL ("size reduction with ftruncate failed");
+  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
+    FAIL ("size after reduction with ftruncate is incorrect");
+
+  /* The following test covers more than POSIX.  POSIX does not require
+     that ftruncate() can increase the file size.  But we are testing
+     Unix systems.  */
+  if (ftruncate (temp_fd, offset + 1200) < 0)
+    FAIL ("size increate with ftruncate failed");
+  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
+    FAIL ("size after increase is incorrect");
+
+  if (truncate (temp_filename, offset + 800) < 0)
+    FAIL ("size reduction with truncate failed");
+  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
+    FAIL ("size after reduction with truncate incorrect");
+
+  /* The following test covers more than POSIX.  POSIX does not require
+     that truncate() can increase the file size.  But we are testing
+     Unix systems.  */
+  if (truncate (temp_filename, (offset + 1200)) < 0)
+    FAIL ("size increase with truncate failed");
+  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
+    FAIL ("size increase with truncate is incorrect");
+
+  return 0;
+}
diff --git a/posix/tst-truncate.c b/posix/tst-truncate.c
index 99bddb3..3166c3b 100644
--- a/posix/tst-truncate.c
+++ b/posix/tst-truncate.c
@@ -17,116 +17,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <error.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
+#include "tst-truncate-common.c"
 
-
-/* Allow testing of the 64-bit versions as well.  */
-#ifndef TRUNCATE
-# define TRUNCATE truncate
-# define FTRUNCATE ftruncate
-#endif
-
-#define STRINGIFY(s) STRINGIFY2 (s)
-#define STRINGIFY2(s) #s
-
-/* Prototype for our test function.  */
-extern void do_prepare (int argc, char *argv[]);
-extern int do_test (int argc, char *argv[]);
-
-/* We have a preparation function.  */
-#define PREPARE do_prepare
-
-/* We might need a bit longer timeout.  */
-#define TIMEOUT 20 /* sec */
-
-/* This defines the `main' function and some more.  */
-#include <test-skeleton.c>
-
-/* These are for the temporary file we generate.  */
-char *name;
-int fd;
-
-void
-do_prepare (int argc, char *argv[])
+static int
+do_test (void)
 {
-   size_t name_len;
-
-#define FNAME FNAME2(TRUNCATE)
-#define FNAME2(s) "/" STRINGIFY(s) "XXXXXX"
-
-   name_len = strlen (test_dir);
-   name = xmalloc (name_len + sizeof (FNAME));
-   mempcpy (mempcpy (name, test_dir, name_len), FNAME, sizeof (FNAME));
-   add_temp_file (name);
-
-   /* Open our test file.   */
-   fd = mkstemp (name);
-   if (fd == -1)
-     error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
-}
-
-
-int
-do_test (int argc, char *argv[])
-{
-  struct stat st;
-  char buf[1000];
-
-  memset (buf, '\0', sizeof (buf));
-
-  if (write (fd, buf, sizeof (buf)) != sizeof (buf))
-    error (EXIT_FAILURE, errno, "during write");
-
-  if (fstat (fd, &st) < 0 || st.st_size != sizeof (buf))
-    error (EXIT_FAILURE, 0, "initial size wrong");
-
-
-  if (FTRUNCATE (fd, 800) < 0)
-    error (EXIT_FAILURE, errno, "size reduction with %s failed",
-	   STRINGIFY (FTRUNCATE));
-
-  if (fstat (fd, &st) < 0 || st.st_size != 800)
-    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
-	   STRINGIFY (FTRUNCATE));
-
-  /* The following test covers more than POSIX.  POSIX does not require
-     that ftruncate() can increase the file size.  But we are testing
-     Unix systems.  */
-  if (FTRUNCATE (fd, 1200) < 0)
-    error (EXIT_FAILURE, errno, "size increase with %s failed",
-	   STRINGIFY (FTRUNCATE));
-
-  if (fstat (fd, &st) < 0 || st.st_size != 1200)
-    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
-	   STRINGIFY (FTRUNCATE));
-
-
-  if (TRUNCATE (name, 800) < 0)
-    error (EXIT_FAILURE, errno, "size reduction with %s failed",
-	   STRINGIFY (TRUNCATE));
-
-  if (fstat (fd, &st) < 0 || st.st_size != 800)
-    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
-	   STRINGIFY (TRUNCATE));
-
-  /* The following test covers more than POSIX.  POSIX does not require
-     that truncate() can increase the file size.  But we are testing
-     Unix systems.  */
-  if (TRUNCATE (name, 1200) < 0)
-    error (EXIT_FAILURE, errno, "size increase with %s failed",
-	   STRINGIFY (TRUNCATE));
-
-  if (fstat (fd, &st) < 0 || st.st_size != 1200)
-    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
-	   STRINGIFY (TRUNCATE));
-
-
-  close (fd);
-  unlink (name);
-
-  return 0;
+  return do_test_with_offset (0);
 }
diff --git a/posix/tst-truncate64.c b/posix/tst-truncate64.c
index 64eb0a4..08c4942 100644
--- a/posix/tst-truncate64.c
+++ b/posix/tst-truncate64.c
@@ -17,7 +17,22 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TRUNCATE truncate64
-#define FTRUNCATE ftruncate64
+#define _FILE_OFFSET_BITS 64
+#include "tst-truncate-common.c"
 
-#include "tst-truncate.c"
+static int
+do_test (void)
+{
+  int ret;
+
+  ret = do_test_with_offset (0);
+  if (ret == -1)
+    return -1;
+
+  off_t base_offset = UINT32_MAX + 512LL;
+  ret = do_test_with_offset (base_offset);
+  if (ret == -1)
+    return 1;
+
+  return 0;
+}
diff --git a/sysdeps/unix/sysv/linux/arm/ftruncate64.c b/sysdeps/unix/sysv/linux/arm/ftruncate64.c
deleted file mode 100644
index 0e8d8ba..0000000
--- a/sysdeps/unix/sysv/linux/arm/ftruncate64.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <errno.h>
-#include <endian.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-__ftruncate64 (int fd, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
-}
-weak_alias (__ftruncate64, ftruncate64)
diff --git a/sysdeps/unix/sysv/linux/ftruncate.c b/sysdeps/unix/sysv/linux/ftruncate.c
new file mode 100644
index 0000000..5c0cd44
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ftruncate.c
@@ -0,0 +1,35 @@
+/* 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 <sysdep.h>
+#include <errno.h>
+
+#ifndef __OFF_T_MATCHES_OFF64_T
+/* Truncate the file FD refers to LENGTH bytes.  */
+int
+__ftruncate (int fd, off_t length)
+{
+# ifndef __NR_ftruncate
+  return INLINE_SYSCALL_CALL (ftruncate64, fd,
+			      __ALIGNMENT_ARG SYSCALL_LL (length));
+# else
+  return INLINE_SYSCALL_CALL (ftruncate, fd, length);
+# endif
+}
+weak_alias (__ftruncate, ftruncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
index a6bf878..914ce67 100644
--- a/sysdeps/unix/sysv/linux/ftruncate64.c
+++ b/sysdeps/unix/sysv/linux/ftruncate64.c
@@ -15,22 +15,23 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sys/types.h>
-#include <errno.h>
-#include <endian.h>
 #include <unistd.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
+#include <errno.h>
+
+#ifndef __NR_ftruncate64
+# define __NR_ftruncate64 __NR_ftruncate
+#endif
 
 /* Truncate the file referenced by FD to LENGTH bytes.  */
 int
 __ftruncate64 (int fd, off64_t length)
 {
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (ftruncate64, 3, fd,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
+  return INLINE_SYSCALL_CALL (ftruncate64, fd,
+			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
 }
 weak_alias (__ftruncate64, ftruncate64)
+
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__ftruncate64, ftruncate);
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
deleted file mode 100644
index e1b500d..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
+++ /dev/null
@@ -1,31 +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 <unistd.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-__ftruncate (int fd, off_t length)
-{
-  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
-                         __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR (length >> 31, length));
-}
-weak_alias (__ftruncate, ftruncate)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
deleted file mode 100644
index 946f05a..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
+++ /dev/null
@@ -1,32 +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 <unistd.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-__ftruncate64 (int fd, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
-                         __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
-}
-weak_alias (__ftruncate64, ftruncate64)
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
deleted file mode 100644
index 0e8d8ba..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <errno.h>
-#include <endian.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-__ftruncate64 (int fd, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
-}
-weak_alias (__ftruncate64, ftruncate64)
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
deleted file mode 100644
index 6e25b02..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
deleted file mode 100644
index 9eee1d7..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file referenced by FD to LENGTH bytes.  */
-int
-__ftruncate64 (int fd, off64_t length)
-{
-  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
-			       (long) (length >> 32),
-			       (long) length);
-
-  return result;
-}
-weak_alias (__ftruncate64, ftruncate64)
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
deleted file mode 100644
index 673a8b5..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* ftruncate64 is the same as ftruncate. */
-- 
2.7.4

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

* [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-20 15:02 [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH 1/4] Add INTERNAL_SYSCALL_CALL Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations Adhemerval Zanella
@ 2016-09-20 15:02 ` Adhemerval Zanella
  2016-09-22 14:25   ` Yury Norov
  2016-09-20 15:02 ` [PATCH 3/4] Consolidate Linux ftruncate implementations Adhemerval Zanella
  3 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-20 15:02 UTC (permalink / raw)
  To: libc-alpha

Changes from previous version:

  - Using __NR_truncate64 for truncate in case of __NR_truncate is
    not defined.  This will still use 32-bit off_t offsets (similar to
    pread).

--

This patch consolidates all Linux truncate implementation on
sysdeps/unix/sysv/linux/truncate{64}.c.  It is based on
{INTERNAL,INLINE}_SYSCALL patch [1] to simplify the syscall
construction.

General idea is to build ftruncate iff __OFF_T_MATCHES_OFF64_T is not
defined, otherwise ftruncate64 will be build and ftruncate will be an
alias.  The fallocate will use old compat syscall and pass 32-bit off_t
argument, while fallocate64 will handle the correct off64_t passing using
__ALIGNMENT_ARG and SYSCALL_LL64 macros.

Tested on x86_64, i386, aarch64, and armhf.

	* sysdeps/unix/sysv/linux/arm/truncate64.c: Remove file.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c: Likewise.
	* sysdeps/sysv/linux/generic/wordsize-32/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/truncate.c: New file.
	* sysdeps/unix/sysv/linux/truncate64.c (truncate64): Use
	INLINE_SYSCALL_CALL, __ALIGNMENT_ARG and SYSCALL_LL64 macros.

[1] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
---
 sysdeps/unix/sysv/linux/arm/truncate64.c           | 35 ----------------------
 .../unix/sysv/linux/generic/wordsize-32/truncate.c | 31 -------------------
 .../sysv/linux/generic/wordsize-32/truncate64.c    | 31 -------------------
 sysdeps/unix/sysv/linux/mips/mips32/truncate64.c   | 35 ----------------------
 sysdeps/unix/sysv/linux/mips/mips64/truncate64.c   |  1 -
 .../unix/sysv/linux/powerpc/powerpc32/truncate64.c | 34 ---------------------
 sysdeps/unix/sysv/linux/truncate.c                 | 35 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/truncate64.c               | 26 ++++++++--------
 sysdeps/unix/sysv/linux/wordsize-64/truncate64.c   |  1 -
 9 files changed, 49 insertions(+), 180 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/arm/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
 create mode 100644 sysdeps/unix/sysv/linux/truncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/truncate64.c

diff --git a/sysdeps/unix/sysv/linux/arm/truncate64.c b/sysdeps/unix/sysv/linux/arm/truncate64.c
deleted file mode 100644
index 28563af..0000000
--- a/sysdeps/unix/sysv/linux/arm/truncate64.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <endian.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-truncate64 (const char *path, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (truncate64, 4, path, 0,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
-}
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
deleted file mode 100644
index 2579951..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
+++ /dev/null
@@ -1,31 +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 <unistd.h>
-
-/* Truncate PATH to LENGTH bytes.  */
-int
-__truncate (const char *path, off_t length)
-{
-  return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
-                         __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR (length >> 31, length));
-}
-weak_alias (__truncate, truncate)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
deleted file mode 100644
index f2927ea..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
+++ /dev/null
@@ -1,31 +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 <unistd.h>
-
-/* Truncate the file PATH to LENGTH bytes.  */
-int
-truncate64 (const char *path, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
-                         __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
-}
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
deleted file mode 100644
index 28563af..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <endian.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-truncate64 (const char *path, off64_t length)
-{
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (truncate64, 4, path, 0,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
-}
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
deleted file mode 100644
index 6e25b02..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
deleted file mode 100644
index ccfdafa..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Copyright (C) 1997-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 <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-/* Truncate the file referenced by FD to LENGTH bytes.  */
-int
-truncate64 (const char *path, off64_t length)
-{
-  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  int result = INLINE_SYSCALL (truncate64, 4, path, 0,
-			       (long) (length >> 32),
-			       (long) length);
-  return result;
-}
diff --git a/sysdeps/unix/sysv/linux/truncate.c b/sysdeps/unix/sysv/linux/truncate.c
new file mode 100644
index 0000000..9e71288
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/truncate.c
@@ -0,0 +1,35 @@
+/* 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 <sysdep.h>
+#include <errno.h>
+
+#ifndef __OFF_T_MATCHES_OFF64_T
+/* Truncate PATH to LENGTH bytes.  */
+int
+__truncate (const char *path, off_t length)
+{
+# ifndef __NR_truncate
+  return INLINE_SYSCALL_CALL (truncate64, path,
+			      __ALIGNMENT_ARG SYSCALL_LL (length));
+# else
+  return INLINE_SYSCALL_CALL (truncate, path, length);
+# endif
+}
+weak_alias (__truncate, truncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/truncate64.c b/sysdeps/unix/sysv/linux/truncate64.c
index 92a6bc4..0d70da7 100644
--- a/sysdeps/unix/sysv/linux/truncate64.c
+++ b/sysdeps/unix/sysv/linux/truncate64.c
@@ -15,21 +15,23 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sys/types.h>
-#include <endian.h>
-#include <errno.h>
 #include <unistd.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
+#include <errno.h>
 
-/* Truncate the file referenced by FD to LENGTH bytes.  */
+#ifndef __NR_truncate64
+# define __NR_truncate64 __NR_truncate
+#endif
+
+/* Truncate PATH to LENGTH bytes.  */
 int
-truncate64 (const char *path, off64_t length)
+__truncate64 (const char *path, off64_t length)
 {
-  unsigned int low = length & 0xffffffff;
-  unsigned int high = length >> 32;
-  int result = INLINE_SYSCALL (truncate64, 3, path,
-			       __LONG_LONG_PAIR (high, low));
-  return result;
+  return INLINE_SYSCALL_CALL (truncate64, path,
+			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
 }
+weak_alias (__truncate64, truncate64)
+
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__truncate64, truncate);
+#endif
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c
deleted file mode 100644
index 8999768..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* truncate64 is the same as truncate. */
-- 
2.7.4

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

* [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-20 15:02 [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation Adhemerval Zanella
@ 2016-09-20 15:02 ` Adhemerval Zanella
  2016-09-20 21:36   ` Florian Weimer
  2016-09-20 15:02 ` [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations Adhemerval Zanella
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-20 15:02 UTC (permalink / raw)
  To: libc-alpha

This patch adds two new macros for internal and inline syscall to use
within GLIBC: INTERNAL_SYSCALL_CALL and INLINE_SYSCALL_CALL.  They are
similar to the old INTERNAL_SYSCALL and INLINE_SYSCALL with the difference
the new macros accept a variable argument call and do not require to pass
the expected argument size.

The advantage is it is possible to use variable argument macros like
SYSCALL_LL{64} without the need to also handle the argument size.  So
for an ABI where SYSCALL_LL might split the argument in high and low
parts, instead of:

  INTERNAL_SYSCALL_DECL (err);
 #if ...
  INTERNAL_SYSCALL (syscall, err, 2, SYSCALL_LL (len));
 #else
  INTERNAL_SYSCALL (syscall, err, 1, SYSCALL_LL (len));
 #endif

It will be just:

  INTERNAL_SYSCALL_CALL (syscall, err, SYSCALL_LL (len));

The INLINE_SYSCALL_CALL follows the same semanthic regarding the argument
and is similar to INLINE_SYSCALL regarding setting errno.

No function currently uses these new macros, so no code change is expected.

	* sysdeps/unix/sysdep.h (__INTERNAL_SYSCALL0): New macro.
	(__INTERNAL_SYSCALL1): Likewise.
	(__INTERNAL_SYSCALL2): Likewise.
	(__INTERNAL_SYSCALL3): Likewise.
	(__INTERNAL_SYSCALL4): Likewise.
	(__INTERNAL_SYSCALL5): Likewise.
	(__INTERNAL_SYSCALL6): Likewise.
	(__INTERNAL_SYSCALL7): Likewise.
	(__INTERNAL_SYSCALL_NARGS_X): Likewise.
	(__INTERNAL_SYSCALL_NARGS): Likewise.
	(__INTERNAL_SYSCALL_CONCAT_X): Likewise.
	(__INTERNAL_SYSCALL_CONCAT): Likewise.
	(__INTERNAL_SYSCALL_DISP): Likewise.
	(INTERNAL_SYSCALL_CALL): Likewise.
	(__SYSCALL_CALL): Rename to INLINE_SYSCALL_CALL.
	(SYSCALL_CANCEL): Replace __SYSCALL_CALL with INLINE_SYSCALL_CALL.
---
 sysdeps/unix/sysdep.h | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 94a2ce0..50ac4d1 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -24,6 +24,38 @@
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
+#define __INTERNAL_SYSCALL0(name, err) \
+  INTERNAL_SYSCALL (name, err, 0)
+#define __INTERNAL_SYSCALL1(name, err, a1) \
+  INTERNAL_SYSCALL (name, err, 1, a1)
+#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
+  INTERNAL_SYSCALL (name, err, 2, a1, a2)
+#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
+  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
+#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
+  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
+#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
+  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
+#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
+  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
+#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
+  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
+
+#define __INTERNAL_SYSCALL_NARGS_X(a, b, c, d, e, f, g, h, n, ...) n
+#define __INTERNAL_SYSCALL_NARGS(...) \
+  __INTERNAL_SYSCALL_NARGS_X (__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
+#define __INTERNAL_SYSCALL_CONCAT_X(a, b) a##b
+#define __INTERNAL_SYSCALL_CONCAT(a, b)   __SYSCALL_CONCAT_X (a, b)
+#define __INTERNAL_SYSCALL_DISP(b,err,...) \
+  __INTERNAL_SYSCALL_CONCAT (b, __SYSCALL_NARGS (__VA_ARGS__)) \
+			    (err, __VA_ARGS__)
+
+/* Issue a syscall defined by syscall number plus any other argument required.
+   It is similar to INTERNAL_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INTERNAL_SYSCALL_CALL(nr, err, ...) \
+  __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL, nr, err, __VA_ARGS__)
+
 #define __SYSCALL0(name) \
   INLINE_SYSCALL (name, 0)
 #define __SYSCALL1(name, a1) \
@@ -49,17 +81,22 @@
 #define __SYSCALL_DISP(b,...) \
   __SYSCALL_CONCAT (b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
 
-#define __SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__)
+/* Issue a syscall defined by syscall number plus any other argument required.
+   Any error will be handled using arch defined macros and errno will be se
+   accordingly.
+   It is similar to INLINE_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INLINE_SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__)
 
 #define SYSCALL_CANCEL(...) \
   ({									     \
     long int sc_ret;							     \
     if (SINGLE_THREAD_P) 						     \
-      sc_ret = __SYSCALL_CALL (__VA_ARGS__);   				     \
+      sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); 			     \
     else								     \
       {									     \
 	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = __SYSCALL_CALL (__VA_ARGS__);				     \
+	sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);			     \
         LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
       }									     \
     sc_ret;								     \
-- 
2.7.4

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

* [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation
@ 2016-09-20 15:02 Adhemerval Zanella
  2016-09-20 15:02 ` [PATCH 1/4] Add INTERNAL_SYSCALL_CALL Adhemerval Zanella
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-20 15:02 UTC (permalink / raw)
  To: libc-alpha

Hi all,

This is my ongoing Linux syscall consolidation to avoid code duplication
and to try make new ports easier.  The patchset contains update version
of my previous patches for lseek [1], truncate [2], and ftruncate [3].

[1] https://sourceware.org/ml/libc-alpha/2016-08/msg00810.html
[2] https://sourceware.org/ml/libc-alpha/2016-08/msg00811.html 
[3] https://sourceware.org/ml/libc-alpha/2016-08/msg00812.html

Adhemerval Zanella (4):
  Add INTERNAL_SYSCALL_CALL
  Consolidate lseek/lseek64/llseek implementations
  Consolidate Linux ftruncate implementations
  Consolidate Linux truncate implementations

 nptl/Makefile                                      |   2 +-
 posix/tst-truncate-common.c                        |  88 ++++++++++++++++
 posix/tst-truncate.c                               | 114 +--------------------
 posix/tst-truncate64.c                             |  21 +++-
 sysdeps/unix/sysdep.h                              |  43 +++++++-
 sysdeps/unix/sysv/linux/Makefile                   |   2 +-
 sysdeps/unix/sysv/linux/alpha/Makefile             |   2 +-
 sysdeps/unix/sysv/linux/arm/ftruncate64.c          |  36 -------
 sysdeps/unix/sysv/linux/arm/truncate64.c           |  35 -------
 sysdeps/unix/sysv/linux/ftruncate.c                |  35 +++++++
 sysdeps/unix/sysv/linux/ftruncate64.c              |  21 ++--
 sysdeps/unix/sysv/linux/generic/sysdep.h           |   4 +-
 .../sysv/linux/generic/wordsize-32/ftruncate.c     |  31 ------
 .../sysv/linux/generic/wordsize-32/ftruncate64.c   |  32 ------
 .../unix/sysv/linux/generic/wordsize-32/llseek.c   |  46 ---------
 .../unix/sysv/linux/generic/wordsize-32/lseek.c    |  38 -------
 .../unix/sysv/linux/generic/wordsize-32/truncate.c |  31 ------
 .../sysv/linux/generic/wordsize-32/truncate64.c    |  31 ------
 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/mips32/ftruncate64.c  |  36 -------
 sysdeps/unix/sysv/linux/mips/mips32/truncate64.c   |  35 -------
 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c  |   1 -
 sysdeps/unix/sysv/linux/mips/mips64/llseek.c       |   1 -
 sysdeps/unix/sysv/linux/mips/mips64/syscalls.list  |   2 -
 sysdeps/unix/sysv/linux/mips/mips64/truncate64.c   |   1 -
 .../sysv/linux/powerpc/powerpc32/ftruncate64.c     |  36 -------
 .../unix/sysv/linux/powerpc/powerpc32/truncate64.c |  34 ------
 sysdeps/unix/sysv/linux/truncate.c                 |  35 +++++++
 sysdeps/unix/sysv/linux/truncate64.c               |  26 ++---
 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c  |   1 -
 sysdeps/unix/sysv/linux/wordsize-64/syscalls.list  |   3 -
 sysdeps/unix/sysv/linux/wordsize-64/truncate64.c   |   1 -
 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S       |   1 +
 35 files changed, 361 insertions(+), 620 deletions(-)
 create mode 100644 posix/tst-truncate-common.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/truncate64.c
 create mode 100644 sysdeps/unix/sysv/linux/ftruncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
 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/generic/wordsize-32/truncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.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/mips32/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/llseek.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
 create mode 100644 sysdeps/unix/sysv/linux/truncate.c
 delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
 delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/truncate64.c
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S

-- 
2.7.4

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-20 15:02 ` [PATCH 1/4] Add INTERNAL_SYSCALL_CALL Adhemerval Zanella
@ 2016-09-20 21:36   ` Florian Weimer
  2016-09-21 18:00     ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Florian Weimer @ 2016-09-20 21:36 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

* Adhemerval Zanella:

> +#define __INTERNAL_SYSCALL0(name, err) \
> +  INTERNAL_SYSCALL (name, err, 0)
> +#define __INTERNAL_SYSCALL1(name, err, a1) \
> +  INTERNAL_SYSCALL (name, err, 1, a1)
> +#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
> +  INTERNAL_SYSCALL (name, err, 2, a1, a2)
> +#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
> +  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
> +#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
> +  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
> +#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
> +  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
> +#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
> +  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
> +#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
> +  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)

It's not immediately obvious why these definitions are needed.

> +#define __INTERNAL_SYSCALL_NARGS_X(a, b, c, d, e, f, g, h, n, ...) n
> +#define __INTERNAL_SYSCALL_NARGS(...) \
> +  __INTERNAL_SYSCALL_NARGS_X (__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
> +#define __INTERNAL_SYSCALL_CONCAT_X(a, b) a##b
> +#define __INTERNAL_SYSCALL_CONCAT(a, b)   __SYSCALL_CONCAT_X (a, b)

I think you can reuse the macros from sysdeps/unix/sysdep.h here.

> +/* Issue a syscall defined by syscall number plus any other argument required.

These comment lines are rather long.

> +   Any error will be handled using arch defined macros and errno will be se
> +   accordingly.

“will be set”

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-20 21:36   ` Florian Weimer
@ 2016-09-21 18:00     ` Adhemerval Zanella
  2016-09-21 19:22       ` Florian Weimer
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-21 18:00 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha



On 20/09/2016 18:36, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> +#define __INTERNAL_SYSCALL0(name, err) \
>> +  INTERNAL_SYSCALL (name, err, 0)
>> +#define __INTERNAL_SYSCALL1(name, err, a1) \
>> +  INTERNAL_SYSCALL (name, err, 1, a1)
>> +#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
>> +  INTERNAL_SYSCALL (name, err, 2, a1, a2)
>> +#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
>> +  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
>> +#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
>> +  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
>> +#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
>> +  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
>> +#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
>> +  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
>> +#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
>> +  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
> 
> It's not immediately obvious why these definitions are needed.

I agree this is not obvious, but it follows the SYSCALL_CANCEL macro logic
where __INTERNAL_SYSCALL_DISP will select the correct __INTERNAL_SYSCALL
(based on number of arguments).

> 
>> +#define __INTERNAL_SYSCALL_NARGS_X(a, b, c, d, e, f, g, h, n, ...) n
>> +#define __INTERNAL_SYSCALL_NARGS(...) \
>> +  __INTERNAL_SYSCALL_NARGS_X (__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
>> +#define __INTERNAL_SYSCALL_CONCAT_X(a, b) a##b
>> +#define __INTERNAL_SYSCALL_CONCAT(a, b)   __SYSCALL_CONCAT_X (a, b)
> 
> I think you can reuse the macros from sysdeps/unix/sysdep.h here.

Indeed this is just a duplicate macro logic with different name.  I
think it is safe to remove.

> 
>> +/* Issue a syscall defined by syscall number plus any other argument required.
> 
> These comment lines are rather long.

Fixed.

> 
>> +   Any error will be handled using arch defined macros and errno will be se
>> +   accordingly.
> 
> “will be set”
> 

Fixed.

I think patch below simplify the macro code and address your comments:

--

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 94a2ce0..7816b6a 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -24,6 +24,40 @@
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
+/* Glue macros to select the correct {INTERNAL,INLINE}_SYSCALL variant based
+   on number of arguments used.  */
+#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
+#define __SYSCALL_NARGS(...) \
+  __SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
+#define __SYSCALL_CONCAT_X(a,b)     a##b
+#define __SYSCALL_CONCAT(a,b)       __SYSCALL_CONCAT_X (a, b)
+#define __SYSCALL_DISP(b,...) \
+  __SYSCALL_CONCAT (b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+
+
+#define __INTERNAL_SYSCALL0(name, err) \
+  INTERNAL_SYSCALL (name, err, 0)
+#define __INTERNAL_SYSCALL1(name, err, a1) \
+  INTERNAL_SYSCALL (name, err, 1, a1)
+#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
+  INTERNAL_SYSCALL (name, err, 2, a1, a2)
+#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
+  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
+#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
+  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
+#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
+  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
+#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
+  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
+#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
+  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
+
+/* Issue a syscall defined by syscall number plus any other argument required.
+   It is similar to INTERNAL_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INTERNAL_SYSCALL_CALL(nr, err, ...) \
+  __SYSCALL_DISP (__INTERNAL_SYSCALL, nr, err, __VA_ARGS__)
+
 #define __SYSCALL0(name) \
   INLINE_SYSCALL (name, 0)
 #define __SYSCALL1(name, a1) \
@@ -41,25 +75,22 @@
 #define __SYSCALL7(name, a1, a2, a3, a4, a5, a6, a7) \
   INLINE_SYSCALL (name, 7, a1, a2, a3, a4, a5, a6, a7)
 
-#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
-#define __SYSCALL_NARGS(...) \
-  __SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
-#define __SYSCALL_CONCAT_X(a,b)     a##b
-#define __SYSCALL_CONCAT(a,b)       __SYSCALL_CONCAT_X (a, b)
-#define __SYSCALL_DISP(b,...) \
-  __SYSCALL_CONCAT (b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
-
-#define __SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__)
+/* Issue a syscall defined by syscall number plus any other argument
+   required.  Any error will be handled using arch defined macros and errno
+   will be set accordingly.
+   It is similar to INLINE_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INLINE_SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__)
 
 #define SYSCALL_CANCEL(...) \
   ({									     \
     long int sc_ret;							     \
     if (SINGLE_THREAD_P) 						     \
-      sc_ret = __SYSCALL_CALL (__VA_ARGS__);   				     \
+      sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); 			     \
     else								     \
       {									     \
 	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = __SYSCALL_CALL (__VA_ARGS__);				     \
+	sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);			     \
         LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
       }									     \
     sc_ret;								     \

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-21 18:00     ` Adhemerval Zanella
@ 2016-09-21 19:22       ` Florian Weimer
  2016-09-22 13:43         ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Florian Weimer @ 2016-09-21 19:22 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

* Adhemerval Zanella:

> On 20/09/2016 18:36, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>> +#define __INTERNAL_SYSCALL0(name, err) \
>>> +  INTERNAL_SYSCALL (name, err, 0)
>>> +#define __INTERNAL_SYSCALL1(name, err, a1) \
>>> +  INTERNAL_SYSCALL (name, err, 1, a1)
>>> +#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
>>> +  INTERNAL_SYSCALL (name, err, 2, a1, a2)
>>> +#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
>>> +  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
>>> +#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
>>> +  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
>>> +#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
>>> +  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
>>> +#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
>>> +  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
>>> +#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
>>> +  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
>> 
>> It's not immediately obvious why these definitions are needed.
>
> I agree this is not obvious, but it follows the SYSCALL_CANCEL macro logic
> where __INTERNAL_SYSCALL_DISP will select the correct __INTERNAL_SYSCALL
> (based on number of arguments).

Is there anything that overrides inidivdual __INTERNAL_SYSCALLx
macros?

What I mean is this:  Why can't this

+#define __INTERNAL_SYSCALL_DISP(b,err,...) \
+  __INTERNAL_SYSCALL_CONCAT (b, __SYSCALL_NARGS (__VA_ARGS__)) \
+			    (err, __VA_ARGS__)

turn into

+#define __INTERNAL_SYSCALL_DISP(b,err,...) \
+  INTERNAL_SYSCALL (b, err, __SYSCALL_NARGS (__VA_ARGS__), __VA_ARGS__)

?

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-21 19:22       ` Florian Weimer
@ 2016-09-22 13:43         ` Adhemerval Zanella
  2016-09-22 20:34           ` Florian Weimer
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-22 13:43 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha



On 21/09/2016 16:22, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> On 20/09/2016 18:36, Florian Weimer wrote:
>>> * Adhemerval Zanella:
>>>
>>>> +#define __INTERNAL_SYSCALL0(name, err) \
>>>> +  INTERNAL_SYSCALL (name, err, 0)
>>>> +#define __INTERNAL_SYSCALL1(name, err, a1) \
>>>> +  INTERNAL_SYSCALL (name, err, 1, a1)
>>>> +#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
>>>> +  INTERNAL_SYSCALL (name, err, 2, a1, a2)
>>>> +#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
>>>> +  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
>>>> +#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
>>>> +  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
>>>> +#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
>>>> +  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
>>>> +#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
>>>> +  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
>>>> +#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
>>>> +  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
>>>
>>> It's not immediately obvious why these definitions are needed.
>>
>> I agree this is not obvious, but it follows the SYSCALL_CANCEL macro logic
>> where __INTERNAL_SYSCALL_DISP will select the correct __INTERNAL_SYSCALL
>> (based on number of arguments).
> 
> Is there anything that overrides inidivdual __INTERNAL_SYSCALLx
> macros?
> 
> What I mean is this:  Why can't this
> 
> +#define __INTERNAL_SYSCALL_DISP(b,err,...) \
> +  __INTERNAL_SYSCALL_CONCAT (b, __SYSCALL_NARGS (__VA_ARGS__)) \
> +			    (err, __VA_ARGS__)
> 
> turn into
> 
> +#define __INTERNAL_SYSCALL_DISP(b,err,...) \
> +  INTERNAL_SYSCALL (b, err, __SYSCALL_NARGS (__VA_ARGS__), __VA_ARGS__)
> 
> ?
> 

We can, at least for x86_64 for instance where it uses another indirection
for INTERNAL_SYSCALL.  However, something similar fails for i386, where
macro substitution for INTERNAL_SYSCALL will try string concatenation and
thus mess with intended behaviour.  Also, _SYSCALL_NARGS macro would be
required to be different to take in consideration the 'err' argument
required for INTERNAL syscall (something I noted I coded wrong).

I think calling the {INLINE,INTERNAL}_SYSCALL directly would be the safer 
and agnostic approach to avoid issues on how they are actually implemented 
by each port.

I tested the following patch with a build for practically all current
supported ports (aarch64, alpha, armeabi, armeaihf, hppa, ia64, i386, m68k,
microblaze, mips{32,64,n64}, nios2, powerpc{32,64,64le}, s390{-32,-64}, sh4,
sparc{64}, tile{pro,x64}, x86_64, and x32) and saw no build issues.  I also
checked on x86_64 and i386.  To actually check INTERNAL_SYSCALL_CALL macro
work I changed sysdeps/unix/sysv/linux/pthread_setaffinity.c to use it.

For below patch I changed it to the INLINE_SYSCALL macros would follow 
INLINE name and fixed the __INTERNAL_SYSCALL_NARGS argument selection
value.

--

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 94a2ce0..dfd3cfd 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -24,42 +24,79 @@
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
-#define __SYSCALL0(name) \
+#define __SYSCALL_CONCAT_X(a,b)     a##b
+#define __SYSCALL_CONCAT(a,b)       __SYSCALL_CONCAT_X (a, b)
+
+
+#define __INTERNAL_SYSCALL0(name, err) \
+  INTERNAL_SYSCALL (name, err, 0)
+#define __INTERNAL_SYSCALL1(name, err, a1) \
+  INTERNAL_SYSCALL (name, err, 1, a1)
+#define __INTERNAL_SYSCALL2(name, err, a1, a2) \
+  INTERNAL_SYSCALL (name, err, 2, a1, a2)
+#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \
+  INTERNAL_SYSCALL (name, err, 3, a1, a2, a3)
+#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \
+  INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4)
+#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \
+  INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5)
+#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \
+  INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6)
+#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \
+  INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
+
+#define __INTERNAL_SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
+#define __INTERNAL_SYSCALL_NARGS(...) \
+  __INTERNAL_SYSCALL_NARGS_X (__VA_ARGS__,6,5,4,3,2,1,0,)
+#define __INTERNAL_SYSCALL_DISP(b,...) \
+  __SYSCALL_CONCAT (b,__INTERNAL_SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+
+/* Issue a syscall defined by syscall number plus any other argument required.
+   It is similar to INTERNAL_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INTERNAL_SYSCALL_CALL(...) \
+  __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL, __VA_ARGS__)
+
+#define __INLINE_SYSCALL0(name) \
   INLINE_SYSCALL (name, 0)
-#define __SYSCALL1(name, a1) \
+#define __INLINE_SYSCALL1(name, a1) \
   INLINE_SYSCALL (name, 1, a1)
-#define __SYSCALL2(name, a1, a2) \
+#define __INLINE_SYSCALL2(name, a1, a2) \
   INLINE_SYSCALL (name, 2, a1, a2)
-#define __SYSCALL3(name, a1, a2, a3) \
+#define __INLINE_SYSCALL3(name, a1, a2, a3) \
   INLINE_SYSCALL (name, 3, a1, a2, a3)
-#define __SYSCALL4(name, a1, a2, a3, a4) \
+#define __INLINE_SYSCALL4(name, a1, a2, a3, a4) \
   INLINE_SYSCALL (name, 4, a1, a2, a3, a4)
-#define __SYSCALL5(name, a1, a2, a3, a4, a5) \
+#define __INLINE_SYSCALL5(name, a1, a2, a3, a4, a5) \
   INLINE_SYSCALL (name, 5, a1, a2, a3, a4, a5)
-#define __SYSCALL6(name, a1, a2, a3, a4, a5, a6) \
+#define __INLINE_SYSCALL6(name, a1, a2, a3, a4, a5, a6) \
   INLINE_SYSCALL (name, 6, a1, a2, a3, a4, a5, a6)
-#define __SYSCALL7(name, a1, a2, a3, a4, a5, a6, a7) \
+#define __INLINE_SYSCALL7(name, a1, a2, a3, a4, a5, a6, a7) \
   INLINE_SYSCALL (name, 7, a1, a2, a3, a4, a5, a6, a7)
 
-#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
-#define __SYSCALL_NARGS(...) \
-  __SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
-#define __SYSCALL_CONCAT_X(a,b)     a##b
-#define __SYSCALL_CONCAT(a,b)       __SYSCALL_CONCAT_X (a, b)
-#define __SYSCALL_DISP(b,...) \
-  __SYSCALL_CONCAT (b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+#define __INLINE_SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
+#define __INLINE_SYSCALL_NARGS(...) \
+  __INLINE_SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
+#define __INLINE_SYSCALL_DISP(b,...) \
+  __SYSCALL_CONCAT (b,__INLINE_SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
 
-#define __SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__)
+/* Issue a syscall defined by syscall number plus any other argument
+   required.  Any error will be handled using arch defined macros and errno
+   will be set accordingly.
+   It is similar to INLINE_SYSCALL macro, but without the need to pass the
+   expected argument number as second parameter.  */
+#define INLINE_SYSCALL_CALL(...) \
+  __INLINE_SYSCALL_DISP (__INLINE_SYSCALL, __VA_ARGS__)
 
 #define SYSCALL_CANCEL(...) \
   ({									     \
     long int sc_ret;							     \
     if (SINGLE_THREAD_P) 						     \
-      sc_ret = __SYSCALL_CALL (__VA_ARGS__);   				     \
+      sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); 			     \
     else								     \
       {									     \
 	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = __SYSCALL_CALL (__VA_ARGS__);				     \
+	sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);			     \
         LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
       }									     \
     sc_ret;	

  

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-20 15:02 ` [PATCH 4/4] Consolidate Linux truncate implementations Adhemerval Zanella
@ 2016-09-22 14:25   ` Yury Norov
  2016-09-22 14:42     ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Yury Norov @ 2016-09-22 14:25 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Tue, Sep 20, 2016 at 12:01:54PM -0300, Adhemerval Zanella wrote:
> diff --git a/sysdeps/unix/sysv/linux/truncate.c b/sysdeps/unix/sysv/linux/truncate.c
> new file mode 100644
> index 0000000..9e71288
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/truncate.c
> @@ -0,0 +1,35 @@
> +/* 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 <sysdep.h>
> +#include <errno.h>
> +
> +#ifndef __OFF_T_MATCHES_OFF64_T
> +/* Truncate PATH to LENGTH bytes.  */
> +int
> +__truncate (const char *path, off_t length)
> +{
> +# ifndef __NR_truncate
> +  return INLINE_SYSCALL_CALL (truncate64, path,
> +			      __ALIGNMENT_ARG SYSCALL_LL (length));
> +# else
> +  return INLINE_SYSCALL_CALL (truncate, path, length);
> +# endif
> +}
> +weak_alias (__truncate, truncate)
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/truncate64.c b/sysdeps/unix/sysv/linux/truncate64.c
> index 92a6bc4..0d70da7 100644
> --- a/sysdeps/unix/sysv/linux/truncate64.c
> +++ b/sysdeps/unix/sysv/linux/truncate64.c
> @@ -15,21 +15,23 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <sys/types.h>
> -#include <endian.h>
> -#include <errno.h>
>  #include <unistd.h>
> -
>  #include <sysdep.h>
> -#include <sys/syscall.h>
> +#include <errno.h>
>  
> -/* Truncate the file referenced by FD to LENGTH bytes.  */
> +#ifndef __NR_truncate64
> +# define __NR_truncate64 __NR_truncate
> +#endif
> +
> +/* Truncate PATH to LENGTH bytes.  */
>  int
> -truncate64 (const char *path, off64_t length)
> +__truncate64 (const char *path, off64_t length)
>  {
> -  unsigned int low = length & 0xffffffff;
> -  unsigned int high = length >> 32;
> -  int result = INLINE_SYSCALL (truncate64, 3, path,
> -			       __LONG_LONG_PAIR (high, low));
> -  return result;
> +  return INLINE_SYSCALL_CALL (truncate64, path,
> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>  }
> +weak_alias (__truncate64, truncate64)
> +
> +#ifdef __OFF_T_MATCHES_OFF64_T
> +weak_alias (__truncate64, truncate);
> +#endif

It seems you forgot weak_alias (__truncate64, __truncate);

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-22 14:25   ` Yury Norov
@ 2016-09-22 14:42     ` Adhemerval Zanella
  2016-09-22 15:52       ` Yury Norov
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-22 14:42 UTC (permalink / raw)
  To: libc-alpha



On 22/09/2016 11:24, Yury Norov wrote:
>> +/* Truncate PATH to LENGTH bytes.  */
>>  int
>> -truncate64 (const char *path, off64_t length)
>> +__truncate64 (const char *path, off64_t length)
>>  {
>> -  unsigned int low = length & 0xffffffff;
>> -  unsigned int high = length >> 32;
>> -  int result = INLINE_SYSCALL (truncate64, 3, path,
>> -			       __LONG_LONG_PAIR (high, low));
>> -  return result;
>> +  return INLINE_SYSCALL_CALL (truncate64, path,
>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>  }
>> +weak_alias (__truncate64, truncate64)
>> +
>> +#ifdef __OFF_T_MATCHES_OFF64_T
>> +weak_alias (__truncate64, truncate);
>> +#endif
> 
> It seems you forgot weak_alias (__truncate64, __truncate);
> 

I do not think it requires to add __truncate alias since glibc currently
does have internal calls to truncate.

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-22 14:42     ` Adhemerval Zanella
@ 2016-09-22 15:52       ` Yury Norov
  2016-09-22 19:05         ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Yury Norov @ 2016-09-22 15:52 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, Sep 22, 2016 at 11:42:11AM -0300, Adhemerval Zanella wrote:
> 
> 
> On 22/09/2016 11:24, Yury Norov wrote:
> >> +/* Truncate PATH to LENGTH bytes.  */
> >>  int
> >> -truncate64 (const char *path, off64_t length)
> >> +__truncate64 (const char *path, off64_t length)
> >>  {
> >> -  unsigned int low = length & 0xffffffff;
> >> -  unsigned int high = length >> 32;
> >> -  int result = INLINE_SYSCALL (truncate64, 3, path,
> >> -			       __LONG_LONG_PAIR (high, low));
> >> -  return result;
> >> +  return INLINE_SYSCALL_CALL (truncate64, path,
> >> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
> >>  }
> >> +weak_alias (__truncate64, truncate64)
> >> +
> >> +#ifdef __OFF_T_MATCHES_OFF64_T
> >> +weak_alias (__truncate64, truncate);
> >> +#endif
> > 
> > It seems you forgot weak_alias (__truncate64, __truncate);
> > 
> 
> I do not think it requires to add __truncate alias since glibc currently
> does have internal calls to truncate.

Sorry, I was meaning __ftruncate: 
/home/yury/work/toolchain/build-glibc-aarch64-thunderx-linux-gnu-mabi-ilp32/libc_pic.os:
In function `internal_fallocate':
/home/yury/work/toolchain/gits/glibc/io/../sysdeps/posix/posix_fallocate.c:64:
undefined reference to `__ftruncate'

Truncate looks correct.
The fix is like this to me:

--
diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
index 914ce67..4a00db5 100644
--- a/sysdeps/unix/sysv/linux/ftruncate64.c
+++ b/sysdeps/unix/sysv/linux/ftruncate64.c
@@ -33,5 +33,6 @@ __ftruncate64 (int fd, off64_t length)
 weak_alias (__ftruncate64, ftruncate64)

 #ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__ftruncate64, __ftruncate)
 weak_alias (__ftruncate64, ftruncate);
 #endif

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-22 15:52       ` Yury Norov
@ 2016-09-22 19:05         ` Adhemerval Zanella
  2016-10-25 17:55           ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-22 19:05 UTC (permalink / raw)
  To: Yury Norov; +Cc: libc-alpha



On 22/09/2016 12:51, Yury Norov wrote:
> On Thu, Sep 22, 2016 at 11:42:11AM -0300, Adhemerval Zanella wrote:
>>
>>
>> On 22/09/2016 11:24, Yury Norov wrote:
>>>> +/* Truncate PATH to LENGTH bytes.  */
>>>>  int
>>>> -truncate64 (const char *path, off64_t length)
>>>> +__truncate64 (const char *path, off64_t length)
>>>>  {
>>>> -  unsigned int low = length & 0xffffffff;
>>>> -  unsigned int high = length >> 32;
>>>> -  int result = INLINE_SYSCALL (truncate64, 3, path,
>>>> -			       __LONG_LONG_PAIR (high, low));
>>>> -  return result;
>>>> +  return INLINE_SYSCALL_CALL (truncate64, path,
>>>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>>>  }
>>>> +weak_alias (__truncate64, truncate64)
>>>> +
>>>> +#ifdef __OFF_T_MATCHES_OFF64_T
>>>> +weak_alias (__truncate64, truncate);
>>>> +#endif
>>>
>>> It seems you forgot weak_alias (__truncate64, __truncate);
>>>
>>
>> I do not think it requires to add __truncate alias since glibc currently
>> does have internal calls to truncate.
> 
> Sorry, I was meaning __ftruncate: 
> /home/yury/work/toolchain/build-glibc-aarch64-thunderx-linux-gnu-mabi-ilp32/libc_pic.os:
> In function `internal_fallocate':
> /home/yury/work/toolchain/gits/glibc/io/../sysdeps/posix/posix_fallocate.c:64:
> undefined reference to `__ftruncate'
> 
> Truncate looks correct.
> The fix is like this to me:
> 
> --
> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
> index 914ce67..4a00db5 100644
> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
> @@ -33,5 +33,6 @@ __ftruncate64 (int fd, off64_t length)
>  weak_alias (__ftruncate64, ftruncate64)
> 
>  #ifdef __OFF_T_MATCHES_OFF64_T
> +weak_alias (__ftruncate64, __ftruncate)
>  weak_alias (__ftruncate64, ftruncate);
>  #endif
> 

Ah right, the fallback posix_fallocate implementation. I will add this to
the patch, thanks.

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-22 13:43         ` Adhemerval Zanella
@ 2016-09-22 20:34           ` Florian Weimer
  2016-09-23 14:16             ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Florian Weimer @ 2016-09-22 20:34 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

* Adhemerval Zanella:

> We can, at least for x86_64 for instance where it uses another indirection
> for INTERNAL_SYSCALL.  However, something similar fails for i386, where
> macro substitution for INTERNAL_SYSCALL will try string concatenation and
> thus mess with intended behaviour.  Also, _SYSCALL_NARGS macro would be
> required to be different to take in consideration the 'err' argument
> required for INTERNAL syscall (something I noted I coded wrong).
>
> I think calling the {INLINE,INTERNAL}_SYSCALL directly would be the safer 
> and agnostic approach to avoid issues on how they are actually implemented 
> by each port.

Okay, it looks like this is the better way for now.

> I tested the following patch with a build for practically all current
> supported ports (aarch64, alpha, armeabi, armeaihf, hppa, ia64, i386, m68k,
> microblaze, mips{32,64,n64}, nios2, powerpc{32,64,64le}, s390{-32,-64}, sh4,
> sparc{64}, tile{pro,x64}, x86_64, and x32) and saw no build issues.  I also
> checked on x86_64 and i386.  To actually check INTERNAL_SYSCALL_CALL macro
> work I changed sysdeps/unix/sysv/linux/pthread_setaffinity.c to use it.

Did you see object code changes from that?

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-22 20:34           ` Florian Weimer
@ 2016-09-23 14:16             ` Adhemerval Zanella
  2016-09-23 20:39               ` Florian Weimer
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-09-23 14:16 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha



On 22/09/2016 17:34, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> We can, at least for x86_64 for instance where it uses another indirection
>> for INTERNAL_SYSCALL.  However, something similar fails for i386, where
>> macro substitution for INTERNAL_SYSCALL will try string concatenation and
>> thus mess with intended behaviour.  Also, _SYSCALL_NARGS macro would be
>> required to be different to take in consideration the 'err' argument
>> required for INTERNAL syscall (something I noted I coded wrong).
>>
>> I think calling the {INLINE,INTERNAL}_SYSCALL directly would be the safer 
>> and agnostic approach to avoid issues on how they are actually implemented 
>> by each port.
> 
> Okay, it looks like this is the better way for now.
> 
>> I tested the following patch with a build for practically all current
>> supported ports (aarch64, alpha, armeabi, armeaihf, hppa, ia64, i386, m68k,
>> microblaze, mips{32,64,n64}, nios2, powerpc{32,64,64le}, s390{-32,-64}, sh4,
>> sparc{64}, tile{pro,x64}, x86_64, and x32) and saw no build issues.  I also
>> checked on x86_64 and i386.  To actually check INTERNAL_SYSCALL_CALL macro
>> work I changed sysdeps/unix/sysv/linux/pthread_setaffinity.c to use it.
> 
> Did you see object code changes from that?

I haven't checked all of the, but at least x86_64, i386, aarch64, and powerpc64le
do not change.  I presume it is ok to push upstream, correct?

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

* Re: [PATCH 1/4] Add INTERNAL_SYSCALL_CALL
  2016-09-23 14:16             ` Adhemerval Zanella
@ 2016-09-23 20:39               ` Florian Weimer
  0 siblings, 0 replies; 27+ messages in thread
From: Florian Weimer @ 2016-09-23 20:39 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

* Adhemerval Zanella:

> On 22/09/2016 17:34, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>> We can, at least for x86_64 for instance where it uses another indirection
>>> for INTERNAL_SYSCALL.  However, something similar fails for i386, where
>>> macro substitution for INTERNAL_SYSCALL will try string concatenation and
>>> thus mess with intended behaviour.  Also, _SYSCALL_NARGS macro would be
>>> required to be different to take in consideration the 'err' argument
>>> required for INTERNAL syscall (something I noted I coded wrong).
>>>
>>> I think calling the {INLINE,INTERNAL}_SYSCALL directly would be the safer 
>>> and agnostic approach to avoid issues on how they are actually implemented 
>>> by each port.
>> 
>> Okay, it looks like this is the better way for now.
>> 
>>> I tested the following patch with a build for practically all current
>>> supported ports (aarch64, alpha, armeabi, armeaihf, hppa, ia64, i386, m68k,
>>> microblaze, mips{32,64,n64}, nios2, powerpc{32,64,64le}, s390{-32,-64}, sh4,
>>> sparc{64}, tile{pro,x64}, x86_64, and x32) and saw no build issues.  I also
>>> checked on x86_64 and i386.  To actually check INTERNAL_SYSCALL_CALL macro
>>> work I changed sysdeps/unix/sysv/linux/pthread_setaffinity.c to use it.
>> 
>> Did you see object code changes from that?
>
> I haven't checked all of the, but at least x86_64, i386, aarch64, and
> powerpc64le

Great, thanks.

> do not change.  I presume it is ok to push upstream, correct?

I can't really tell you that the patch is totally unproblematic, but
all my concerns have been addressed.  Please push.

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

* Re: [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations
  2016-09-20 15:02 ` [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations Adhemerval Zanella
@ 2016-10-11 14:40   ` Adhemerval Zanella
  2016-10-25 17:54     ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-10-11 14:40 UTC (permalink / raw)
  To: libc-alpha

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

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

* Re: [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-09-20 15:02 ` [PATCH 3/4] Consolidate Linux ftruncate implementations Adhemerval Zanella
@ 2016-10-11 14:41   ` Adhemerval Zanella
  2016-10-25 17:54     ` Adhemerval Zanella
  2016-11-09 15:33   ` Andreas Schwab
  1 sibling, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-10-11 14:41 UTC (permalink / raw)
  To: libc-alpha

Ping.

On 20/09/2016 12:01, Adhemerval Zanella wrote:
> THis patch consolidates all Linux ftruncate implementation on
> sysdeps/unix/sysv/linux/ftruncate{64}.c.  It is based on
> {INTERNAL,INLINE}_SYSCALL patch [1] to simplify the syscall construction.
> 
> General idea is to build ftruncate iff __OFF_T_MATCHES_OFF64_T is not
> defined, otherwise ftruncate64 will be build and ftruncate will be an
> alias.  The fallocate will use old compat syscall and pass 32-bit off_t
> argument, while fallocate64 will handle the correct off64_t passing using
> __ALIGNMENT_ARG and SYSCALL_LL64 macros.
> 
> Tested on x86_64, i386, aarch64, and armhf.
> 
> 	* posix/tst-truncate-common.c: New file.
> 	* posix/tst-truncate.c: Use tst-truncate-common.c.
> 	* posix/tst-truncate64.c: Likewise and add LFS tests.
> 	* sysdeps/unix/sysv/linux/arm/ftruncate64.c: Remove file.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c: Likewise.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c: Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c: Likewise.
> 	* sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c: Likewise.
> 	* sysdeps/unix/sysv/linux/ftruncate.c: New file.
> 	* sysdeps/unix/sysv/linux/ftruncate64.c (__ftruncate64): Use
> 	INLINE_SYSCALL_CALL, __ALIGNMENT_ARG and SYSCALL_LL64 macros.
> 	[__OFF_T_MATCHES_OFF64_T] (ftruncate): Add alias.
> 
> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
> ---
>  posix/tst-truncate-common.c                        |  88 ++++++++++++++++
>  posix/tst-truncate.c                               | 114 +--------------------
>  posix/tst-truncate64.c                             |  21 +++-
>  sysdeps/unix/sysv/linux/arm/ftruncate64.c          |  36 -------
>  sysdeps/unix/sysv/linux/ftruncate.c                |  35 +++++++
>  sysdeps/unix/sysv/linux/ftruncate64.c              |  21 ++--
>  .../sysv/linux/generic/wordsize-32/ftruncate.c     |  31 ------
>  .../sysv/linux/generic/wordsize-32/ftruncate64.c   |  32 ------
>  sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c  |  36 -------
>  sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c  |   1 -
>  .../sysv/linux/powerpc/powerpc32/ftruncate64.c     |  36 -------
>  sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c  |   1 -
>  12 files changed, 156 insertions(+), 296 deletions(-)
>  create mode 100644 posix/tst-truncate-common.c
>  delete mode 100644 sysdeps/unix/sysv/linux/arm/ftruncate64.c
>  create mode 100644 sysdeps/unix/sysv/linux/ftruncate.c
>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>  delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
> 
> diff --git a/posix/tst-truncate-common.c b/posix/tst-truncate-common.c
> new file mode 100644
> index 0000000..80bf277
> --- /dev/null
> +++ b/posix/tst-truncate-common.c
> @@ -0,0 +1,88 @@
> +/* Common f{truncate} tests definitions.
> +   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 <sys/types.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +
> +static void do_prepare (void);
> +#define PREPARE(argc, argv)     do_prepare ()
> +static int do_test (void);
> +#define TEST_FUNCTION           do_test ()
> +
> +#include <test-skeleton.c>
> +
> +static char *temp_filename;
> +static int temp_fd;
> +
> +static void
> +do_prepare (void)
> +{
> +  temp_fd = create_temp_file ("tst-trucate.", &temp_filename);
> +  if (temp_fd == -1)
> +    {
> +      printf ("cannot create temporary file: %m\n");
> +      exit (1);
> +    }
> +}
> +
> +#define FAIL(str) \
> +  do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0)
> +
> +static int
> +do_test_with_offset (off_t offset)
> +{
> +  struct stat st;
> +  char buf[1000];
> +
> +  memset (buf, 0xcf, sizeof (buf));
> +
> +  if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf))
> +    FAIL ("write failed");
> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf)))
> +    FAIL ("initial size wrong");
> +
> +  if (ftruncate (temp_fd, offset + 800) < 0)
> +    FAIL ("size reduction with ftruncate failed");
> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
> +    FAIL ("size after reduction with ftruncate is incorrect");
> +
> +  /* The following test covers more than POSIX.  POSIX does not require
> +     that ftruncate() can increase the file size.  But we are testing
> +     Unix systems.  */
> +  if (ftruncate (temp_fd, offset + 1200) < 0)
> +    FAIL ("size increate with ftruncate failed");
> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
> +    FAIL ("size after increase is incorrect");
> +
> +  if (truncate (temp_filename, offset + 800) < 0)
> +    FAIL ("size reduction with truncate failed");
> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
> +    FAIL ("size after reduction with truncate incorrect");
> +
> +  /* The following test covers more than POSIX.  POSIX does not require
> +     that truncate() can increase the file size.  But we are testing
> +     Unix systems.  */
> +  if (truncate (temp_filename, (offset + 1200)) < 0)
> +    FAIL ("size increase with truncate failed");
> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
> +    FAIL ("size increase with truncate is incorrect");
> +
> +  return 0;
> +}
> diff --git a/posix/tst-truncate.c b/posix/tst-truncate.c
> index 99bddb3..3166c3b 100644
> --- a/posix/tst-truncate.c
> +++ b/posix/tst-truncate.c
> @@ -17,116 +17,10 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <errno.h>
> -#include <error.h>
> -#include <string.h>
> -#include <unistd.h>
> -#include <sys/stat.h>
> +#include "tst-truncate-common.c"
>  
> -
> -/* Allow testing of the 64-bit versions as well.  */
> -#ifndef TRUNCATE
> -# define TRUNCATE truncate
> -# define FTRUNCATE ftruncate
> -#endif
> -
> -#define STRINGIFY(s) STRINGIFY2 (s)
> -#define STRINGIFY2(s) #s
> -
> -/* Prototype for our test function.  */
> -extern void do_prepare (int argc, char *argv[]);
> -extern int do_test (int argc, char *argv[]);
> -
> -/* We have a preparation function.  */
> -#define PREPARE do_prepare
> -
> -/* We might need a bit longer timeout.  */
> -#define TIMEOUT 20 /* sec */
> -
> -/* This defines the `main' function and some more.  */
> -#include <test-skeleton.c>
> -
> -/* These are for the temporary file we generate.  */
> -char *name;
> -int fd;
> -
> -void
> -do_prepare (int argc, char *argv[])
> +static int
> +do_test (void)
>  {
> -   size_t name_len;
> -
> -#define FNAME FNAME2(TRUNCATE)
> -#define FNAME2(s) "/" STRINGIFY(s) "XXXXXX"
> -
> -   name_len = strlen (test_dir);
> -   name = xmalloc (name_len + sizeof (FNAME));
> -   mempcpy (mempcpy (name, test_dir, name_len), FNAME, sizeof (FNAME));
> -   add_temp_file (name);
> -
> -   /* Open our test file.   */
> -   fd = mkstemp (name);
> -   if (fd == -1)
> -     error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
> -}
> -
> -
> -int
> -do_test (int argc, char *argv[])
> -{
> -  struct stat st;
> -  char buf[1000];
> -
> -  memset (buf, '\0', sizeof (buf));
> -
> -  if (write (fd, buf, sizeof (buf)) != sizeof (buf))
> -    error (EXIT_FAILURE, errno, "during write");
> -
> -  if (fstat (fd, &st) < 0 || st.st_size != sizeof (buf))
> -    error (EXIT_FAILURE, 0, "initial size wrong");
> -
> -
> -  if (FTRUNCATE (fd, 800) < 0)
> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
> -	   STRINGIFY (FTRUNCATE));
> -
> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
> -	   STRINGIFY (FTRUNCATE));
> -
> -  /* The following test covers more than POSIX.  POSIX does not require
> -     that ftruncate() can increase the file size.  But we are testing
> -     Unix systems.  */
> -  if (FTRUNCATE (fd, 1200) < 0)
> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
> -	   STRINGIFY (FTRUNCATE));
> -
> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
> -	   STRINGIFY (FTRUNCATE));
> -
> -
> -  if (TRUNCATE (name, 800) < 0)
> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
> -	   STRINGIFY (TRUNCATE));
> -
> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
> -	   STRINGIFY (TRUNCATE));
> -
> -  /* The following test covers more than POSIX.  POSIX does not require
> -     that truncate() can increase the file size.  But we are testing
> -     Unix systems.  */
> -  if (TRUNCATE (name, 1200) < 0)
> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
> -	   STRINGIFY (TRUNCATE));
> -
> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
> -	   STRINGIFY (TRUNCATE));
> -
> -
> -  close (fd);
> -  unlink (name);
> -
> -  return 0;
> +  return do_test_with_offset (0);
>  }
> diff --git a/posix/tst-truncate64.c b/posix/tst-truncate64.c
> index 64eb0a4..08c4942 100644
> --- a/posix/tst-truncate64.c
> +++ b/posix/tst-truncate64.c
> @@ -17,7 +17,22 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#define TRUNCATE truncate64
> -#define FTRUNCATE ftruncate64
> +#define _FILE_OFFSET_BITS 64
> +#include "tst-truncate-common.c"
>  
> -#include "tst-truncate.c"
> +static int
> +do_test (void)
> +{
> +  int ret;
> +
> +  ret = do_test_with_offset (0);
> +  if (ret == -1)
> +    return -1;
> +
> +  off_t base_offset = UINT32_MAX + 512LL;
> +  ret = do_test_with_offset (base_offset);
> +  if (ret == -1)
> +    return 1;
> +
> +  return 0;
> +}
> diff --git a/sysdeps/unix/sysv/linux/arm/ftruncate64.c b/sysdeps/unix/sysv/linux/arm/ftruncate64.c
> deleted file mode 100644
> index 0e8d8ba..0000000
> --- a/sysdeps/unix/sysv/linux/arm/ftruncate64.c
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -/* Copyright (C) 1997-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 <sys/types.h>
> -#include <errno.h>
> -#include <endian.h>
> -#include <unistd.h>
> -
> -#include <sysdep.h>
> -#include <sys/syscall.h>
> -
> -/* Truncate the file FD refers to to LENGTH bytes.  */
> -int
> -__ftruncate64 (int fd, off64_t length)
> -{
> -  unsigned int low = length & 0xffffffff;
> -  unsigned int high = length >> 32;
> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
> -			       __LONG_LONG_PAIR (high, low));
> -  return result;
> -}
> -weak_alias (__ftruncate64, ftruncate64)
> diff --git a/sysdeps/unix/sysv/linux/ftruncate.c b/sysdeps/unix/sysv/linux/ftruncate.c
> new file mode 100644
> index 0000000..5c0cd44
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/ftruncate.c
> @@ -0,0 +1,35 @@
> +/* 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 <sysdep.h>
> +#include <errno.h>
> +
> +#ifndef __OFF_T_MATCHES_OFF64_T
> +/* Truncate the file FD refers to LENGTH bytes.  */
> +int
> +__ftruncate (int fd, off_t length)
> +{
> +# ifndef __NR_ftruncate
> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
> +			      __ALIGNMENT_ARG SYSCALL_LL (length));
> +# else
> +  return INLINE_SYSCALL_CALL (ftruncate, fd, length);
> +# endif
> +}
> +weak_alias (__ftruncate, ftruncate)
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
> index a6bf878..914ce67 100644
> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
> @@ -15,22 +15,23 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <sys/types.h>
> -#include <errno.h>
> -#include <endian.h>
>  #include <unistd.h>
> -
>  #include <sysdep.h>
> -#include <sys/syscall.h>
> +#include <errno.h>
> +
> +#ifndef __NR_ftruncate64
> +# define __NR_ftruncate64 __NR_ftruncate
> +#endif
>  
>  /* Truncate the file referenced by FD to LENGTH bytes.  */
>  int
>  __ftruncate64 (int fd, off64_t length)
>  {
> -  unsigned int low = length & 0xffffffff;
> -  unsigned int high = length >> 32;
> -  int result = INLINE_SYSCALL (ftruncate64, 3, fd,
> -			       __LONG_LONG_PAIR (high, low));
> -  return result;
> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>  }
>  weak_alias (__ftruncate64, ftruncate64)
> +
> +#ifdef __OFF_T_MATCHES_OFF64_T
> +weak_alias (__ftruncate64, ftruncate);
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
> deleted file mode 100644
> index e1b500d..0000000
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
> +++ /dev/null
> @@ -1,31 +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 <unistd.h>
> -
> -/* Truncate the file FD refers to to LENGTH bytes.  */
> -int
> -__ftruncate (int fd, off_t length)
> -{
> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
> -                         __ALIGNMENT_ARG
> -                         __LONG_LONG_PAIR (length >> 31, length));
> -}
> -weak_alias (__ftruncate, ftruncate)
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
> deleted file mode 100644
> index 946f05a..0000000
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
> +++ /dev/null
> @@ -1,32 +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 <unistd.h>
> -
> -/* Truncate the file FD refers to to LENGTH bytes.  */
> -int
> -__ftruncate64 (int fd, off64_t length)
> -{
> -  unsigned int low = length & 0xffffffff;
> -  unsigned int high = length >> 32;
> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
> -                         __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
> -}
> -weak_alias (__ftruncate64, ftruncate64)
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
> deleted file mode 100644
> index 0e8d8ba..0000000
> --- a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -/* Copyright (C) 1997-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 <sys/types.h>
> -#include <errno.h>
> -#include <endian.h>
> -#include <unistd.h>
> -
> -#include <sysdep.h>
> -#include <sys/syscall.h>
> -
> -/* Truncate the file FD refers to to LENGTH bytes.  */
> -int
> -__ftruncate64 (int fd, off64_t length)
> -{
> -  unsigned int low = length & 0xffffffff;
> -  unsigned int high = length >> 32;
> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
> -			       __LONG_LONG_PAIR (high, low));
> -  return result;
> -}
> -weak_alias (__ftruncate64, ftruncate64)
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
> deleted file mode 100644
> index 6e25b02..0000000
> --- a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* Empty.  */
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
> deleted file mode 100644
> index 9eee1d7..0000000
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -/* Copyright (C) 1997-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 <sys/types.h>
> -#include <errno.h>
> -#include <unistd.h>
> -
> -#include <sysdep.h>
> -#include <sys/syscall.h>
> -
> -/* Truncate the file referenced by FD to LENGTH bytes.  */
> -int
> -__ftruncate64 (int fd, off64_t length)
> -{
> -  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
> -			       (long) (length >> 32),
> -			       (long) length);
> -
> -  return result;
> -}
> -weak_alias (__ftruncate64, ftruncate64)
> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
> deleted file mode 100644
> index 673a8b5..0000000
> --- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* ftruncate64 is the same as ftruncate. */
> 

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

* Re: [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations
  2016-10-11 14:40   ` Adhemerval Zanella
@ 2016-10-25 17:54     ` Adhemerval Zanella
  2016-11-04 16:23       ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-10-25 17:54 UTC (permalink / raw)
  To: libc-alpha

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

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

* Re: [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-10-11 14:41   ` Adhemerval Zanella
@ 2016-10-25 17:54     ` Adhemerval Zanella
  2016-11-09 13:44       ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-10-25 17:54 UTC (permalink / raw)
  To: libc-alpha

Ping (x2).

On 11/10/2016 11:41, Adhemerval Zanella wrote:
> Ping.
> 
> On 20/09/2016 12:01, Adhemerval Zanella wrote:
>> THis patch consolidates all Linux ftruncate implementation on
>> sysdeps/unix/sysv/linux/ftruncate{64}.c.  It is based on
>> {INTERNAL,INLINE}_SYSCALL patch [1] to simplify the syscall construction.
>>
>> General idea is to build ftruncate iff __OFF_T_MATCHES_OFF64_T is not
>> defined, otherwise ftruncate64 will be build and ftruncate will be an
>> alias.  The fallocate will use old compat syscall and pass 32-bit off_t
>> argument, while fallocate64 will handle the correct off64_t passing using
>> __ALIGNMENT_ARG and SYSCALL_LL64 macros.
>>
>> Tested on x86_64, i386, aarch64, and armhf.
>>
>> 	* posix/tst-truncate-common.c: New file.
>> 	* posix/tst-truncate.c: Use tst-truncate-common.c.
>> 	* posix/tst-truncate64.c: Likewise and add LFS tests.
>> 	* sysdeps/unix/sysv/linux/arm/ftruncate64.c: Remove file.
>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c: Likewise.
>> 	* sysdeps/unix/sysv/linux/ftruncate.c: New file.
>> 	* sysdeps/unix/sysv/linux/ftruncate64.c (__ftruncate64): Use
>> 	INLINE_SYSCALL_CALL, __ALIGNMENT_ARG and SYSCALL_LL64 macros.
>> 	[__OFF_T_MATCHES_OFF64_T] (ftruncate): Add alias.
>>
>> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
>> ---
>>  posix/tst-truncate-common.c                        |  88 ++++++++++++++++
>>  posix/tst-truncate.c                               | 114 +--------------------
>>  posix/tst-truncate64.c                             |  21 +++-
>>  sysdeps/unix/sysv/linux/arm/ftruncate64.c          |  36 -------
>>  sysdeps/unix/sysv/linux/ftruncate.c                |  35 +++++++
>>  sysdeps/unix/sysv/linux/ftruncate64.c              |  21 ++--
>>  .../sysv/linux/generic/wordsize-32/ftruncate.c     |  31 ------
>>  .../sysv/linux/generic/wordsize-32/ftruncate64.c   |  32 ------
>>  sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c  |  36 -------
>>  sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c  |   1 -
>>  .../sysv/linux/powerpc/powerpc32/ftruncate64.c     |  36 -------
>>  sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c  |   1 -
>>  12 files changed, 156 insertions(+), 296 deletions(-)
>>  create mode 100644 posix/tst-truncate-common.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/arm/ftruncate64.c
>>  create mode 100644 sysdeps/unix/sysv/linux/ftruncate.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>>  delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>>
>> diff --git a/posix/tst-truncate-common.c b/posix/tst-truncate-common.c
>> new file mode 100644
>> index 0000000..80bf277
>> --- /dev/null
>> +++ b/posix/tst-truncate-common.c
>> @@ -0,0 +1,88 @@
>> +/* Common f{truncate} tests definitions.
>> +   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 <sys/types.h>
>> +#include <sys/stat.h>
>> +#include <unistd.h>
>> +
>> +static void do_prepare (void);
>> +#define PREPARE(argc, argv)     do_prepare ()
>> +static int do_test (void);
>> +#define TEST_FUNCTION           do_test ()
>> +
>> +#include <test-skeleton.c>
>> +
>> +static char *temp_filename;
>> +static int temp_fd;
>> +
>> +static void
>> +do_prepare (void)
>> +{
>> +  temp_fd = create_temp_file ("tst-trucate.", &temp_filename);
>> +  if (temp_fd == -1)
>> +    {
>> +      printf ("cannot create temporary file: %m\n");
>> +      exit (1);
>> +    }
>> +}
>> +
>> +#define FAIL(str) \
>> +  do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0)
>> +
>> +static int
>> +do_test_with_offset (off_t offset)
>> +{
>> +  struct stat st;
>> +  char buf[1000];
>> +
>> +  memset (buf, 0xcf, sizeof (buf));
>> +
>> +  if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf))
>> +    FAIL ("write failed");
>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf)))
>> +    FAIL ("initial size wrong");
>> +
>> +  if (ftruncate (temp_fd, offset + 800) < 0)
>> +    FAIL ("size reduction with ftruncate failed");
>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
>> +    FAIL ("size after reduction with ftruncate is incorrect");
>> +
>> +  /* The following test covers more than POSIX.  POSIX does not require
>> +     that ftruncate() can increase the file size.  But we are testing
>> +     Unix systems.  */
>> +  if (ftruncate (temp_fd, offset + 1200) < 0)
>> +    FAIL ("size increate with ftruncate failed");
>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
>> +    FAIL ("size after increase is incorrect");
>> +
>> +  if (truncate (temp_filename, offset + 800) < 0)
>> +    FAIL ("size reduction with truncate failed");
>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
>> +    FAIL ("size after reduction with truncate incorrect");
>> +
>> +  /* The following test covers more than POSIX.  POSIX does not require
>> +     that truncate() can increase the file size.  But we are testing
>> +     Unix systems.  */
>> +  if (truncate (temp_filename, (offset + 1200)) < 0)
>> +    FAIL ("size increase with truncate failed");
>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
>> +    FAIL ("size increase with truncate is incorrect");
>> +
>> +  return 0;
>> +}
>> diff --git a/posix/tst-truncate.c b/posix/tst-truncate.c
>> index 99bddb3..3166c3b 100644
>> --- a/posix/tst-truncate.c
>> +++ b/posix/tst-truncate.c
>> @@ -17,116 +17,10 @@
>>     License along with the GNU C Library; if not, see
>>     <http://www.gnu.org/licenses/>.  */
>>  
>> -#include <errno.h>
>> -#include <error.h>
>> -#include <string.h>
>> -#include <unistd.h>
>> -#include <sys/stat.h>
>> +#include "tst-truncate-common.c"
>>  
>> -
>> -/* Allow testing of the 64-bit versions as well.  */
>> -#ifndef TRUNCATE
>> -# define TRUNCATE truncate
>> -# define FTRUNCATE ftruncate
>> -#endif
>> -
>> -#define STRINGIFY(s) STRINGIFY2 (s)
>> -#define STRINGIFY2(s) #s
>> -
>> -/* Prototype for our test function.  */
>> -extern void do_prepare (int argc, char *argv[]);
>> -extern int do_test (int argc, char *argv[]);
>> -
>> -/* We have a preparation function.  */
>> -#define PREPARE do_prepare
>> -
>> -/* We might need a bit longer timeout.  */
>> -#define TIMEOUT 20 /* sec */
>> -
>> -/* This defines the `main' function and some more.  */
>> -#include <test-skeleton.c>
>> -
>> -/* These are for the temporary file we generate.  */
>> -char *name;
>> -int fd;
>> -
>> -void
>> -do_prepare (int argc, char *argv[])
>> +static int
>> +do_test (void)
>>  {
>> -   size_t name_len;
>> -
>> -#define FNAME FNAME2(TRUNCATE)
>> -#define FNAME2(s) "/" STRINGIFY(s) "XXXXXX"
>> -
>> -   name_len = strlen (test_dir);
>> -   name = xmalloc (name_len + sizeof (FNAME));
>> -   mempcpy (mempcpy (name, test_dir, name_len), FNAME, sizeof (FNAME));
>> -   add_temp_file (name);
>> -
>> -   /* Open our test file.   */
>> -   fd = mkstemp (name);
>> -   if (fd == -1)
>> -     error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
>> -}
>> -
>> -
>> -int
>> -do_test (int argc, char *argv[])
>> -{
>> -  struct stat st;
>> -  char buf[1000];
>> -
>> -  memset (buf, '\0', sizeof (buf));
>> -
>> -  if (write (fd, buf, sizeof (buf)) != sizeof (buf))
>> -    error (EXIT_FAILURE, errno, "during write");
>> -
>> -  if (fstat (fd, &st) < 0 || st.st_size != sizeof (buf))
>> -    error (EXIT_FAILURE, 0, "initial size wrong");
>> -
>> -
>> -  if (FTRUNCATE (fd, 800) < 0)
>> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
>> -	   STRINGIFY (FTRUNCATE));
>> -
>> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
>> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
>> -	   STRINGIFY (FTRUNCATE));
>> -
>> -  /* The following test covers more than POSIX.  POSIX does not require
>> -     that ftruncate() can increase the file size.  But we are testing
>> -     Unix systems.  */
>> -  if (FTRUNCATE (fd, 1200) < 0)
>> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
>> -	   STRINGIFY (FTRUNCATE));
>> -
>> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
>> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
>> -	   STRINGIFY (FTRUNCATE));
>> -
>> -
>> -  if (TRUNCATE (name, 800) < 0)
>> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
>> -	   STRINGIFY (TRUNCATE));
>> -
>> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
>> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
>> -	   STRINGIFY (TRUNCATE));
>> -
>> -  /* The following test covers more than POSIX.  POSIX does not require
>> -     that truncate() can increase the file size.  But we are testing
>> -     Unix systems.  */
>> -  if (TRUNCATE (name, 1200) < 0)
>> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
>> -	   STRINGIFY (TRUNCATE));
>> -
>> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
>> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
>> -	   STRINGIFY (TRUNCATE));
>> -
>> -
>> -  close (fd);
>> -  unlink (name);
>> -
>> -  return 0;
>> +  return do_test_with_offset (0);
>>  }
>> diff --git a/posix/tst-truncate64.c b/posix/tst-truncate64.c
>> index 64eb0a4..08c4942 100644
>> --- a/posix/tst-truncate64.c
>> +++ b/posix/tst-truncate64.c
>> @@ -17,7 +17,22 @@
>>     License along with the GNU C Library; if not, see
>>     <http://www.gnu.org/licenses/>.  */
>>  
>> -#define TRUNCATE truncate64
>> -#define FTRUNCATE ftruncate64
>> +#define _FILE_OFFSET_BITS 64
>> +#include "tst-truncate-common.c"
>>  
>> -#include "tst-truncate.c"
>> +static int
>> +do_test (void)
>> +{
>> +  int ret;
>> +
>> +  ret = do_test_with_offset (0);
>> +  if (ret == -1)
>> +    return -1;
>> +
>> +  off_t base_offset = UINT32_MAX + 512LL;
>> +  ret = do_test_with_offset (base_offset);
>> +  if (ret == -1)
>> +    return 1;
>> +
>> +  return 0;
>> +}
>> diff --git a/sysdeps/unix/sysv/linux/arm/ftruncate64.c b/sysdeps/unix/sysv/linux/arm/ftruncate64.c
>> deleted file mode 100644
>> index 0e8d8ba..0000000
>> --- a/sysdeps/unix/sysv/linux/arm/ftruncate64.c
>> +++ /dev/null
>> @@ -1,36 +0,0 @@
>> -/* Copyright (C) 1997-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 <sys/types.h>
>> -#include <errno.h>
>> -#include <endian.h>
>> -#include <unistd.h>
>> -
>> -#include <sysdep.h>
>> -#include <sys/syscall.h>
>> -
>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>> -int
>> -__ftruncate64 (int fd, off64_t length)
>> -{
>> -  unsigned int low = length & 0xffffffff;
>> -  unsigned int high = length >> 32;
>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>> -			       __LONG_LONG_PAIR (high, low));
>> -  return result;
>> -}
>> -weak_alias (__ftruncate64, ftruncate64)
>> diff --git a/sysdeps/unix/sysv/linux/ftruncate.c b/sysdeps/unix/sysv/linux/ftruncate.c
>> new file mode 100644
>> index 0000000..5c0cd44
>> --- /dev/null
>> +++ b/sysdeps/unix/sysv/linux/ftruncate.c
>> @@ -0,0 +1,35 @@
>> +/* 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 <sysdep.h>
>> +#include <errno.h>
>> +
>> +#ifndef __OFF_T_MATCHES_OFF64_T
>> +/* Truncate the file FD refers to LENGTH bytes.  */
>> +int
>> +__ftruncate (int fd, off_t length)
>> +{
>> +# ifndef __NR_ftruncate
>> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
>> +			      __ALIGNMENT_ARG SYSCALL_LL (length));
>> +# else
>> +  return INLINE_SYSCALL_CALL (ftruncate, fd, length);
>> +# endif
>> +}
>> +weak_alias (__ftruncate, ftruncate)
>> +#endif
>> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
>> index a6bf878..914ce67 100644
>> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
>> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
>> @@ -15,22 +15,23 @@
>>     License along with the GNU C Library; if not, see
>>     <http://www.gnu.org/licenses/>.  */
>>  
>> -#include <sys/types.h>
>> -#include <errno.h>
>> -#include <endian.h>
>>  #include <unistd.h>
>> -
>>  #include <sysdep.h>
>> -#include <sys/syscall.h>
>> +#include <errno.h>
>> +
>> +#ifndef __NR_ftruncate64
>> +# define __NR_ftruncate64 __NR_ftruncate
>> +#endif
>>  
>>  /* Truncate the file referenced by FD to LENGTH bytes.  */
>>  int
>>  __ftruncate64 (int fd, off64_t length)
>>  {
>> -  unsigned int low = length & 0xffffffff;
>> -  unsigned int high = length >> 32;
>> -  int result = INLINE_SYSCALL (ftruncate64, 3, fd,
>> -			       __LONG_LONG_PAIR (high, low));
>> -  return result;
>> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>  }
>>  weak_alias (__ftruncate64, ftruncate64)
>> +
>> +#ifdef __OFF_T_MATCHES_OFF64_T
>> +weak_alias (__ftruncate64, ftruncate);
>> +#endif
>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>> deleted file mode 100644
>> index e1b500d..0000000
>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>> +++ /dev/null
>> @@ -1,31 +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 <unistd.h>
>> -
>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>> -int
>> -__ftruncate (int fd, off_t length)
>> -{
>> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
>> -                         __ALIGNMENT_ARG
>> -                         __LONG_LONG_PAIR (length >> 31, length));
>> -}
>> -weak_alias (__ftruncate, ftruncate)
>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>> deleted file mode 100644
>> index 946f05a..0000000
>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>> +++ /dev/null
>> @@ -1,32 +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 <unistd.h>
>> -
>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>> -int
>> -__ftruncate64 (int fd, off64_t length)
>> -{
>> -  unsigned int low = length & 0xffffffff;
>> -  unsigned int high = length >> 32;
>> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
>> -                         __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
>> -}
>> -weak_alias (__ftruncate64, ftruncate64)
>> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>> deleted file mode 100644
>> index 0e8d8ba..0000000
>> --- a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>> +++ /dev/null
>> @@ -1,36 +0,0 @@
>> -/* Copyright (C) 1997-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 <sys/types.h>
>> -#include <errno.h>
>> -#include <endian.h>
>> -#include <unistd.h>
>> -
>> -#include <sysdep.h>
>> -#include <sys/syscall.h>
>> -
>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>> -int
>> -__ftruncate64 (int fd, off64_t length)
>> -{
>> -  unsigned int low = length & 0xffffffff;
>> -  unsigned int high = length >> 32;
>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>> -			       __LONG_LONG_PAIR (high, low));
>> -  return result;
>> -}
>> -weak_alias (__ftruncate64, ftruncate64)
>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>> deleted file mode 100644
>> index 6e25b02..0000000
>> --- a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>> +++ /dev/null
>> @@ -1 +0,0 @@
>> -/* Empty.  */
>> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>> deleted file mode 100644
>> index 9eee1d7..0000000
>> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>> +++ /dev/null
>> @@ -1,36 +0,0 @@
>> -/* Copyright (C) 1997-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 <sys/types.h>
>> -#include <errno.h>
>> -#include <unistd.h>
>> -
>> -#include <sysdep.h>
>> -#include <sys/syscall.h>
>> -
>> -/* Truncate the file referenced by FD to LENGTH bytes.  */
>> -int
>> -__ftruncate64 (int fd, off64_t length)
>> -{
>> -  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>> -			       (long) (length >> 32),
>> -			       (long) length);
>> -
>> -  return result;
>> -}
>> -weak_alias (__ftruncate64, ftruncate64)
>> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>> deleted file mode 100644
>> index 673a8b5..0000000
>> --- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>> +++ /dev/null
>> @@ -1 +0,0 @@
>> -/* ftruncate64 is the same as ftruncate. */
>>

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-09-22 19:05         ` Adhemerval Zanella
@ 2016-10-25 17:55           ` Adhemerval Zanella
  2016-11-09 13:44             ` Adhemerval Zanella
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-10-25 17:55 UTC (permalink / raw)
  To: Yury Norov; +Cc: libc-alpha

Ping.

On 22/09/2016 16:04, Adhemerval Zanella wrote:
> 
> 
> On 22/09/2016 12:51, Yury Norov wrote:
>> On Thu, Sep 22, 2016 at 11:42:11AM -0300, Adhemerval Zanella wrote:
>>>
>>>
>>> On 22/09/2016 11:24, Yury Norov wrote:
>>>>> +/* Truncate PATH to LENGTH bytes.  */
>>>>>  int
>>>>> -truncate64 (const char *path, off64_t length)
>>>>> +__truncate64 (const char *path, off64_t length)
>>>>>  {
>>>>> -  unsigned int low = length & 0xffffffff;
>>>>> -  unsigned int high = length >> 32;
>>>>> -  int result = INLINE_SYSCALL (truncate64, 3, path,
>>>>> -			       __LONG_LONG_PAIR (high, low));
>>>>> -  return result;
>>>>> +  return INLINE_SYSCALL_CALL (truncate64, path,
>>>>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>>>>  }
>>>>> +weak_alias (__truncate64, truncate64)
>>>>> +
>>>>> +#ifdef __OFF_T_MATCHES_OFF64_T
>>>>> +weak_alias (__truncate64, truncate);
>>>>> +#endif
>>>>
>>>> It seems you forgot weak_alias (__truncate64, __truncate);
>>>>
>>>
>>> I do not think it requires to add __truncate alias since glibc currently
>>> does have internal calls to truncate.
>>
>> Sorry, I was meaning __ftruncate: 
>> /home/yury/work/toolchain/build-glibc-aarch64-thunderx-linux-gnu-mabi-ilp32/libc_pic.os:
>> In function `internal_fallocate':
>> /home/yury/work/toolchain/gits/glibc/io/../sysdeps/posix/posix_fallocate.c:64:
>> undefined reference to `__ftruncate'
>>
>> Truncate looks correct.
>> The fix is like this to me:
>>
>> --
>> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
>> index 914ce67..4a00db5 100644
>> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
>> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
>> @@ -33,5 +33,6 @@ __ftruncate64 (int fd, off64_t length)
>>  weak_alias (__ftruncate64, ftruncate64)
>>
>>  #ifdef __OFF_T_MATCHES_OFF64_T
>> +weak_alias (__ftruncate64, __ftruncate)
>>  weak_alias (__ftruncate64, ftruncate);
>>  #endif
>>
> 
> Ah right, the fallback posix_fallocate implementation. I will add this to
> the patch, thanks.
> 

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

* Re: [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations
  2016-10-25 17:54     ` Adhemerval Zanella
@ 2016-11-04 16:23       ` Adhemerval Zanella
  2016-11-08 19:02         ` Steve Ellcey
  0 siblings, 1 reply; 27+ messages in thread
From: Adhemerval Zanella @ 2016-11-04 16:23 UTC (permalink / raw)
  To: libc-alpha

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

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

* Re: [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations
  2016-11-04 16:23       ` Adhemerval Zanella
@ 2016-11-08 19:02         ` Steve Ellcey
  0 siblings, 0 replies; 27+ messages in thread
From: Steve Ellcey @ 2016-11-08 19:02 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

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

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

* Re: [PATCH 4/4] Consolidate Linux truncate implementations
  2016-10-25 17:55           ` Adhemerval Zanella
@ 2016-11-09 13:44             ` Adhemerval Zanella
  0 siblings, 0 replies; 27+ messages in thread
From: Adhemerval Zanella @ 2016-11-09 13:44 UTC (permalink / raw)
  To: Yury Norov; +Cc: libc-alpha

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:54, Adhemerval Zanella wrote:
> Ping.
> 
> On 22/09/2016 16:04, Adhemerval Zanella wrote:
>>
>>
>> On 22/09/2016 12:51, Yury Norov wrote:
>>> On Thu, Sep 22, 2016 at 11:42:11AM -0300, Adhemerval Zanella wrote:
>>>>
>>>>
>>>> On 22/09/2016 11:24, Yury Norov wrote:
>>>>>> +/* Truncate PATH to LENGTH bytes.  */
>>>>>>  int
>>>>>> -truncate64 (const char *path, off64_t length)
>>>>>> +__truncate64 (const char *path, off64_t length)
>>>>>>  {
>>>>>> -  unsigned int low = length & 0xffffffff;
>>>>>> -  unsigned int high = length >> 32;
>>>>>> -  int result = INLINE_SYSCALL (truncate64, 3, path,
>>>>>> -			       __LONG_LONG_PAIR (high, low));
>>>>>> -  return result;
>>>>>> +  return INLINE_SYSCALL_CALL (truncate64, path,
>>>>>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>>>>>  }
>>>>>> +weak_alias (__truncate64, truncate64)
>>>>>> +
>>>>>> +#ifdef __OFF_T_MATCHES_OFF64_T
>>>>>> +weak_alias (__truncate64, truncate);
>>>>>> +#endif
>>>>>
>>>>> It seems you forgot weak_alias (__truncate64, __truncate);
>>>>>
>>>>
>>>> I do not think it requires to add __truncate alias since glibc currently
>>>> does have internal calls to truncate.
>>>
>>> Sorry, I was meaning __ftruncate: 
>>> /home/yury/work/toolchain/build-glibc-aarch64-thunderx-linux-gnu-mabi-ilp32/libc_pic.os:
>>> In function `internal_fallocate':
>>> /home/yury/work/toolchain/gits/glibc/io/../sysdeps/posix/posix_fallocate.c:64:
>>> undefined reference to `__ftruncate'
>>>
>>> Truncate looks correct.
>>> The fix is like this to me:
>>>
>>> --
>>> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
>>> index 914ce67..4a00db5 100644
>>> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
>>> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
>>> @@ -33,5 +33,6 @@ __ftruncate64 (int fd, off64_t length)
>>>  weak_alias (__ftruncate64, ftruncate64)
>>>
>>>  #ifdef __OFF_T_MATCHES_OFF64_T
>>> +weak_alias (__ftruncate64, __ftruncate)
>>>  weak_alias (__ftruncate64, ftruncate);
>>>  #endif
>>>
>>
>> Ah right, the fallback posix_fallocate implementation. I will add this to
>> the patch, thanks.
>>

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

* Re: [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-10-25 17:54     ` Adhemerval Zanella
@ 2016-11-09 13:44       ` Adhemerval Zanella
  0 siblings, 0 replies; 27+ messages in thread
From: Adhemerval Zanella @ 2016-11-09 13:44 UTC (permalink / raw)
  To: libc-alpha

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:41, Adhemerval Zanella wrote:
>> Ping.
>>
>> On 20/09/2016 12:01, Adhemerval Zanella wrote:
>>> THis patch consolidates all Linux ftruncate implementation on
>>> sysdeps/unix/sysv/linux/ftruncate{64}.c.  It is based on
>>> {INTERNAL,INLINE}_SYSCALL patch [1] to simplify the syscall construction.
>>>
>>> General idea is to build ftruncate iff __OFF_T_MATCHES_OFF64_T is not
>>> defined, otherwise ftruncate64 will be build and ftruncate will be an
>>> alias.  The fallocate will use old compat syscall and pass 32-bit off_t
>>> argument, while fallocate64 will handle the correct off64_t passing using
>>> __ALIGNMENT_ARG and SYSCALL_LL64 macros.
>>>
>>> Tested on x86_64, i386, aarch64, and armhf.
>>>
>>> 	* posix/tst-truncate-common.c: New file.
>>> 	* posix/tst-truncate.c: Use tst-truncate-common.c.
>>> 	* posix/tst-truncate64.c: Likewise and add LFS tests.
>>> 	* sysdeps/unix/sysv/linux/arm/ftruncate64.c: Remove file.
>>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c: Likewise.
>>> 	* sysdeps/unix/sysv/linux/ftruncate.c: New file.
>>> 	* sysdeps/unix/sysv/linux/ftruncate64.c (__ftruncate64): Use
>>> 	INLINE_SYSCALL_CALL, __ALIGNMENT_ARG and SYSCALL_LL64 macros.
>>> 	[__OFF_T_MATCHES_OFF64_T] (ftruncate): Add alias.
>>>
>>> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
>>> ---
>>>  posix/tst-truncate-common.c                        |  88 ++++++++++++++++
>>>  posix/tst-truncate.c                               | 114 +--------------------
>>>  posix/tst-truncate64.c                             |  21 +++-
>>>  sysdeps/unix/sysv/linux/arm/ftruncate64.c          |  36 -------
>>>  sysdeps/unix/sysv/linux/ftruncate.c                |  35 +++++++
>>>  sysdeps/unix/sysv/linux/ftruncate64.c              |  21 ++--
>>>  .../sysv/linux/generic/wordsize-32/ftruncate.c     |  31 ------
>>>  .../sysv/linux/generic/wordsize-32/ftruncate64.c   |  32 ------
>>>  sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c  |  36 -------
>>>  sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c  |   1 -
>>>  .../sysv/linux/powerpc/powerpc32/ftruncate64.c     |  36 -------
>>>  sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c  |   1 -
>>>  12 files changed, 156 insertions(+), 296 deletions(-)
>>>  create mode 100644 posix/tst-truncate-common.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/arm/ftruncate64.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/ftruncate.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>>>  delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>>>
>>> diff --git a/posix/tst-truncate-common.c b/posix/tst-truncate-common.c
>>> new file mode 100644
>>> index 0000000..80bf277
>>> --- /dev/null
>>> +++ b/posix/tst-truncate-common.c
>>> @@ -0,0 +1,88 @@
>>> +/* Common f{truncate} tests definitions.
>>> +   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 <sys/types.h>
>>> +#include <sys/stat.h>
>>> +#include <unistd.h>
>>> +
>>> +static void do_prepare (void);
>>> +#define PREPARE(argc, argv)     do_prepare ()
>>> +static int do_test (void);
>>> +#define TEST_FUNCTION           do_test ()
>>> +
>>> +#include <test-skeleton.c>
>>> +
>>> +static char *temp_filename;
>>> +static int temp_fd;
>>> +
>>> +static void
>>> +do_prepare (void)
>>> +{
>>> +  temp_fd = create_temp_file ("tst-trucate.", &temp_filename);
>>> +  if (temp_fd == -1)
>>> +    {
>>> +      printf ("cannot create temporary file: %m\n");
>>> +      exit (1);
>>> +    }
>>> +}
>>> +
>>> +#define FAIL(str) \
>>> +  do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0)
>>> +
>>> +static int
>>> +do_test_with_offset (off_t offset)
>>> +{
>>> +  struct stat st;
>>> +  char buf[1000];
>>> +
>>> +  memset (buf, 0xcf, sizeof (buf));
>>> +
>>> +  if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf))
>>> +    FAIL ("write failed");
>>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf)))
>>> +    FAIL ("initial size wrong");
>>> +
>>> +  if (ftruncate (temp_fd, offset + 800) < 0)
>>> +    FAIL ("size reduction with ftruncate failed");
>>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
>>> +    FAIL ("size after reduction with ftruncate is incorrect");
>>> +
>>> +  /* The following test covers more than POSIX.  POSIX does not require
>>> +     that ftruncate() can increase the file size.  But we are testing
>>> +     Unix systems.  */
>>> +  if (ftruncate (temp_fd, offset + 1200) < 0)
>>> +    FAIL ("size increate with ftruncate failed");
>>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
>>> +    FAIL ("size after increase is incorrect");
>>> +
>>> +  if (truncate (temp_filename, offset + 800) < 0)
>>> +    FAIL ("size reduction with truncate failed");
>>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800))
>>> +    FAIL ("size after reduction with truncate incorrect");
>>> +
>>> +  /* The following test covers more than POSIX.  POSIX does not require
>>> +     that truncate() can increase the file size.  But we are testing
>>> +     Unix systems.  */
>>> +  if (truncate (temp_filename, (offset + 1200)) < 0)
>>> +    FAIL ("size increase with truncate failed");
>>> +  if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200))
>>> +    FAIL ("size increase with truncate is incorrect");
>>> +
>>> +  return 0;
>>> +}
>>> diff --git a/posix/tst-truncate.c b/posix/tst-truncate.c
>>> index 99bddb3..3166c3b 100644
>>> --- a/posix/tst-truncate.c
>>> +++ b/posix/tst-truncate.c
>>> @@ -17,116 +17,10 @@
>>>     License along with the GNU C Library; if not, see
>>>     <http://www.gnu.org/licenses/>.  */
>>>  
>>> -#include <errno.h>
>>> -#include <error.h>
>>> -#include <string.h>
>>> -#include <unistd.h>
>>> -#include <sys/stat.h>
>>> +#include "tst-truncate-common.c"
>>>  
>>> -
>>> -/* Allow testing of the 64-bit versions as well.  */
>>> -#ifndef TRUNCATE
>>> -# define TRUNCATE truncate
>>> -# define FTRUNCATE ftruncate
>>> -#endif
>>> -
>>> -#define STRINGIFY(s) STRINGIFY2 (s)
>>> -#define STRINGIFY2(s) #s
>>> -
>>> -/* Prototype for our test function.  */
>>> -extern void do_prepare (int argc, char *argv[]);
>>> -extern int do_test (int argc, char *argv[]);
>>> -
>>> -/* We have a preparation function.  */
>>> -#define PREPARE do_prepare
>>> -
>>> -/* We might need a bit longer timeout.  */
>>> -#define TIMEOUT 20 /* sec */
>>> -
>>> -/* This defines the `main' function and some more.  */
>>> -#include <test-skeleton.c>
>>> -
>>> -/* These are for the temporary file we generate.  */
>>> -char *name;
>>> -int fd;
>>> -
>>> -void
>>> -do_prepare (int argc, char *argv[])
>>> +static int
>>> +do_test (void)
>>>  {
>>> -   size_t name_len;
>>> -
>>> -#define FNAME FNAME2(TRUNCATE)
>>> -#define FNAME2(s) "/" STRINGIFY(s) "XXXXXX"
>>> -
>>> -   name_len = strlen (test_dir);
>>> -   name = xmalloc (name_len + sizeof (FNAME));
>>> -   mempcpy (mempcpy (name, test_dir, name_len), FNAME, sizeof (FNAME));
>>> -   add_temp_file (name);
>>> -
>>> -   /* Open our test file.   */
>>> -   fd = mkstemp (name);
>>> -   if (fd == -1)
>>> -     error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
>>> -}
>>> -
>>> -
>>> -int
>>> -do_test (int argc, char *argv[])
>>> -{
>>> -  struct stat st;
>>> -  char buf[1000];
>>> -
>>> -  memset (buf, '\0', sizeof (buf));
>>> -
>>> -  if (write (fd, buf, sizeof (buf)) != sizeof (buf))
>>> -    error (EXIT_FAILURE, errno, "during write");
>>> -
>>> -  if (fstat (fd, &st) < 0 || st.st_size != sizeof (buf))
>>> -    error (EXIT_FAILURE, 0, "initial size wrong");
>>> -
>>> -
>>> -  if (FTRUNCATE (fd, 800) < 0)
>>> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
>>> -	   STRINGIFY (FTRUNCATE));
>>> -
>>> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
>>> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
>>> -	   STRINGIFY (FTRUNCATE));
>>> -
>>> -  /* The following test covers more than POSIX.  POSIX does not require
>>> -     that ftruncate() can increase the file size.  But we are testing
>>> -     Unix systems.  */
>>> -  if (FTRUNCATE (fd, 1200) < 0)
>>> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
>>> -	   STRINGIFY (FTRUNCATE));
>>> -
>>> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
>>> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
>>> -	   STRINGIFY (FTRUNCATE));
>>> -
>>> -
>>> -  if (TRUNCATE (name, 800) < 0)
>>> -    error (EXIT_FAILURE, errno, "size reduction with %s failed",
>>> -	   STRINGIFY (TRUNCATE));
>>> -
>>> -  if (fstat (fd, &st) < 0 || st.st_size != 800)
>>> -    error (EXIT_FAILURE, 0, "size after reduction with %s incorrect",
>>> -	   STRINGIFY (TRUNCATE));
>>> -
>>> -  /* The following test covers more than POSIX.  POSIX does not require
>>> -     that truncate() can increase the file size.  But we are testing
>>> -     Unix systems.  */
>>> -  if (TRUNCATE (name, 1200) < 0)
>>> -    error (EXIT_FAILURE, errno, "size increase with %s failed",
>>> -	   STRINGIFY (TRUNCATE));
>>> -
>>> -  if (fstat (fd, &st) < 0 || st.st_size != 1200)
>>> -    error (EXIT_FAILURE, 0, "size after increase with %s incorrect",
>>> -	   STRINGIFY (TRUNCATE));
>>> -
>>> -
>>> -  close (fd);
>>> -  unlink (name);
>>> -
>>> -  return 0;
>>> +  return do_test_with_offset (0);
>>>  }
>>> diff --git a/posix/tst-truncate64.c b/posix/tst-truncate64.c
>>> index 64eb0a4..08c4942 100644
>>> --- a/posix/tst-truncate64.c
>>> +++ b/posix/tst-truncate64.c
>>> @@ -17,7 +17,22 @@
>>>     License along with the GNU C Library; if not, see
>>>     <http://www.gnu.org/licenses/>.  */
>>>  
>>> -#define TRUNCATE truncate64
>>> -#define FTRUNCATE ftruncate64
>>> +#define _FILE_OFFSET_BITS 64
>>> +#include "tst-truncate-common.c"
>>>  
>>> -#include "tst-truncate.c"
>>> +static int
>>> +do_test (void)
>>> +{
>>> +  int ret;
>>> +
>>> +  ret = do_test_with_offset (0);
>>> +  if (ret == -1)
>>> +    return -1;
>>> +
>>> +  off_t base_offset = UINT32_MAX + 512LL;
>>> +  ret = do_test_with_offset (base_offset);
>>> +  if (ret == -1)
>>> +    return 1;
>>> +
>>> +  return 0;
>>> +}
>>> diff --git a/sysdeps/unix/sysv/linux/arm/ftruncate64.c b/sysdeps/unix/sysv/linux/arm/ftruncate64.c
>>> deleted file mode 100644
>>> index 0e8d8ba..0000000
>>> --- a/sysdeps/unix/sysv/linux/arm/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1,36 +0,0 @@
>>> -/* Copyright (C) 1997-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 <sys/types.h>
>>> -#include <errno.h>
>>> -#include <endian.h>
>>> -#include <unistd.h>
>>> -
>>> -#include <sysdep.h>
>>> -#include <sys/syscall.h>
>>> -
>>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>>> -int
>>> -__ftruncate64 (int fd, off64_t length)
>>> -{
>>> -  unsigned int low = length & 0xffffffff;
>>> -  unsigned int high = length >> 32;
>>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>>> -			       __LONG_LONG_PAIR (high, low));
>>> -  return result;
>>> -}
>>> -weak_alias (__ftruncate64, ftruncate64)
>>> diff --git a/sysdeps/unix/sysv/linux/ftruncate.c b/sysdeps/unix/sysv/linux/ftruncate.c
>>> new file mode 100644
>>> index 0000000..5c0cd44
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/ftruncate.c
>>> @@ -0,0 +1,35 @@
>>> +/* 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 <sysdep.h>
>>> +#include <errno.h>
>>> +
>>> +#ifndef __OFF_T_MATCHES_OFF64_T
>>> +/* Truncate the file FD refers to LENGTH bytes.  */
>>> +int
>>> +__ftruncate (int fd, off_t length)
>>> +{
>>> +# ifndef __NR_ftruncate
>>> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
>>> +			      __ALIGNMENT_ARG SYSCALL_LL (length));
>>> +# else
>>> +  return INLINE_SYSCALL_CALL (ftruncate, fd, length);
>>> +# endif
>>> +}
>>> +weak_alias (__ftruncate, ftruncate)
>>> +#endif
>>> diff --git a/sysdeps/unix/sysv/linux/ftruncate64.c b/sysdeps/unix/sysv/linux/ftruncate64.c
>>> index a6bf878..914ce67 100644
>>> --- a/sysdeps/unix/sysv/linux/ftruncate64.c
>>> +++ b/sysdeps/unix/sysv/linux/ftruncate64.c
>>> @@ -15,22 +15,23 @@
>>>     License along with the GNU C Library; if not, see
>>>     <http://www.gnu.org/licenses/>.  */
>>>  
>>> -#include <sys/types.h>
>>> -#include <errno.h>
>>> -#include <endian.h>
>>>  #include <unistd.h>
>>> -
>>>  #include <sysdep.h>
>>> -#include <sys/syscall.h>
>>> +#include <errno.h>
>>> +
>>> +#ifndef __NR_ftruncate64
>>> +# define __NR_ftruncate64 __NR_ftruncate
>>> +#endif
>>>  
>>>  /* Truncate the file referenced by FD to LENGTH bytes.  */
>>>  int
>>>  __ftruncate64 (int fd, off64_t length)
>>>  {
>>> -  unsigned int low = length & 0xffffffff;
>>> -  unsigned int high = length >> 32;
>>> -  int result = INLINE_SYSCALL (ftruncate64, 3, fd,
>>> -			       __LONG_LONG_PAIR (high, low));
>>> -  return result;
>>> +  return INLINE_SYSCALL_CALL (ftruncate64, fd,
>>> +			      __ALIGNMENT_ARG SYSCALL_LL64 (length));
>>>  }
>>>  weak_alias (__ftruncate64, ftruncate64)
>>> +
>>> +#ifdef __OFF_T_MATCHES_OFF64_T
>>> +weak_alias (__ftruncate64, ftruncate);
>>> +#endif
>>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>>> deleted file mode 100644
>>> index e1b500d..0000000
>>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
>>> +++ /dev/null
>>> @@ -1,31 +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 <unistd.h>
>>> -
>>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>>> -int
>>> -__ftruncate (int fd, off_t length)
>>> -{
>>> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
>>> -                         __ALIGNMENT_ARG
>>> -                         __LONG_LONG_PAIR (length >> 31, length));
>>> -}
>>> -weak_alias (__ftruncate, ftruncate)
>>> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>>> deleted file mode 100644
>>> index 946f05a..0000000
>>> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1,32 +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 <unistd.h>
>>> -
>>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>>> -int
>>> -__ftruncate64 (int fd, off64_t length)
>>> -{
>>> -  unsigned int low = length & 0xffffffff;
>>> -  unsigned int high = length >> 32;
>>> -  return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
>>> -                         __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
>>> -}
>>> -weak_alias (__ftruncate64, ftruncate64)
>>> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>>> deleted file mode 100644
>>> index 0e8d8ba..0000000
>>> --- a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1,36 +0,0 @@
>>> -/* Copyright (C) 1997-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 <sys/types.h>
>>> -#include <errno.h>
>>> -#include <endian.h>
>>> -#include <unistd.h>
>>> -
>>> -#include <sysdep.h>
>>> -#include <sys/syscall.h>
>>> -
>>> -/* Truncate the file FD refers to to LENGTH bytes.  */
>>> -int
>>> -__ftruncate64 (int fd, off64_t length)
>>> -{
>>> -  unsigned int low = length & 0xffffffff;
>>> -  unsigned int high = length >> 32;
>>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>>> -			       __LONG_LONG_PAIR (high, low));
>>> -  return result;
>>> -}
>>> -weak_alias (__ftruncate64, ftruncate64)
>>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>>> deleted file mode 100644
>>> index 6e25b02..0000000
>>> --- a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1 +0,0 @@
>>> -/* Empty.  */
>>> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>>> deleted file mode 100644
>>> index 9eee1d7..0000000
>>> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1,36 +0,0 @@
>>> -/* Copyright (C) 1997-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 <sys/types.h>
>>> -#include <errno.h>
>>> -#include <unistd.h>
>>> -
>>> -#include <sysdep.h>
>>> -#include <sys/syscall.h>
>>> -
>>> -/* Truncate the file referenced by FD to LENGTH bytes.  */
>>> -int
>>> -__ftruncate64 (int fd, off64_t length)
>>> -{
>>> -  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
>>> -  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
>>> -			       (long) (length >> 32),
>>> -			       (long) length);
>>> -
>>> -  return result;
>>> -}
>>> -weak_alias (__ftruncate64, ftruncate64)
>>> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>>> deleted file mode 100644
>>> index 673a8b5..0000000
>>> --- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>>> +++ /dev/null
>>> @@ -1 +0,0 @@
>>> -/* ftruncate64 is the same as ftruncate. */
>>>

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

* Re: [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-09-20 15:02 ` [PATCH 3/4] Consolidate Linux ftruncate implementations Adhemerval Zanella
  2016-10-11 14:41   ` Adhemerval Zanella
@ 2016-11-09 15:33   ` Andreas Schwab
  2016-11-09 17:24     ` Adhemerval Zanella
  1 sibling, 1 reply; 27+ messages in thread
From: Andreas Schwab @ 2016-11-09 15:33 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Sep 20 2016, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
> deleted file mode 100644
> index 673a8b5..0000000
> --- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* ftruncate64 is the same as ftruncate. */

There are now two objects providing ftruncate/ftruncate64 on 64-bit archs,
one from .../linux/ftruncate64.c, the other from
.../linux/wordsize-64/syscalls.list:ftruncate.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH 3/4] Consolidate Linux ftruncate implementations
  2016-11-09 15:33   ` Andreas Schwab
@ 2016-11-09 17:24     ` Adhemerval Zanella
  0 siblings, 0 replies; 27+ messages in thread
From: Adhemerval Zanella @ 2016-11-09 17:24 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha



On 09/11/2016 13:33, Andreas Schwab wrote:
> On Sep 20 2016, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> 
>> diff --git a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>> deleted file mode 100644
>> index 673a8b5..0000000
>> --- a/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
>> +++ /dev/null
>> @@ -1 +0,0 @@
>> -/* ftruncate64 is the same as ftruncate. */
> 
> There are now two objects providing ftruncate/ftruncate64 on 64-bit archs,
> one from .../linux/ftruncate64.c, the other from
> .../linux/wordsize-64/syscalls.list:ftruncate.
> 
> Andreas.

The C file take precedence over syscalls.list, I will remove it from
auto-generation.

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

end of thread, other threads:[~2016-11-09 17:24 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-20 15:02 [PATCH 0/4] Linux lseek and {f}truncate syscall consolidation Adhemerval Zanella
2016-09-20 15:02 ` [PATCH 1/4] Add INTERNAL_SYSCALL_CALL Adhemerval Zanella
2016-09-20 21:36   ` Florian Weimer
2016-09-21 18:00     ` Adhemerval Zanella
2016-09-21 19:22       ` Florian Weimer
2016-09-22 13:43         ` Adhemerval Zanella
2016-09-22 20:34           ` Florian Weimer
2016-09-23 14:16             ` Adhemerval Zanella
2016-09-23 20:39               ` Florian Weimer
2016-09-20 15:02 ` [PATCH v3 2/4] Consolidate lseek/lseek64/llseek implementations Adhemerval Zanella
2016-10-11 14:40   ` Adhemerval Zanella
2016-10-25 17:54     ` Adhemerval Zanella
2016-11-04 16:23       ` Adhemerval Zanella
2016-11-08 19:02         ` Steve Ellcey
2016-09-20 15:02 ` [PATCH 4/4] Consolidate Linux truncate implementations Adhemerval Zanella
2016-09-22 14:25   ` Yury Norov
2016-09-22 14:42     ` Adhemerval Zanella
2016-09-22 15:52       ` Yury Norov
2016-09-22 19:05         ` Adhemerval Zanella
2016-10-25 17:55           ` Adhemerval Zanella
2016-11-09 13:44             ` Adhemerval Zanella
2016-09-20 15:02 ` [PATCH 3/4] Consolidate Linux ftruncate implementations Adhemerval Zanella
2016-10-11 14:41   ` Adhemerval Zanella
2016-10-25 17:54     ` Adhemerval Zanella
2016-11-09 13:44       ` Adhemerval Zanella
2016-11-09 15:33   ` Andreas Schwab
2016-11-09 17:24     ` 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).