Merge branch 'selftests-bpf-use-pkg-config-to-determine-ld-flags'
Akihiko Odaki says:
====================
selftests/bpf: Use pkg-config to determine ld flags
When linking statically, libraries may require other dependencies to be
included to ld flags. In particular, libelf may require libzstd. Use
pkg-config to determine such dependencies.
V4 -> V5: Introduced variables LIBELF_CFLAGS and LIBELF_LIBS.
(Daniel Borkmann)
Added patch "selftests/bpf: Choose pkg-config for the target".
V3 -> V4: Added "2> /dev/null".
V2 -> V3: Added missing "echo".
V1 -> V2: Implemented fallback, referring to HOSTPKG_CONFIG.
====================
Link: https://lore.kernel.org/r/20231125084253.85025-1-akihiko.odaki@daynix.com
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
This commit is contained in:
@@ -18,7 +18,7 @@ else
|
||||
GENDIR := $(abspath ../../../../include/generated)
|
||||
endif
|
||||
GENHDR := $(GENDIR)/autoconf.h
|
||||
HOSTPKG_CONFIG := pkg-config
|
||||
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
|
||||
|
||||
ifneq ($(wildcard $(GENHDR)),)
|
||||
GENFLAGS := -DHAVE_GENHDR
|
||||
@@ -29,13 +29,17 @@ SAN_CFLAGS ?=
|
||||
SAN_LDFLAGS ?= $(SAN_CFLAGS)
|
||||
RELEASE ?=
|
||||
OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0)
|
||||
|
||||
LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null)
|
||||
LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
|
||||
|
||||
CFLAGS += -g $(OPT_FLAGS) -rdynamic \
|
||||
-Wall -Werror \
|
||||
$(GENFLAGS) $(SAN_CFLAGS) \
|
||||
$(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
|
||||
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
|
||||
-I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
|
||||
LDFLAGS += $(SAN_LDFLAGS)
|
||||
LDLIBS += -lelf -lz -lrt -lpthread
|
||||
LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
|
||||
|
||||
ifneq ($(LLVM),)
|
||||
# Silence some warnings when compiled with clang
|
||||
@@ -219,9 +223,9 @@ $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_r
|
||||
|
||||
$(OUTPUT)/sign-file: ../../../../scripts/sign-file.c
|
||||
$(call msg,SIGN-FILE,,$@)
|
||||
$(Q)$(CC) $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) \
|
||||
$(Q)$(CC) $(shell $(PKG_CONFIG) --cflags libcrypto 2> /dev/null) \
|
||||
$< -o $@ \
|
||||
$(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
|
||||
$(shell $(PKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
|
||||
|
||||
$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
|
||||
$(call msg,MOD,,$@)
|
||||
|
||||
@@ -77,7 +77,7 @@ In case of linker errors when running selftests, try using static linking:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ LDLIBS=-static vmtest.sh
|
||||
$ LDLIBS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
|
||||
|
||||
.. note:: Some distros may not support static linking.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user