Subject: Re: bug#39929: coreutils-8.32 fails to build on aarch64

From: Pádraig Brady <[email-masked]>
Date: Thu, 5 Mar 2020 17:39:23 +0000

On 05/03/2020 16:21, Kamil Dudka wrote:
> While trying to build coreutils-8.32 for Fedora on aarch64, I got the following
> compilation failure:
> 
> ../src/ls.c: In function 'print_dir':
> ../src/ls.c:3026:24: error: 'SYS_getdents' undeclared (first use in this function); did you mean 'SYS_getdents64'?
>   3026 |           if (syscall (SYS_getdents, dirfd (dirp), NULL, 0) == -1
>        |                        ^~~~~~~~~~~~
>        |                        SYS_getdents64
> ../src/ls.c:3026:24: note: each undeclared identifier is reported only once for each function it appears in
> 
> 
> Sorry for reporting it late.  I tried to build 8.31.90-cc4c and 8.31.99-f2034
> in Fedora copr but forgot to enable aarch64, so these builds succeeded  :-/

Ah well.
Does the attached address this for you.
>From 8012c07aae89f9f855b7c0663158b24464248a3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Thu, 5 Mar 2020 17:34:33 +0000
Subject: [PATCH] build: fix build failure on linux systems without getdents

* src/ls.c (print_dir): aarch64 doesn't define the getdents
system call, only providing the getdents64 variant.
This is available enough to use instead.
---
 src/ls.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index 24b983287..29462bfee 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3018,12 +3018,12 @@ print_dir (char const *name, char const *realname, bool command_line_arg)
           if (errno != EOVERFLOW)
             break;
         }
-#ifdef __linux__
       else if (! found_any_entries)
         {
+#if defined __linux__ && defined SYS_getdents64
           /* If readdir finds no directory entries at all, not even "." or
              "..", then double check that the directory exists.  */
-          if (syscall (SYS_getdents, dirfd (dirp), NULL, 0) == -1
+          if (syscall (SYS_getdents64, dirfd (dirp), NULL, 0) == -1
               && errno != EINVAL)
             {
               /* We exclude EINVAL as that pertains to buffer handling,
@@ -3031,9 +3031,9 @@ print_dir (char const *name, char const *realname, bool command_line_arg)
                  ENOENT is returned if appropriate before buffer handling.  */
               file_failure (command_line_arg, _("reading directory %s"), name);
             }
+#endif
           break;
         }
-#endif
       else
         break;
 
-- 
2.24.1