mbox series

[bpf-next,v2,0/5] samples: bpf: fix build after move to full libbpf

Message ID 20180515053506.4345-1-jakub.kicinski@netronome.com
Headers show
Series samples: bpf: fix build after move to full libbpf | expand

Message

Jakub Kicinski May 15, 2018, 5:35 a.m. UTC
Hi!

Following patches address build issues after recent move to libbpf.
For out-of-tree builds we would see the following error:

gcc: error: samples/bpf/../../tools/lib/bpf/libbpf.a: No such file or directory

libbpf build system is now always invoked explicitly rather than
relying on building single objects most of the time.  We need to
resolve the friction between Kbuild and tools/ build system.

Mini-library called libbpf.h in samples is renamed to bpf_insn.h,
using linux/filter.h seems not completely trivial since some samples
get upset when order on include search path in changed.  We do have
to rename libbpf.h, however, because otherwise it's hard to reliably
get to libbpf's header in out-of-tree builds.

v2:
 - fix the build error harder (patch 3);
 - add patch 5 (make clang less noisy).

Jakub Kicinski (5):
  samples: bpf: include bpf/bpf.h instead of local libbpf.h
  samples: bpf: rename libbpf.h to bpf_insn.h
  samples: bpf: fix build after move to compiling full libbpf.a
  samples: bpf: move libbpf from object dependencies to libs
  samples: bpf: make the build less noisy

 samples/bpf/Makefile                          | 165 +++++++-----------
 samples/bpf/{libbpf.h => bpf_insn.h}          |   8 +-
 samples/bpf/bpf_load.c                        |   2 +-
 samples/bpf/bpf_load.h                        |   2 +-
 samples/bpf/cookie_uid_helper_example.c       |   2 +-
 samples/bpf/cpustat_user.c                    |   2 +-
 samples/bpf/fds_example.c                     |   4 +-
 samples/bpf/lathist_user.c                    |   2 +-
 samples/bpf/load_sock_ops.c                   |   2 +-
 samples/bpf/lwt_len_hist_user.c               |   2 +-
 samples/bpf/map_perf_test_user.c              |   2 +-
 samples/bpf/sock_example.c                    |   3 +-
 samples/bpf/sock_example.h                    |   1 -
 samples/bpf/sockex1_user.c                    |   2 +-
 samples/bpf/sockex2_user.c                    |   2 +-
 samples/bpf/sockex3_user.c                    |   2 +-
 samples/bpf/syscall_tp_user.c                 |   2 +-
 samples/bpf/tc_l2_redirect_user.c             |   2 +-
 samples/bpf/test_cgrp2_array_pin.c            |   2 +-
 samples/bpf/test_cgrp2_attach.c               |   3 +-
 samples/bpf/test_cgrp2_attach2.c              |   3 +-
 samples/bpf/test_cgrp2_sock.c                 |   3 +-
 samples/bpf/test_cgrp2_sock2.c                |   3 +-
 .../bpf/test_current_task_under_cgroup_user.c |   2 +-
 samples/bpf/test_lru_dist.c                   |   2 +-
 samples/bpf/test_map_in_map_user.c            |   2 +-
 samples/bpf/test_overhead_user.c              |   2 +-
 samples/bpf/test_probe_write_user_user.c      |   2 +-
 samples/bpf/trace_output_user.c               |   2 +-
 samples/bpf/tracex1_user.c                    |   2 +-
 samples/bpf/tracex2_user.c                    |   2 +-
 samples/bpf/tracex3_user.c                    |   2 +-
 samples/bpf/tracex4_user.c                    |   2 +-
 samples/bpf/tracex5_user.c                    |   2 +-
 samples/bpf/tracex6_user.c                    |   2 +-
 samples/bpf/tracex7_user.c                    |   2 +-
 samples/bpf/xdp_fwd_user.c                    |   2 +-
 samples/bpf/xdp_monitor_user.c                |   2 +-
 samples/bpf/xdp_redirect_cpu_user.c           |   2 +-
 samples/bpf/xdp_redirect_map_user.c           |   2 +-
 samples/bpf/xdp_redirect_user.c               |   2 +-
 samples/bpf/xdp_router_ipv4_user.c            |   2 +-
 samples/bpf/xdp_tx_iptunnel_user.c            |   2 +-
 samples/bpf/xdpsock_user.c                    |   2 +-
 44 files changed, 116 insertions(+), 147 deletions(-)
 rename samples/bpf/{libbpf.h => bpf_insn.h} (98%)

Comments

Alexei Starovoitov May 15, 2018, 5:57 a.m. UTC | #1
On Mon, May 14, 2018 at 10:35:01PM -0700, Jakub Kicinski wrote:
> Hi!
> 
> Following patches address build issues after recent move to libbpf.
> For out-of-tree builds we would see the following error:
> 
> gcc: error: samples/bpf/../../tools/lib/bpf/libbpf.a: No such file or directory
> 
> libbpf build system is now always invoked explicitly rather than
> relying on building single objects most of the time.  We need to
> resolve the friction between Kbuild and tools/ build system.
> 
> Mini-library called libbpf.h in samples is renamed to bpf_insn.h,
> using linux/filter.h seems not completely trivial since some samples
> get upset when order on include search path in changed.  We do have
> to rename libbpf.h, however, because otherwise it's hard to reliably
> get to libbpf's header in out-of-tree builds.
> 
> v2:
>  - fix the build error harder (patch 3);
>  - add patch 5 (make clang less noisy).

Applied, Thanks
Jesper Dangaard Brouer May 15, 2018, 6:10 a.m. UTC | #2
On Mon, 14 May 2018 22:57:53 -0700
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> On Mon, May 14, 2018 at 10:35:01PM -0700, Jakub Kicinski wrote:
> > Hi!
> > 
> > Following patches address build issues after recent move to libbpf.
> > For out-of-tree builds we would see the following error:
> > 
> > gcc: error: samples/bpf/../../tools/lib/bpf/libbpf.a: No such file or directory
> > 
> > libbpf build system is now always invoked explicitly rather than
> > relying on building single objects most of the time.  We need to
> > resolve the friction between Kbuild and tools/ build system.
> > 
> > Mini-library called libbpf.h in samples is renamed to bpf_insn.h,
> > using linux/filter.h seems not completely trivial since some samples
> > get upset when order on include search path in changed.  We do have
> > to rename libbpf.h, however, because otherwise it's hard to reliably
> > get to libbpf's header in out-of-tree builds.
> > 
> > v2:
> >  - fix the build error harder (patch 3);
> >  - add patch 5 (make clang less noisy).  
> 
> Applied, Thanks

I just tried it out, but the build fails.

$ make samples/bpf/
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  DESCEND  objtool
  CHK     scripts/mod/devicetable-offsets.h
make -C /home/jbrouer/git/kernel/bpf-next/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/home/jbrouer/git/kernel/bpf-next/samples/bpf/../../ O=

Auto-detecting system features:
...                        libelf: [ OFF ]
...                           bpf: [ OFF ]

No libelf found
make[2]: *** [Makefile:212: elfdep] Error 1
make[1]: *** [samples/bpf/Makefile:207: /home/jbrouer/git/kernel/bpf-next/samples/bpf/../../tools/lib/bpf/libbpf.a] Error 2
make: *** [Makefile:1743: samples/bpf/] Error 2
 

But it might not be related to this change, as the problem seems to the
with the "Auto-detecting system features".  It is the build of libbpf
that is the problem.

$ cd tools/lib/bpf/
$ make

Auto-detecting system features:
...                        libelf: [ OFF ]
...                           bpf: [ OFF ]

No libelf found
make: *** [Makefile:212: elfdep] Error 1


And do have 'libelf' installed on this system... the same build/make
commands works on net-next.

On net-next I see:

$ cd tools/lib/bpf/
$ make

Auto-detecting system features:
...                        libelf: [ on  ]
...                           bpf: [ on  ]

Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
  CC       libbpf.o
  CC       bpf.o
  CC       nlattr.o
  CC       btf.o
  LD       libbpf-in.o
  LINK     libbpf.a
  LINK     libbpf.so
Jesper Dangaard Brouer May 15, 2018, 9:16 a.m. UTC | #3
SOLVED, how see below

On Tue, 15 May 2018 08:10:09 +0200
Jesper Dangaard Brouer <brouer@redhat.com> wrote:

> On Mon, 14 May 2018 22:57:53 -0700
> Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> 
> > On Mon, May 14, 2018 at 10:35:01PM -0700, Jakub Kicinski wrote:  
> > > Hi!
> > > 
> > > Following patches address build issues after recent move to libbpf.
> > > For out-of-tree builds we would see the following error:
> > > 
> > > gcc: error: samples/bpf/../../tools/lib/bpf/libbpf.a: No such file or directory
> > > 
> > > libbpf build system is now always invoked explicitly rather than
> > > relying on building single objects most of the time.  We need to
> > > resolve the friction between Kbuild and tools/ build system.
> > > 
> > > Mini-library called libbpf.h in samples is renamed to bpf_insn.h,
> > > using linux/filter.h seems not completely trivial since some samples
> > > get upset when order on include search path in changed.  We do have
> > > to rename libbpf.h, however, because otherwise it's hard to reliably
> > > get to libbpf's header in out-of-tree builds.
> > > 
> > > v2:
> > >  - fix the build error harder (patch 3);
> > >  - add patch 5 (make clang less noisy).    
> > 
> > Applied, Thanks  
> 
> I just tried it out, but the build fails.
> 
> $ make samples/bpf/
>   CHK     include/config/kernel.release
>   CHK     include/generated/uapi/linux/version.h
>   CHK     include/generated/utsrelease.h
>   CHK     include/generated/bounds.h
>   CHK     include/generated/timeconst.h
>   CHK     include/generated/asm-offsets.h
>   CALL    scripts/checksyscalls.sh
>   DESCEND  objtool
>   CHK     scripts/mod/devicetable-offsets.h
> make -C /home/jbrouer/git/kernel/bpf-next/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/home/jbrouer/git/kernel/bpf-next/samples/bpf/../../ O=
> 
> Auto-detecting system features:
> ...                        libelf: [ OFF ]
> ...                           bpf: [ OFF ]
> 
> No libelf found
> make[2]: *** [Makefile:212: elfdep] Error 1
> make[1]: *** [samples/bpf/Makefile:207: /home/jbrouer/git/kernel/bpf-next/samples/bpf/../../tools/lib/bpf/libbpf.a] Error 2
> make: *** [Makefile:1743: samples/bpf/] Error 2
>  
> 
> But it might not be related to this change, as the problem seems to the
> with the "Auto-detecting system features".  It is the build of libbpf
> that is the problem.
> 
> $ cd tools/lib/bpf/
> $ make
> 
> Auto-detecting system features:
> ...                        libelf: [ OFF ]
> ...                           bpf: [ OFF ]
> 
> No libelf found
> make: *** [Makefile:212: elfdep] Error 1
> 
> 
> And do have 'libelf' installed on this system... the same build/make
> commands works on net-next.
> 
> On net-next I see:
> 
> $ cd tools/lib/bpf/
> $ make
> 
> Auto-detecting system features:
> ...                        libelf: [ on  ]
> ...                           bpf: [ on  ]
> 
> Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
> Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
>   CC       libbpf.o
>   CC       bpf.o
>   CC       nlattr.o
>   CC       btf.o
>   LD       libbpf-in.o
>   LINK     libbpf.a
>   LINK     libbpf.so

SOLVED

It seems that the "Auto-detecting system" needed a 'make clean'.
My problem goes away when I did the following:

$ cd tools/
$ make clean

$ cd lib/bpf/
$ make

Auto-detecting system features:
...                        libelf: [ on  ]
...                           bpf: [ on  ]

  HOSTCC   fixdep.o
  HOSTLD   fixdep-in.o
  LINK     fixdep
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
  CC       libbpf.o
  CC       bpf.o
  CC       nlattr.o
  CC       btf.o
  LD       libbpf-in.o
  LINK     libbpf.a
  LINK     libbpf.so
Jakub Kicinski May 15, 2018, 5:46 p.m. UTC | #4
On Tue, 15 May 2018 11:16:43 +0200, Jesper Dangaard Brouer wrote:
> > $ cd tools/lib/bpf/
> > $ make
> > 
> > Auto-detecting system features:
> > ...                        libelf: [ on  ]
> > ...                           bpf: [ on  ]
> > 
> > Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
> > Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
> >   CC       libbpf.o
> >   CC       bpf.o
> >   CC       nlattr.o
> >   CC       btf.o
> >   LD       libbpf-in.o
> >   LINK     libbpf.a
> >   LINK     libbpf.so  
> 
> SOLVED
> 
> It seems that the "Auto-detecting system" needed a 'make clean'.
> My problem goes away when I did the following:
> 
> $ cd tools/
> $ make clean
> 
> $ cd lib/bpf/
> $ make
> 
> Auto-detecting system features:
> ...                        libelf: [ on  ]
> ...                           bpf: [ on  ]

Interesting!  I've seen the same thing (on Fedora, not sure distro is
relevant).  I tracked it down to dependency files (*.d) in
tools/build/features/ containing a reference to a sigset.h header which
didn't exist :S  I did git clean -xdf to fix my tree.

Thanks for testing and sorry about the breakage!