generic/wordsize-32: don't declare getdents() if not needed

Message ID 1474304204-30677-1-git-send-email-ynorov@caviumnetworks.com
State New, archived
Headers

Commit Message

Yury Norov Sept. 19, 2016, 4:56 p.m. UTC
  Modern 32-bit arches has off_t and ino_t types both 64-bit length. It means that
struct dirent is the same as struct dirent64. So we can avoid useless conversion
from 64- to 32-bit dirent layout, and simply alias __getdents64() to __getdents().
The same is true if __USE_FILE_OFFSET64 option is enabled.

Tested with aarch64/ilp32.

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

	* sysdeps/unix/sysv/linux/bits/dirent.h: enable _DIRENT_MATCHES_DIRENT64
	  if __USE_FILE_OFFSET64 is enabled.
	* sysdeps/unix/sysv/linux/generic/getdents64.c: alias __getdents64() to
	  __getdents() also if _DIRENT_MATCHES_DIRENT64 is enabled.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: don't declare
	  __getdents() if _DIRENT_MATCHES_DIRENT64 is enabled.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 sysdeps/unix/sysv/linux/bits/dirent.h                  | 3 ++-
 sysdeps/unix/sysv/linux/generic/getdents64.c           | 3 ++-
 sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)
  

Comments

Yury Norov Oct. 25, 2016, 8:45 p.m. UTC | #1
On Mon, Sep 19, 2016 at 07:56:44PM +0300, Yury Norov wrote:
> 
> Modern 32-bit arches has off_t and ino_t types both 64-bit length. It means that
> struct dirent is the same as struct dirent64. So we can avoid useless conversion
> from 64- to 32-bit dirent layout, and simply alias __getdents64() to __getdents().
> The same is true if __USE_FILE_OFFSET64 option is enabled.
> 
> Tested with aarch64/ilp32.
> 
> 2016-09-19: Yury Norov  <ynorov@caviumnetworks.com>
> 
> 	* sysdeps/unix/sysv/linux/bits/dirent.h: enable _DIRENT_MATCHES_DIRENT64
> 	  if __USE_FILE_OFFSET64 is enabled.
> 	* sysdeps/unix/sysv/linux/generic/getdents64.c: alias __getdents64() to
> 	  __getdents() also if _DIRENT_MATCHES_DIRENT64 is enabled.
> 	* sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: don't declare
> 	  __getdents() if _DIRENT_MATCHES_DIRENT64 is enabled.
> 
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>

Ping?
  

Patch

diff --git a/sysdeps/unix/sysv/linux/bits/dirent.h b/sysdeps/unix/sysv/linux/bits/dirent.h
index 31b1961..23b7e6f 100644
--- a/sysdeps/unix/sysv/linux/bits/dirent.h
+++ b/sysdeps/unix/sysv/linux/bits/dirent.h
@@ -51,7 +51,8 @@  struct dirent64
 #define _DIRENT_HAVE_D_OFF
 #define _DIRENT_HAVE_D_TYPE
 
-#if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T
+#if (defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T) \
+  || defined __USE_FILE_OFFSET64
 /* Inform libc code that these two types are effectively identical.  */
 # define _DIRENT_MATCHES_DIRENT64	1
 #endif
diff --git a/sysdeps/unix/sysv/linux/generic/getdents64.c b/sysdeps/unix/sysv/linux/generic/getdents64.c
index 3e44699..a9b63a3 100644
--- a/sysdeps/unix/sysv/linux/generic/getdents64.c
+++ b/sysdeps/unix/sysv/linux/generic/getdents64.c
@@ -16,6 +16,7 @@ 
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <dirent.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <unistd.h>
@@ -32,6 +33,6 @@  __getdents64 (int fd, char *buf, size_t nbytes)
   return INLINE_SYSCALL (getdents64, 3, fd, buf, nbytes);
 }
 
-#if __WORDSIZE == 64
+#if (__WORDSIZE == 64) || defined (_DIRENT_MATCHES_DIRENT64)
 strong_alias (__getdents64, __getdents)
 #endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
index bc3a80e..7d2fbe6 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
@@ -30,6 +30,7 @@ 
 #include <sysdep.h>
 #include <sys/syscall.h>
 
+#ifndef _DIRENT_MATCHES_DIRENT64
 /* Pack the dirent64 struct down into 32-bit offset/inode fields, and
    ensure that no overflow occurs.  */
 ssize_t
@@ -113,3 +114,4 @@  __getdents (int fd, char *buf, size_t nbytes)
 
   return outp->b - buf;
 }
+#endif