Skip to contentSkip to conversation

package/nfs-utils: fix build failure due to glibc <= 2.24

PATCH In review Giulio Benetti 2 participants 2 messages Oct 26, 2023 – Nov 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/nfs-utils: fix build failure due to glibc <= 2.24

Add local patches pending upstream that check if <sys/random.h> exists or not. If it doesn't exist it uses uses the corresponding syscall if present, otherwise it fails to build during autotools configuration. This happens only on Linux < 3.17.

---
 ...e-due-to-glibc-2.24-and-check-for-Li.patch | 98 +++++++++++++++++++
 .../0004-Drop-unused-sys-random.h.patch       | 40 ++++++++
 2 files changed, 138 insertions(+)
 create mode 100644 package/nfs-utils/0003-Fix-build-failure-due-to-glibc-2.24-and-check-for-Li.patch
 create mode 100644 package/nfs-utils/0004-Drop-unused-sys-random.h.patch
package/nfs-utils/0003-Fix-build-failure-due-to-glibc-2.24-and-check-for-Li.patch new file +98 -0
new file mode 100644
index 0000000000..4febfee9e4
@@ -0,0 +1,98 @@
+From b99d073193502efdead21a6d2488350e1a29bac4 Mon Sep 17 00:00:00 2001
+From: Giulio Benetti <[email protected]>
+Date: Thu, 26 Oct 2023 13:18:51 +0200
+Subject: [PATCH] Fix build failure due to glibc <= 2.24 and check for Linux
+ 3.17+
+
+Function getrandom() is present only with glibc 2.24+ so add a direct
+syscall otherwise. This is only possible with Linux 3.17+ so let's also
+check for it and in case emit error on autotools configure.
+
+Upstream: https://patchwork.kernel.org/project/linux-nfs/patch/[email protected]/
+
+Signed-off-by: Giulio Benetti <[email protected]>
+---
+ configure.ac                      | 32 +++++++++++++++++++++++++++++++
+ support/reexport/backend_sqlite.c | 17 +++++++++++++++-
+ 2 files changed, 48 insertions(+), 1 deletion(-)
+
+diff --git a/configure.ac b/configure.ac
+index 6fbcb974..7efca90c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -328,6 +328,38 @@ AC_CHECK_HEADERS([sched.h], [], [])
+ AC_CHECK_FUNCS([unshare fstatat statx], [] , [])
+ AC_LIBPTHREAD([])
+ 
++AC_MSG_CHECKING([for getrandom (Linux 3.17+, glibc 2.25+)])
++AC_LINK_IFELSE([AC_LANG_SOURCE([
++  #include <stdlib.h>  /* for NULL */
++  #include <sys/random.h>
++  int main() {
++    return getrandom(NULL, 0U, 0U);
++  }
++])], [
++    AC_DEFINE([HAVE_GETRANDOM], [1],
++        [Define to 1 if you have the `getrandom' function.])
++    AC_MSG_RESULT([yes])
++], [
++    AC_MSG_RESULT([no])
++
++    AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)])
++    AC_LINK_IFELSE([AC_LANG_SOURCE([
++      #include <stdlib.h>  /* for NULL */
++      #include <unistd.h>  /* for syscall */
++      #include <sys/syscall.h>  /* for SYS_getrandom */
++      int main() {
++        syscall(SYS_getrandom, NULL, 0, 0);
++        return 0;
++      }
++    ])], [
++        AC_DEFINE([HAVE_SYSCALL_GETRANDOM], [1],
++            [Define to 1 if you have `syscall' and `SYS_getrandom'.])
++        AC_MSG_RESULT([yes])
++    ], [
++        AC_MSG_ERROR(['syscall' and 'SYS_getrandom' not found.])
++    ])
++])
++
+ # rpc/rpc.h can come from the glibc or from libtirpc
+ nfsutils_save_CPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${CPPFLAGS} ${TIRPC_CFLAGS}"
+diff --git a/support/reexport/backend_sqlite.c b/support/reexport/backend_sqlite.c
+index 132f30c4..f1e390bc 100644
+--- a/support/reexport/backend_sqlite.c
++++ b/support/reexport/backend_sqlite.c
+@@ -7,13 +7,28 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <sys/random.h>
+ #include <unistd.h>
+ 
+ #include "conffile.h"
+ #include "reexport_backend.h"
+ #include "xlog.h"
+ 
++/* Fix up glibc <= 2.24 not having getrandom() */
++#if defined HAVE_GETRANDOM
++#include <sys/random.h>
++#else
++#include <sys/syscall.h>
++static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
++{
++# if defined(__NR_getrandom)
++	return syscall(__NR_getrandom, buffer, length, flags);
++# else
++	errno = ENOSYS;
++	return -1;
++# endif
++}
++#endif
++
+ #define REEXPDB_DBFILE NFS_STATEDIR "/reexpdb.sqlite3"
+ #define REEXPDB_DBFILE_WAIT_USEC (5000)
+ 
+-- 
+2.34.1
+
package/nfs-utils/0004-Drop-unused-sys-random.h.patch new file +40 -0
new file mode 100644
index 0000000000..b8467a573d
@@ -0,0 +1,40 @@
+From 03946584e9ecadb72b09433ff86cc70d297a970f Mon Sep 17 00:00:00 2001
+From: Giulio Benetti <[email protected]>
+Date: Thu, 26 Oct 2023 13:23:44 +0200
+Subject: [PATCH] Drop unused <sys/random.h>
+
+Upstream: https://patchwork.kernel.org/project/linux-nfs/patch/[email protected]/
+
+Signed-off-by: Giulio Benetti <[email protected]>
+---
+ support/reexport/fsidd.c    | 1 -
+ support/reexport/reexport.c | 1 -
+ 2 files changed, 2 deletions(-)
+
+diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c
+index d4b245e8..352de1be 100644
+--- a/support/reexport/fsidd.c
++++ b/support/reexport/fsidd.c
+@@ -10,7 +10,6 @@
+ #include <limits.h>
+ #include <stdint.h>
+ #include <stdio.h>
+-#include <sys/random.h>
+ #include <sys/socket.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+diff --git a/support/reexport/reexport.c b/support/reexport/reexport.c
+index d9a700af..c59e6b2f 100644
+--- a/support/reexport/reexport.c
++++ b/support/reexport/reexport.c
+@@ -7,7 +7,6 @@
+ #endif
+ #include <stdint.h>
+ #include <stdio.h>
+-#include <sys/random.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/vfs.h>
+-- 
+2.34.1
+
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Giulio, All,

On 2023-10-26 14:12 +0200, Giulio Benetti spake thusly:

Quoted 8 lines

Add local patches pending upstream that check if <sys/random.h> exists or not. If it doesn't exist it uses uses the corresponding syscall if present, otherwise it fails to build during autotools configuration. This happens only on Linux < 3.17.

Thanks for this patch. However, upstream has applied alternative patches by Petr, and the two sets conflict.

Can you work with Petr on getting a working set of patches, please?

Thanks!

Regards,
Yann E. MORIN.

Quoted 164 lines
---
 ...e-due-to-glibc-2.24-and-check-for-Li.patch | 98 +++++++++++++++++++
 .../0004-Drop-unused-sys-random.h.patch       | 40 ++++++++
 2 files changed, 138 insertions(+)
 create mode 100644 package/nfs-utils/0003-Fix-build-failure-due-to-glibc-2.24-and-check-for-Li.patch
 create mode 100644 package/nfs-utils/0004-Drop-unused-sys-random.h.patch
package/nfs-utils/0003-Fix-build-failure-due-to-glibc-2.24-and-check-for-Li.patch new file +98 -0
new file mode 100644
index 0000000000..4febfee9e4
@@ -0,0 +1,98 @@
+From b99d073193502efdead21a6d2488350e1a29bac4 Mon Sep 17 00:00:00 2001
+From: Giulio Benetti <[email protected]>
+Date: Thu, 26 Oct 2023 13:18:51 +0200
+Subject: [PATCH] Fix build failure due to glibc <= 2.24 and check for Linux
+ 3.17+
+
+Function getrandom() is present only with glibc 2.24+ so add a direct
+syscall otherwise. This is only possible with Linux 3.17+ so let's also
+check for it and in case emit error on autotools configure.
+
+Upstream: https://patchwork.kernel.org/project/linux-nfs/patch/[email protected]/
+
+Signed-off-by: Giulio Benetti <[email protected]>
+---
+ configure.ac                      | 32 +++++++++++++++++++++++++++++++
+ support/reexport/backend_sqlite.c | 17 +++++++++++++++-
+ 2 files changed, 48 insertions(+), 1 deletion(-)
+
+diff --git a/configure.ac b/configure.ac
+index 6fbcb974..7efca90c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -328,6 +328,38 @@ AC_CHECK_HEADERS([sched.h], [], [])
+ AC_CHECK_FUNCS([unshare fstatat statx], [] , [])
+ AC_LIBPTHREAD([])
+ 
++AC_MSG_CHECKING([for getrandom (Linux 3.17+, glibc 2.25+)])
++AC_LINK_IFELSE([AC_LANG_SOURCE([
++  #include <stdlib.h>  /* for NULL */
++  #include <sys/random.h>
++  int main() {
++    return getrandom(NULL, 0U, 0U);
++  }
++])], [
++    AC_DEFINE([HAVE_GETRANDOM], [1],
++        [Define to 1 if you have the `getrandom' function.])
++    AC_MSG_RESULT([yes])
++], [
++    AC_MSG_RESULT([no])
++
++    AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)])
++    AC_LINK_IFELSE([AC_LANG_SOURCE([
++      #include <stdlib.h>  /* for NULL */
++      #include <unistd.h>  /* for syscall */
++      #include <sys/syscall.h>  /* for SYS_getrandom */
++      int main() {
++        syscall(SYS_getrandom, NULL, 0, 0);
++        return 0;
++      }
++    ])], [
++        AC_DEFINE([HAVE_SYSCALL_GETRANDOM], [1],
++            [Define to 1 if you have `syscall' and `SYS_getrandom'.])
++        AC_MSG_RESULT([yes])
++    ], [
++        AC_MSG_ERROR(['syscall' and 'SYS_getrandom' not found.])
++    ])
++])
++
+ # rpc/rpc.h can come from the glibc or from libtirpc
+ nfsutils_save_CPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${CPPFLAGS} ${TIRPC_CFLAGS}"
+diff --git a/support/reexport/backend_sqlite.c b/support/reexport/backend_sqlite.c
+index 132f30c4..f1e390bc 100644
+--- a/support/reexport/backend_sqlite.c
++++ b/support/reexport/backend_sqlite.c
+@@ -7,13 +7,28 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <sys/random.h>
+ #include <unistd.h>
+ 
+ #include "conffile.h"
+ #include "reexport_backend.h"
+ #include "xlog.h"
+ 
++/* Fix up glibc <= 2.24 not having getrandom() */
++#if defined HAVE_GETRANDOM
++#include <sys/random.h>
++#else
++#include <sys/syscall.h>
++static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
++{
++# if defined(__NR_getrandom)
++	return syscall(__NR_getrandom, buffer, length, flags);
++# else
++	errno = ENOSYS;
++	return -1;
++# endif
++}
++#endif
++
+ #define REEXPDB_DBFILE NFS_STATEDIR "/reexpdb.sqlite3"
+ #define REEXPDB_DBFILE_WAIT_USEC (5000)
+ 
+-- 
+2.34.1
+
package/nfs-utils/0004-Drop-unused-sys-random.h.patch new file +40 -0
new file mode 100644
index 0000000000..b8467a573d
@@ -0,0 +1,40 @@
+From 03946584e9ecadb72b09433ff86cc70d297a970f Mon Sep 17 00:00:00 2001
+From: Giulio Benetti <[email protected]>
+Date: Thu, 26 Oct 2023 13:23:44 +0200
+Subject: [PATCH] Drop unused <sys/random.h>
+
+Upstream: https://patchwork.kernel.org/project/linux-nfs/patch/[email protected]/
+
+Signed-off-by: Giulio Benetti <[email protected]>
+---
+ support/reexport/fsidd.c    | 1 -
+ support/reexport/reexport.c | 1 -
+ 2 files changed, 2 deletions(-)
+
+diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c
+index d4b245e8..352de1be 100644
+--- a/support/reexport/fsidd.c
++++ b/support/reexport/fsidd.c
+@@ -10,7 +10,6 @@
+ #include <limits.h>
+ #include <stdint.h>
+ #include <stdio.h>
+-#include <sys/random.h>
+ #include <sys/socket.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+diff --git a/support/reexport/reexport.c b/support/reexport/reexport.c
+index d9a700af..c59e6b2f 100644
+--- a/support/reexport/reexport.c
++++ b/support/reexport/reexport.c
+@@ -7,7 +7,6 @@
+ #endif
+ #include <stdint.h>
+ #include <stdio.h>
+-#include <sys/random.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/vfs.h>
+-- 
+2.34.1
+
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot