Re: [PATCH] libbpf: Fix build on read-only filesystems

From: Andrii Nakryiko
Date: Fri Dec 20 2019 - 17:02:03 EST


On Thu, Dec 19, 2019 at 7:26 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> I got the following error when I tried to build perf on a read-only
> filesystem with O=dir option.
>
> $ cd /some/where/ro/linux/tools/perf
> $ make O=$HOME/build/perf
> ...
> CC /home/namhyung/build/perf/lib.o
> /bin/sh: bpf_helper_defs.h: Read-only file system
> make[3]: *** [Makefile:184: bpf_helper_defs.h] Error 1
> make[2]: *** [Makefile.perf:778: /home/namhyung/build/perf/libbpf.a] Error 2
> make[2]: *** Waiting for unfinished jobs....
> LD /home/namhyung/build/perf/libperf-in.o
> AR /home/namhyung/build/perf/libperf.a
> PERF_VERSION = 5.4.0
> make[1]: *** [Makefile.perf:225: sub-make] Error 2
> make: *** [Makefile:70: all] Error 2
>
> It was becaused bpf_helper_defs.h was generated in current directory.
> Move it to OUTPUT directory.
>
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> ---
> tools/lib/bpf/Makefile | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index 99425d0be6ff..2f42a35f4634 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -159,7 +159,7 @@ all: fixdep
>
> all_cmd: $(CMD_TARGETS) check
>
> -$(BPF_IN_SHARED): force elfdep bpfdep bpf_helper_defs.h
> +$(BPF_IN_SHARED): force elfdep bpfdep $(OUTPUT)bpf_helper_defs.h

btw, there is a lot of $(OUTPUT)bpf_helper_defs.h repetition, could
you please extract it into a variable, similar to BPF_IN_SHARED and
others? E.g., just BPF_HELPER_DEFS would work. Thanks!

> @(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \
> (diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \
> echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true
> @@ -177,12 +177,12 @@ $(BPF_IN_SHARED): force elfdep bpfdep bpf_helper_defs.h
> echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true
> $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)"

[...]