Busybox build error with glibc < 2.25

Markus Mayer mmayer at broadcom.com
Wed Feb 22 22:25:56 UTC 2023


Hi all,

With busybox 1.36.0, we are seeing the following build error if the
target system is using glibc older than 2.25.

  CC      coreutils/printf.o
miscutils/seedrng.c:45:24: fatal error: sys/random.h: No such file or directory
 #include <sys/random.h>
                        ^
compilation terminated.
scripts/Makefile.build:197: recipe for target 'miscutils/seedrng.o' failed
make[5]: *** [miscutils/seedrng.o] Error 1

Aside from the missing header file, this would subsequently be
followed by a linker error that getrandom() is an unknown symbol.

On systems with a newer glibc (>= 2.25), all is well.

This problem happens, because getrandom() is only provided by glibc
2.25 or newer. The kernel supports it as of 3.17, so there is a
version gap where the kernel provides this syscall, but glibc doesn't
provide an interface for it. This seems somewhat problematic.

A stub like this (with some tweaks to how header files are being
included) would allow things to build (and work) as intended:

ssize_t getrandom(void *buffer, size_t length, unsigned int flags)
{
#ifdef __NR_getrandom
      return syscall(__NR_getrandom, buffer, length, flags);
#else
      /* For kernels that don't support getrandom() (< 3.17). */
      errno = ENOSYS;
      return -1;
#endif
}

However, to add such a stub (and to prevent including sys/random.h)
when needed, the build process would need to detect the necessity for
this workaround. However, there seems to be no "configure" stage in
Busybox, so I am not sure how this pre-build detection can be
accomplished. We'd need to compile and link a test program that tries
to use getrandom() and make decisions based on the outcome. But how?

Do you have any suggestions how Busybox could provide an
implementation of the getrandom() system call if glibc does not?

Regards,
-Markus


More information about the busybox mailing list