Subject: Re: [bpf-next,v3,11/13] tools: bpf: make use of reallocarray

From: Jakub Kicinski <[email-masked]>
Date: Fri, 13 Jul 2018 17:07:58 -0700

On Fri, 13 Jul 2018 16:53:05 -0700, Guenter Roeck wrote:
> Hi,
> 
> On Tue, Jul 10, 2018 at 02:43:05PM -0700, Jakub Kicinski wrote:
> > reallocarray() is a safer variant of realloc which checks for
> > multiplication overflow in case of array allocation.  Since it's
> > not available in Glibc < 2.26 import kernel's overflow.h and
> > add a static inline implementation when needed.  Use feature
> > detection to probe for existence of reallocarray.
> >   
> 
> This probe doesn't work on my system (Ubuntu 16.04).
> 
> libbpf.c: In function ‘bpf_object__add_program’:
> libbpf.c:326:10: error: implicit declaration of function ‘reallocarray’

No way :( :(  Maybe you have to clean the build directory hard?  
Maybe you have old feature check results or some such?

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial
# rm -rf /tmp/bpftool
# mkdir /tmp/bpftool
# make -C tools/bpf/bpftool/ O=/tmp/bpftool
make: Entering directory '/tmp/linux/tools/bpf/bpftool'

Auto-detecting system features:
...                        libbfd: [ OFF ]
...        disassembler-four-args: [ OFF ]

  CC       /tmp/bpftool/map_perf_ring.o
  CC       /tmp/bpftool/xlated_dumper.o
  CC       /tmp/bpftool/perf.o
  CC       /tmp/bpftool/prog.o
  CC       /tmp/bpftool/common.o
  CC       /tmp/bpftool/cgroup.o
  CC       /tmp/bpftool/main.o
  CC       /tmp/bpftool/json_writer.o
  CC       /tmp/bpftool/cfg.o
  CC       /tmp/bpftool/map.o
  CC       /tmp/bpftool/jit_disasm.o
  CC       /tmp/bpftool/disasm.o
make[1]: Entering directory '/tmp/linux/tools/lib/bpf'

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

Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
  CC       /tmp/bpftool/libbpf.o
  CC       /tmp/bpftool/bpf.o
  CC       /tmp/bpftool/nlattr.o
  CC       /tmp/bpftool/btf.o
  CC       /tmp/bpftool/libbpf_errno.o
  LD       /tmp/bpftool/libbpf-in.o
  LINK     /tmp/bpftool/libbpf.a
make[1]: Leaving directory '/tmp/linux/tools/lib/bpf'
  LINK     /tmp/bpftool/bpftool
make: Leaving directory '/tmp/linux/tools/bpf/bpftool'