Re: [PATCH bpf-next v1 07/19] selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 24, 2024 at 03:08:31PM +0800, Geliang Tang wrote:
> On Mon, 2024-07-22 at 22:54 -0700, Tony Ambardar wrote:
> > Add a "bpf_util.h" include to avoid the following error seen
> > compiling for
> > mips64el with musl libc:
> > 
> >   bench.c: In function 'find_benchmark':
> >   bench.c:590:25: error: implicit declaration of function
> > 'ARRAY_SIZE' [-Werror=implicit-function-declaration]
> >     590 |         for (i = 0; i < ARRAY_SIZE(benchs); i++) {
> >         |                         ^~~~~~~~~~
> >   cc1: all warnings being treated as errors
> 
> I'm curious why this error doesn't occur on other platforms. ARRAY_SIZE
> is actually defined in linux/kernel.h (tools/include/linux/kernel.h). I
> think you should find out why this file is not included on your
> platform.

The surprising reason is that it compiles on glibc systems by accident, due
to bench.c using get_nprocs() and needing to include <sys/sysinfo.h>. On
musl systems this header defines 'struct sysinfo', but the glibc header
version pulls in <linux/kernel.h> for this struct, which in turn drags in
ARRAY_SIZE and the rest of the kitchen sink. So not very portable...

> > 
> > Fixes: 8e7c2a023ac0 ("selftests/bpf: Add benchmark runner
> > infrastructure")
> > Signed-off-by: Tony Ambardar <tony.ambardar@xxxxxxxxx>
> > ---
> >  tools/testing/selftests/bpf/bench.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/tools/testing/selftests/bpf/bench.c
> > b/tools/testing/selftests/bpf/bench.c
> > index 627b74ae041b..90dc3aca32bd 100644
> > --- a/tools/testing/selftests/bpf/bench.c
> > +++ b/tools/testing/selftests/bpf/bench.c
> > @@ -10,6 +10,7 @@
> >  #include <sys/sysinfo.h>
> >  #include <signal.h>
> >  #include "bench.h"
> > +#include "bpf_util.h"
> >  #include "testing_helpers.h"
> >  
> >  struct env env = {
> 




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux