Message ID | bc4dde77dfcd17a825d8f28f72f3292341966810.1721713597.git.tony.ambardar@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | d44c93fc2f5a0c47b23fa03d374e45259abd92d2 |
Headers | show |
Series | selftests/bpf: Improve libc portability / musl support (part 1) | expand |
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. > > Fixes: 8e7c2a023ac0 ("selftests/bpf: Add benchmark runner > infrastructure") > Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com> > --- > 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 = {
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@gmail.com> > > --- > > 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 = { >
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 = {
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 Fixes: 8e7c2a023ac0 ("selftests/bpf: Add benchmark runner infrastructure") Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com> --- tools/testing/selftests/bpf/bench.c | 1 + 1 file changed, 1 insertion(+)