Skip to content

Commit fa633a0

Browse files
namhyungborkmann
authored andcommitted
libbpf: Fix build on read-only filesystems
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f54c789 commit fa633a0

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

tools/lib/bpf/Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ STATIC_OBJDIR := $(OUTPUT)staticobjs/
138138
BPF_IN_SHARED := $(SHARED_OBJDIR)libbpf-in.o
139139
BPF_IN_STATIC := $(STATIC_OBJDIR)libbpf-in.o
140140
VERSION_SCRIPT := libbpf.map
141+
BPF_HELPER_DEFS := $(OUTPUT)bpf_helper_defs.h
141142

142143
LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
143144
LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
@@ -159,7 +160,7 @@ all: fixdep
159160

160161
all_cmd: $(CMD_TARGETS) check
161162

162-
$(BPF_IN_SHARED): force elfdep bpfdep bpf_helper_defs.h
163+
$(BPF_IN_SHARED): force elfdep bpfdep $(BPF_HELPER_DEFS)
163164
@(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \
164165
(diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \
165166
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 +178,12 @@ $(BPF_IN_SHARED): force elfdep bpfdep bpf_helper_defs.h
177178
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
178179
$(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)"
179180

180-
$(BPF_IN_STATIC): force elfdep bpfdep bpf_helper_defs.h
181+
$(BPF_IN_STATIC): force elfdep bpfdep $(BPF_HELPER_DEFS)
181182
$(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR)
182183

183-
bpf_helper_defs.h: $(srctree)/tools/include/uapi/linux/bpf.h
184+
$(BPF_HELPER_DEFS): $(srctree)/tools/include/uapi/linux/bpf.h
184185
$(Q)$(srctree)/scripts/bpf_helpers_doc.py --header \
185-
--file $(srctree)/tools/include/uapi/linux/bpf.h > bpf_helper_defs.h
186+
--file $(srctree)/tools/include/uapi/linux/bpf.h > $(BPF_HELPER_DEFS)
186187

187188
$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
188189

@@ -243,15 +244,15 @@ install_lib: all_cmd
243244
$(call do_install_mkdir,$(libdir_SQ)); \
244245
cp -fpR $(LIB_FILE) $(DESTDIR)$(libdir_SQ)
245246

246-
install_headers: bpf_helper_defs.h
247+
install_headers: $(BPF_HELPER_DEFS)
247248
$(call QUIET_INSTALL, headers) \
248249
$(call do_install,bpf.h,$(prefix)/include/bpf,644); \
249250
$(call do_install,libbpf.h,$(prefix)/include/bpf,644); \
250251
$(call do_install,btf.h,$(prefix)/include/bpf,644); \
251252
$(call do_install,libbpf_util.h,$(prefix)/include/bpf,644); \
252253
$(call do_install,xsk.h,$(prefix)/include/bpf,644); \
253254
$(call do_install,bpf_helpers.h,$(prefix)/include/bpf,644); \
254-
$(call do_install,bpf_helper_defs.h,$(prefix)/include/bpf,644); \
255+
$(call do_install,$(BPF_HELPER_DEFS),$(prefix)/include/bpf,644); \
255256
$(call do_install,bpf_tracing.h,$(prefix)/include/bpf,644); \
256257
$(call do_install,bpf_endian.h,$(prefix)/include/bpf,644); \
257258
$(call do_install,bpf_core_read.h,$(prefix)/include/bpf,644);
@@ -271,7 +272,7 @@ config-clean:
271272
clean:
272273
$(call QUIET_CLEAN, libbpf) $(RM) -rf $(CMD_TARGETS) \
273274
*.o *~ *.a *.so *.so.$(LIBBPF_MAJOR_VERSION) .*.d .*.cmd \
274-
*.pc LIBBPF-CFLAGS bpf_helper_defs.h \
275+
*.pc LIBBPF-CFLAGS $(BPF_HELPER_DEFS) \
275276
$(SHARED_OBJDIR) $(STATIC_OBJDIR)
276277
$(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf
277278

tools/testing/selftests/bpf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ xdping
4040
test_cpp
4141
/no_alu32
4242
/bpf_gcc
43+
bpf_helper_defs.h

tools/testing/selftests/bpf/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ force:
120120
$(BPFOBJ): force
121121
$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
122122

123-
BPF_HELPERS := $(BPFDIR)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h)
124-
$(BPFDIR)/bpf_helper_defs.h:
125-
$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ bpf_helper_defs.h
123+
BPF_HELPERS := $(OUTPUT)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h)
124+
$(OUTPUT)/bpf_helper_defs.h:
125+
$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ $(OUTPUT)/bpf_helper_defs.h
126126

127127
# Get Clang's default includes on this system, as opposed to those seen by
128128
# '-target bpf'. This fixes "missing" files on some architectures/distros,

0 commit comments

Comments
 (0)