From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: "Raphaël Mélotte" <raphael.melotte@mind.be>
Cc: buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 1/1] package: busybox: backport fix for missing getrandom()
Date: Mon, 8 May 2023 23:47:54 +0200 [thread overview]
Message-ID: <20230508214754.GW252090@scaer> (raw)
In-Reply-To: <20230508214525.GV252090@scaer>
Raphaël, All,
On 2023-05-08 23:45 +0200, Yann E. MORIN spake thusly:
> On 2023-04-19 14:51 +0200, Raphaël Mélotte spake thusly:
[--SNIP--]
> > Fixes:
> > - https://gitlab.com/buildroot.org/buildroot/-/jobs/4122624028
> > - https://gitlab.com/buildroot.org/buildroot/-/jobs/4122624031
> > Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
> I had to backport this patch, as it causes build failures:
I had to _revert_ this patch...
Regards,
Yann E. MORIN.
> $ cat defconfig
> BR2_arm=y
> BR2_cortex_a7=y
> BR2_TOOLCHAIN_EXTERNAL=y
> BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
>
> $ make busybox-configure
> [...]
> ..../build/busybox-1.36.0/Makefile.flags:165: *** unterminated call to function 'shell': missing ')'. Stop.
>
>
> ... which is dues to some issue in (scroll down)...
>
> > diff --git a/package/busybox/0007-seedrng-fix-getrandom-detection-for-non-glibc-libc.patch b/package/busybox/0007-seedrng-fix-getrandom-detection-for-non-glibc-libc.patch
> > new file mode 100644
> > index 0000000000..90cace7968
> > --- /dev/null
> > +++ b/package/busybox/0007-seedrng-fix-getrandom-detection-for-non-glibc-libc.patch
> > @@ -0,0 +1,106 @@
> > +From b8d32dba741daea2ed01a0da32083b1bc994aa04 Mon Sep 17 00:00:00 2001
> > +From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <raphael.melotte@mind.be>
> > +Date: Tue, 18 Apr 2023 15:54:43 +0200
> > +Subject: [PATCH] seedrng: fix getrandom() detection for non-glibc libc
> > +MIME-Version: 1.0
> > +Content-Type: text/plain; charset=UTF-8
> > +Content-Transfer-Encoding: 8bit
> > +
> > +glibc <= 2.24 does not provide getrandom(). A check for it has been
> > +added in 200a9669fbf6f06894e4243cccc9fc11a1a6073a and fixed in
> > +cb57abb46f06f4ede8d9ccbdaac67377fdf416cf.
> > +
> > +However, building with a libc other than glibc can lead to the same
> > +problem as not every other libc has getrandom() either:
> > +
> > +- uClibc provides it from v1.0.2 onwards, but requires to define
> > +_GNU_SOURCE (all versions - we already define it by default), and
> > +stddef to be included first (when using uClibc < 1.0.35 - we already
> > +include it through libbb.h).
> > +
> > +- musl libc has getrandom(), but only from version 1.1.20 onwards. As
> > +musl does not provide __MUSL__ or version information, it's not
> > +possible to check for it like we did for glibc.
> > +
> > +All of this makes it difficult (or impossible in case of musl) to
> > +check what we need to do to have getrandom() based on each libc
> > +versions.
> > +
> > +On top of that, getrandom() is also not available on older kernels. As
> > +an example, when using a 3.10 kernel with uClibc 1.0.26, getrandom()
> > +is declared so compiling works, but it fails at link time because
> > +getrandom() is not defined.
> > +
> > +To make it easier, take a similar approach to what was done for the
> > +crypt library: try to build a sample program to see if we have
> > +getrandom().
> > +
> > +Based on the new Makefile variable, we now either use the
> > +libc-provided getrandom() when it's available, or use our own
> > +implementation when it's not (like it was the case already for glibc <
> > +2.25).
> > +
> > +This should fix compiling with many libc/kernel combinations.
> > +
> > +Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
> > +Upstream: http://lists.busybox.net/pipermail/busybox/2023-April/090285.html
> > +---
> > +Note that I was not able to test every single combination, but I could
> > +confirm it builds successfully for:
> > +uClibc 10.0.24, linux headers 3.10 (libc getrandom NOT used)
> > +uClibc 1.0.36, linux headers 4.9 (libc getrandom used)
> > +musl 1.1.16, linux headers 4.12 (libc getrandom NOT used)
> > +musl 1.2.1, linux headers (libc getrandom used)
> > +glibc 2.25, linux headers 4.10 (libc getrandom used)
> > +
> > + Makefile.flags | 7 +++++++
> > + miscutils/seedrng.c | 8 ++++----
> > + 2 files changed, 11 insertions(+), 4 deletions(-)
> > +
> > +diff --git a/Makefile.flags b/Makefile.flags
> > +index 1cec5ba20..88c11862f 100644
> > +--- a/Makefile.flags
> > ++++ b/Makefile.flags
> > +@@ -161,6 +161,13 @@ ifeq ($(RT_AVAILABLE),y)
> > + LDLIBS += rt
> > + endif
> > +
> > ++# Not all libc versions have getrandom, so check for it.
> > ++HAVE_GETRANDOM := $(shell printf '#include <stddef.h>\n#include <sys/random.h>\nint main(void){char buf[256];\ngetrandom(buf,sizeof(buf),GRND_NONBLOCK);}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -D_GNU_SOURCE -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
>
> ... this big line here...
>
> Regards,
> Yann E. MORIN.
>
> > ++
> > ++ifeq ($(HAVE_GETRANDOM),y)
> > ++CFLAGS += -DHAVE_GETRANDOM
> > ++endif
> > ++
> > + # libpam may use libpthread, libdl and/or libaudit.
> > + # On some platforms that requires an explicit -lpthread, -ldl, -laudit.
> > + # However, on *other platforms* it fails when some of those flags
> > +diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c
> > +index 3bf6e2ea7..2f1e18c32 100644
> > +--- a/miscutils/seedrng.c
> > ++++ b/miscutils/seedrng.c
> > +@@ -44,8 +44,10 @@
> > + #include <linux/random.h>
> > + #include <sys/file.h>
> > +
> > +-/* Fix up glibc <= 2.24 not having getrandom() */
> > +-#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24
> > ++/* Fix up some libc (e.g. glibc <= 2.24) not having getrandom() */
> > ++#if defined HAVE_GETRANDOM
> > ++#include <sys/random.h>
> > ++#else /* No getrandom */
> > + #include <sys/syscall.h>
> > + static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
> > + {
> > +@@ -56,8 +58,6 @@ static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
> > + return -1;
> > + # endif
> > + }
> > +-#else
> > +-#include <sys/random.h>
> > + #endif
> > +
> > + /* Apparently some headers don't ship with this yet. */
> > +--
> > +2.39.1
> > +
> > --
> > 2.37.3
> >
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
>
> --
> .-----------------.--------------------.------------------.--------------------.
> | 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
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
--
.-----------------.--------------------.------------------.--------------------.
| 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
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2023-05-08 21:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 12:51 [Buildroot] [PATCH 1/1] package: busybox: backport fix for missing getrandom() Raphaël Mélotte
2023-05-08 19:30 ` Yann E. MORIN
2023-05-08 21:45 ` Yann E. MORIN
2023-05-08 21:47 ` Yann E. MORIN [this message]
2023-05-09 10:07 ` Raphaël Mélotte via buildroot
2023-05-09 15:41 ` Yann E. MORIN
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230508214754.GW252090@scaer \
--to=yann.morin.1998@free.fr \
--cc=buildroot@buildroot.org \
--cc=raphael.melotte@mind.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox