Message ID | 20211003192208.6297-6-quentin@isovalent.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | install libbpf headers when using the library | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-PR | success | PR summary |
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 5 maintainers not CCed: kafai@fb.com john.fastabend@gmail.com songliubraving@fb.com yhs@fb.com kpsingh@kernel.org |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 41 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
bpf/vmtest-bpf-next | success | VM_Test |
On Sun, Oct 3, 2021 at 12:22 PM Quentin Monnet <quentin@isovalent.com> wrote: > > API headers from libbpf should not be accessed directly from the > library's source directory. Instead, they should be exported with "make > install_headers". Let's make sure that bpf/preload/Makefile installs the > headers properly when building. > > Note that we declare an additional dependency for iterators/iterators.o: > having $(LIBBPF_A) as a dependency to "$(obj)/bpf_preload_umd" is not > sufficient, as it makes it required only at the linking step. But we > need libbpf to be compiled, and in particular its headers to be > exported, before we attempt to compile iterators.o. The issue would not > occur before this commit, because libbpf's headers were not exported and > were always available under tools/lib/bpf. > > Signed-off-by: Quentin Monnet <quentin@isovalent.com> > --- > kernel/bpf/preload/Makefile | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > > diff --git a/kernel/bpf/preload/Makefile b/kernel/bpf/preload/Makefile > index 1951332dd15f..efccf857f7ed 100644 > --- a/kernel/bpf/preload/Makefile > +++ b/kernel/bpf/preload/Makefile > @@ -1,21 +1,36 @@ > # SPDX-License-Identifier: GPL-2.0 > > LIBBPF_SRCS = $(srctree)/tools/lib/bpf/ > -LIBBPF_A = $(obj)/libbpf.a > -LIBBPF_OUT = $(abspath $(obj)) > +LIBBPF_OUT = $(abspath $(obj))/libbpf > +LIBBPF_A = $(LIBBPF_OUT)/libbpf.a > +LIBBPF_DESTDIR = $(LIBBPF_OUT) > +LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > > # Although not in use by libbpf's Makefile, set $(O) so that the "dummy" test > # in tools/scripts/Makefile.include always succeeds when building the kernel > # with $(O) pointing to a relative path, as in "make O=build bindeb-pkg". > -$(LIBBPF_A): > - $(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a > +$(LIBBPF_A): | $(LIBBPF_OUT) > + $(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ \ > + DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > + $(LIBBPF_OUT)/libbpf.a install_headers > + > +libbpf_hdrs: $(LIBBPF_A) > + > +.PHONY: libbpf_hdrs > + > +$(LIBBPF_OUT): > + $(call msg,MKDIR,$@) > + $(Q)mkdir -p $@ > > userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \ > - -I $(srctree)/tools/lib/ -Wno-unused-result > + -I $(LIBBPF_INCLUDE) -Wno-unused-result > > userprogs := bpf_preload_umd > > clean-files := $(userprogs) bpf_helper_defs.h FEATURE-DUMP.libbpf staticobjs/ feature/ > +clean-files += $(LIBBPF_OUT) $(LIBBPF_DESTDIR) > + > +$(obj)/iterators/iterators.o: libbpf_hdrs this should probably be order-only dependency as well > > bpf_preload_umd-objs := iterators/iterators.o > bpf_preload_umd-userldlibs := $(LIBBPF_A) -lelf -lz > -- > 2.30.2 >
diff --git a/kernel/bpf/preload/Makefile b/kernel/bpf/preload/Makefile index 1951332dd15f..efccf857f7ed 100644 --- a/kernel/bpf/preload/Makefile +++ b/kernel/bpf/preload/Makefile @@ -1,21 +1,36 @@ # SPDX-License-Identifier: GPL-2.0 LIBBPF_SRCS = $(srctree)/tools/lib/bpf/ -LIBBPF_A = $(obj)/libbpf.a -LIBBPF_OUT = $(abspath $(obj)) +LIBBPF_OUT = $(abspath $(obj))/libbpf +LIBBPF_A = $(LIBBPF_OUT)/libbpf.a +LIBBPF_DESTDIR = $(LIBBPF_OUT) +LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include # Although not in use by libbpf's Makefile, set $(O) so that the "dummy" test # in tools/scripts/Makefile.include always succeeds when building the kernel # with $(O) pointing to a relative path, as in "make O=build bindeb-pkg". -$(LIBBPF_A): - $(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a +$(LIBBPF_A): | $(LIBBPF_OUT) + $(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ \ + DESTDIR=$(LIBBPF_DESTDIR) prefix= \ + $(LIBBPF_OUT)/libbpf.a install_headers + +libbpf_hdrs: $(LIBBPF_A) + +.PHONY: libbpf_hdrs + +$(LIBBPF_OUT): + $(call msg,MKDIR,$@) + $(Q)mkdir -p $@ userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \ - -I $(srctree)/tools/lib/ -Wno-unused-result + -I $(LIBBPF_INCLUDE) -Wno-unused-result userprogs := bpf_preload_umd clean-files := $(userprogs) bpf_helper_defs.h FEATURE-DUMP.libbpf staticobjs/ feature/ +clean-files += $(LIBBPF_OUT) $(LIBBPF_DESTDIR) + +$(obj)/iterators/iterators.o: libbpf_hdrs bpf_preload_umd-objs := iterators/iterators.o bpf_preload_umd-userldlibs := $(LIBBPF_A) -lelf -lz
API headers from libbpf should not be accessed directly from the library's source directory. Instead, they should be exported with "make install_headers". Let's make sure that bpf/preload/Makefile installs the headers properly when building. Note that we declare an additional dependency for iterators/iterators.o: having $(LIBBPF_A) as a dependency to "$(obj)/bpf_preload_umd" is not sufficient, as it makes it required only at the linking step. But we need libbpf to be compiled, and in particular its headers to be exported, before we attempt to compile iterators.o. The issue would not occur before this commit, because libbpf's headers were not exported and were always available under tools/lib/bpf. Signed-off-by: Quentin Monnet <quentin@isovalent.com> --- kernel/bpf/preload/Makefile | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)