generic/wordsize-32: don't duplicate truncate syscalls if not needed
diff mbox

Message ID 1474318609-18149-1-git-send-email-ynorov@caviumnetworks.com
State New
Headers show

Commit Message

Yury Norov Sept. 19, 2016, 8:56 p.m. UTC
If off_t is 64-bit, current implementation of truncate() and ftruncate()
is wrong, and proper implementation is identical to corresponding 64-bit
versions of syscalls. This patch creates aliases for it.

2016-09-19: Yury Norov  <ynorov@caviumnetworks.com>

	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c:
	  don't declare ftruncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c:
	  declare ftruncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
	  don't declare truncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
	  declare truncate() and symbols if off_t is 64-bit.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c   | 2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c | 9 +++++++++
 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c    | 2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c  | 9 +++++++++
 4 files changed, 22 insertions(+)

Comments

Adhemerval Zanella Sept. 20, 2016, 1:04 p.m. UTC | #1
On 19/09/2016 17:56, Yury Norov wrote:
> If off_t is 64-bit, current implementation of truncate() and ftruncate()
> is wrong, and proper implementation is identical to corresponding 64-bit
> versions of syscalls. This patch creates aliases for it.

I think we can try to go forward and consolidate both all truncate and
ftruncate implementation on Linux.  I sent a patchset last month [1] [2]
and I will send an update today with some small fixes.  I think it should
work on aarch64 ilp32 as well, it uses the logic for:

{f}truncate.c:

#ifndef __OFF_T_MATCHES_OFF64_T
__{f}truncate (..., off_t length)
{
# ifndef __NR_ftruncate
  return INLINE_SYSCALL_CALL (ftruncate64, ...,
                             __ALIGNMENT_ARG SYSCALL_LL (length));
# else
  return INLINE_SYSCALL_CALL (ftruncate, ..., length);
# endif
}
weak_alias (__ftruncate, ftruncate)
#endif


{f}truncate64.c:

#ifndef __NR_ftruncate64
# define __NR_ftruncate64 __NR_ftruncate
#endif

int
__{f}truncate64 (..., off_t length)
{
  return INLINE_SYSCALL_CALL (ftruncate64, ...,
                             __ALIGNMENT_ARG SYSCALL_LL64 (length));
}
weak_alias (__ftruncate64, ftruncate64)

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


[1] https://sourceware.org/ml/libc-alpha/2016-08/msg00811.html
[2] https://sourceware.org/ml/libc-alpha/2016-08/msg00812.html
> 
> 2016-09-19: Yury Norov  <ynorov@caviumnetworks.com>
> 
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c:
> 	  don't declare ftruncate() and symbols if off_t is 64-bit.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c:
> 	  declare ftruncate() and symbols if off_t is 64-bit.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
> 	  don't declare truncate() and symbols if off_t is 64-bit.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
> 	  declare truncate() and symbols if off_t is 64-bit.
> 
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> ---
>  sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c   | 2 ++
>  sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c | 9 +++++++++
>  sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c    | 2 ++
>  sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c  | 9 +++++++++
>  4 files changed, 22 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
> index e1b500d..35ae787 100644
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
> +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
> @@ -20,6 +20,7 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>  
> +#ifndef __OFF_T_MATCHES_OFF64_T
>  /* Truncate the file FD refers to to LENGTH bytes.  */
>  int
>  __ftruncate (int fd, off_t length)
> @@ -29,3 +30,4 @@ __ftruncate (int fd, off_t length)
>                           __LONG_LONG_PAIR (length >> 31, length));
>  }
>  weak_alias (__ftruncate, ftruncate)
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
> index 946f05a..0ff3e70 100644
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
> +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
> @@ -15,6 +15,8 @@
>     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/>.  */
> +#define __ftruncate __ftruncate_disable
> +#define ftruncate ftruncate_disable
>  
>  #include <errno.h>
>  #include <sys/types.h>
> @@ -30,3 +32,10 @@ __ftruncate64 (int fd, off64_t length)
>                           __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
>  }
>  weak_alias (__ftruncate64, ftruncate64)
> +
> +#undef __ftruncate
> +#undef ftruncate
> +#ifdef __OFF_T_MATCHES_OFF64_T
> +weak_alias (__ftruncate64, __ftruncate)
> +weak_alias (__ftruncate64, ftruncate)
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
> index 2579951..b3e54e4 100644
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
> +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
> @@ -20,6 +20,7 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>  
> +#ifndef __OFF_T_MATCHES_OFF64_T
>  /* Truncate PATH to LENGTH bytes.  */
>  int
>  __truncate (const char *path, off_t length)
> @@ -29,3 +30,4 @@ __truncate (const char *path, off_t length)
>                           __LONG_LONG_PAIR (length >> 31, length));
>  }
>  weak_alias (__truncate, truncate)
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
> index f2927ea..e4343cd 100644
> --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
> +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
> @@ -15,6 +15,8 @@
>     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/>.  */
> +#define __truncate __truncate_disabled
> +#define truncate truncate_disabled
>  
>  #include <errno.h>
>  #include <sys/types.h>
> @@ -29,3 +31,10 @@ truncate64 (const char *path, off64_t length)
>    return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
>                           __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
>  }
> +
> +#undef __truncate
> +#undef truncate
> +#ifdef __OFF_T_MATCHES_OFF64_T
> +weak_alias (truncate64, __truncate)
> +weak_alias (truncate64, truncate)
> +#endif
>
Yury Norov Sept. 20, 2016, 1:43 p.m. UTC | #2
On Tue, Sep 20, 2016 at 10:04:12AM -0300, Adhemerval Zanella wrote:
> 
> 
> On 19/09/2016 17:56, Yury Norov wrote:
> > If off_t is 64-bit, current implementation of truncate() and ftruncate()
> > is wrong, and proper implementation is identical to corresponding 64-bit
> > versions of syscalls. This patch creates aliases for it.
> 
> I think we can try to go forward and consolidate both all truncate and
> ftruncate implementation on Linux.  I sent a patchset last month [1] [2]
> and I will send an update today with some small fixes.  I think it should
> work on aarch64 ilp32 as well, it uses the logic for:
> 
> {f}truncate.c:
> 
> #ifndef __OFF_T_MATCHES_OFF64_T
> __{f}truncate (..., off_t length)
> {
> # ifndef __NR_ftruncate
>   return INLINE_SYSCALL_CALL (ftruncate64, ...,
>                              __ALIGNMENT_ARG SYSCALL_LL (length));
> # else
>   return INLINE_SYSCALL_CALL (ftruncate, ..., length);
> # endif
> }
> weak_alias (__ftruncate, ftruncate)
> #endif
> 
> 
> {f}truncate64.c:
> 
> #ifndef __NR_ftruncate64
> # define __NR_ftruncate64 __NR_ftruncate
> #endif
> 
> int
> __{f}truncate64 (..., off_t length)
> {
>   return INLINE_SYSCALL_CALL (ftruncate64, ...,
>                              __ALIGNMENT_ARG SYSCALL_LL64 (length));
> }
> weak_alias (__ftruncate64, ftruncate64)
> 
> #ifdef __OFF_T_MATCHES_OFF64_T
> weak_alias (__ftruncate64, ftruncate);
> #endif
> 
> 
> [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00811.html
> [2] https://sourceware.org/ml/libc-alpha/2016-08/msg00812.html

OK, looks good. I'll replace my patch with your version when you update it.
Could you also comment my patches on stat and getdents()?

https://sourceware.org/ml/libc-alpha/2016-09/msg00315.html
https://sourceware.org/ml/libc-alpha/2016-09/msg00240.html

Yury.

Patch
diff mbox

diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
index e1b500d..35ae787 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
@@ -20,6 +20,7 @@ 
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifndef __OFF_T_MATCHES_OFF64_T
 /* Truncate the file FD refers to to LENGTH bytes.  */
 int
 __ftruncate (int fd, off_t length)
@@ -29,3 +30,4 @@  __ftruncate (int fd, off_t length)
                          __LONG_LONG_PAIR (length >> 31, length));
 }
 weak_alias (__ftruncate, ftruncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
index 946f05a..0ff3e70 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
@@ -15,6 +15,8 @@ 
    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/>.  */
+#define __ftruncate __ftruncate_disable
+#define ftruncate ftruncate_disable
 
 #include <errno.h>
 #include <sys/types.h>
@@ -30,3 +32,10 @@  __ftruncate64 (int fd, off64_t length)
                          __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
 }
 weak_alias (__ftruncate64, ftruncate64)
+
+#undef __ftruncate
+#undef ftruncate
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__ftruncate64, __ftruncate)
+weak_alias (__ftruncate64, ftruncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
index 2579951..b3e54e4 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
@@ -20,6 +20,7 @@ 
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifndef __OFF_T_MATCHES_OFF64_T
 /* Truncate PATH to LENGTH bytes.  */
 int
 __truncate (const char *path, off_t length)
@@ -29,3 +30,4 @@  __truncate (const char *path, off_t length)
                          __LONG_LONG_PAIR (length >> 31, length));
 }
 weak_alias (__truncate, truncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
index f2927ea..e4343cd 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
@@ -15,6 +15,8 @@ 
    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/>.  */
+#define __truncate __truncate_disabled
+#define truncate truncate_disabled
 
 #include <errno.h>
 #include <sys/types.h>
@@ -29,3 +31,10 @@  truncate64 (const char *path, off64_t length)
   return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
                          __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
 }
+
+#undef __truncate
+#undef truncate
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (truncate64, __truncate)
+weak_alias (truncate64, truncate)
+#endif