Currently we hardcode "gcc", which means we get a bogus result any time
a non-default CC is passed to Make. In fact, it's bogus even when CC is
not explicitly set, since Make's default is "cc", which isn't
necessarily the same as "gcc".
Fix the issue by passing the compiler to use to check-reallocarray.sh.
Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
zlib is now a direct dependency of libbpf (previously zlib was only dependency
of libelf, on which libbpf depends as well). For non-pkg-config case, specify
`-lz` compiler flag explicitly.
Recent sync also added another public header to libbpf. Include it in a list
of headers that are installed on target system.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
These were added to the kernel repo, but not in Github. However, they are
useful for browsing the source in Github while prototyping new features and
compiling them into userspace utilities.
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Upstream commit 71dd77fd4bf7 ("libbpf: use LFS (_FILE_OFFSET_BITS) instead
of direct mmap2 syscall") added _FILE_OFFSET_BITS=64 and
_LARGEFILE64_SOURCE CFLAGS. Back-port them to Github's mirror to avoid
compilation problems on ARM.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
After latest shared vs static libraries fixes, `make install` target
broke as it relied on now removed $(LIBS) variable. This patch fixes
issue by listing $(SHARED_LIBS) and $(STATIC_LIBS) explicitly.
Tested with and without BUILD_STATIC_ONLY.
Fixes: 8b2782a1f2 ("makefile: support libbpf symbol versioning in shared library mode")
Reported-by: Michal Rostecki <mrostecki@opensuse.org>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Similarly to Linux's 1bd63524593b ("libbpf: handle symbol versioning properly
for libbpf.a"), add necessary changes to build static and shared object
files separately with extra shared library flags. This allows to
properly handle symbol versioning in shared library mode, while still
having statically linkable library.
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
The -lelf flag needs to be specified *after* the object files, otherwise
the output library produced by some compilers doesn't contain a link to
libelf.so:
(Example from Debian testing run on Travis.)
$ ldd libelf.so
linux-vdso.so.1 (0x00007ffcbfda9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f75f8d24000)
/lib64/ld-linux-x86-64.so.2 (0x00007f75f8f0f000)
Linking against such library then produces 'undefined reference to ...'
errors unless the target links against libelf as well. After this commit
the built library references the libelf library correctly:
$ ldd libbpf.so
linux-vdso.so.1 (0x00007ffc821f1000)
libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x00007f70ea3ec000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f70ea22c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f70ea20f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f70ea433000)
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Backport in f49907472f ("sync: latest libbpf changes from kernel")
missed to bump Makefile's EXTRAVERSION to 3.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
LIBBPF_VERSION is already used to generate libbpf.pc file but was not
actuall set.
Set it same way it's done in kernel tree. Version is in sync with
version script for DSO.
Before:
% grep Version src/libbpf.pc
Version:
After:
% grep Version src/libbpf.pc
Version: 0.0.2
Fixes: 93bc1d0 ("makefile: sync generate pkg-config file for libbpf")
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Version script was synced from kernel tree but not enabled in Makefile.
Enable it same way it's done in kernel tree.
% readelf -s --wide src/libbpf.so | grep -Eo '[^ ]+@LIBBPF_.*' | \
cut -d@ -f 3 | sort | uniq -c
121 LIBBPF_0.0.1
29 LIBBPF_0.0.2
Signed-off-by: Andrey Ignatov <rdna@fb.com>
OBJDIR was not specified for libbpf.pc. It works by default since
default value of OBJDIR is current directory, but breaks as soon as
OBJDIR is set to some other directory:
% OBJDIR=build DESTDIR=root make install
...
ar rcs build/libbpf.a build/bpf.o build/btf.o build/libbpf.o
build/libbpf_errno.o build/netlink.o build/nlattr.o build/str_error.o
build/libbpf_probes.o build/bpf_prog_linfo.o build/xsk.o
cc -shared -lelf build/bpf.o build/btf.o build/libbpf.o build/libbpf_errno.o
build/netlink.o build/nlattr.o build/str_error.o build/libbpf_probes.o
build/bpf_prog_linfo.o build/xsk.o -o build/libbpf.so
make: *** No rule to make target `libbpf.pc', needed by `all'. Stop.
Fix it.
Signed-off-by: Andrey Ignatov <rdna@fb.com>
The vast majority of use cases want a shared library, so to be more
user and packager friendly invert the makefile logic and always build
both static and shared libraries by default.
Add BUILD_STATIC_ONLY variable for the corner cases where only a static
library is needed
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
Distro tools like dpkg-buildpackage use the preprocessor flags to pass
important flags, like hardening features. Pass CPPFLAGS to CC.
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
This patch makes sure we build AF_XDP-related code as part of libbpf. This
also required copying few uapi/linux headers and adding few used definitions
in include headers.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
bpf_common.h is hardly ever changed so it was not installed together
with other uapi headers. Some environments are still prefer to be
consistent and install all relevant uapi headers so add bpf_common.h to
uapi headers.
Signed-off-by: Andrey Ignatov <rdna@fb.com>
* Sync from bpf-next
Sync the following commits from bpf-next:
commit ab9e08482122 ("libbpf: Per-symbol visibility for DSO")
commit c034a177d3c8 ("bpf: bpftool, add flag to allow non-compat map definitions")
Signed-off-by: Andrey Ignatov <rdna@fb.com>
* Use -fvisibility=hidden by default for DSO
This is Makefile part of:
commit ab9e08482122 ("libbpf: Per-symbol visibility for DSO")
See original commit for details.
Introduce multiple improvements to Makefile to make the build more
flexible and support install:
* Support overriding CFLAGS by user but keep required flags in place.
ALL_FLAGS is used in Makefile as recommended in [1].
* Add additional BUILD_SHARED flag to build dynamically linked flavor of
the library. If the flag is set, -fPIC is also passed to make it
possible to build .so.
* Support building in a separate directory provided by OBJDIR variable.
* Add multiple install targets. By default the library itself and libbpf
headers are installed (install target). UAPI headers can be optionally
installed by user.
* All installation paths, including PREFIX, library and include
directories can be overridden. UAPI can be made different from include
directory for libbpf headers. That makes it possible to keep latest
<linux/bpf.h> in a place that doesn't conflict with the one installed
e.g. by kernel-headers package and use it in user's build system.
* Support DESTDIR (see [2]).
* Support overriding LDFLAGS.
* Use utilities such as rm directly as recommended in [3].
* Use compiler and related programs (such as ar) via make variables as
recommended in [3].
* In clean rule remove all possible build artifacts not to rely on passed
options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it).
* Document new build options in README.
[1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables
[2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html
[3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles
Signed-off-by: Andrey Ignatov <rdna@fb.com>