* [PATCH bpf-next v5 1/3] selftests/bpf: Choose pkg-config for the target
2023-11-25 8:42 [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags Akihiko Odaki
@ 2023-11-25 8:42 ` Akihiko Odaki
2023-11-25 8:42 ` [PATCH bpf-next v5 2/3] selftests/bpf: Override PKG_CONFIG for static builds Akihiko Odaki
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Akihiko Odaki @ 2023-11-25 8:42 UTC (permalink / raw)
Cc: Andrii Nakryiko, Mykola Lysenko, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan, Nick Terrell, bpf, linux-kselftest, linux-kernel,
Akihiko Odaki
pkg-config is used to build sign-file executable. It should use the
library for the target instead of the host as it is called during tests.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
tools/testing/selftests/bpf/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 9c27b67bc7b1..94825ef813d5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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
@@ -219,9 +219,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,,$@)
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH bpf-next v5 2/3] selftests/bpf: Override PKG_CONFIG for static builds
2023-11-25 8:42 [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags Akihiko Odaki
2023-11-25 8:42 ` [PATCH bpf-next v5 1/3] selftests/bpf: Choose pkg-config for the target Akihiko Odaki
@ 2023-11-25 8:42 ` Akihiko Odaki
2023-11-25 8:42 ` [PATCH bpf-next v5 3/3] selftests/bpf: Use pkg-config for libelf Akihiko Odaki
2023-11-29 6:20 ` [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Akihiko Odaki @ 2023-11-25 8:42 UTC (permalink / raw)
Cc: Andrii Nakryiko, Mykola Lysenko, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan, Nick Terrell, bpf, linux-kselftest, linux-kernel,
Akihiko Odaki
A library may need to depend on additional archive files for static
builds so pkg-config should be instructed to list them.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
tools/testing/selftests/bpf/README.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/README.rst b/tools/testing/selftests/bpf/README.rst
index cb9b95702ac6..9af79c7a9b58 100644
--- a/tools/testing/selftests/bpf/README.rst
+++ b/tools/testing/selftests/bpf/README.rst
@@ -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.
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next v5 3/3] selftests/bpf: Use pkg-config for libelf
2023-11-25 8:42 [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags Akihiko Odaki
2023-11-25 8:42 ` [PATCH bpf-next v5 1/3] selftests/bpf: Choose pkg-config for the target Akihiko Odaki
2023-11-25 8:42 ` [PATCH bpf-next v5 2/3] selftests/bpf: Override PKG_CONFIG for static builds Akihiko Odaki
@ 2023-11-25 8:42 ` Akihiko Odaki
2023-11-29 6:20 ` [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Akihiko Odaki @ 2023-11-25 8:42 UTC (permalink / raw)
Cc: Andrii Nakryiko, Mykola Lysenko, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan, Nick Terrell, bpf, linux-kselftest, linux-kernel,
Akihiko Odaki
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.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
tools/testing/selftests/bpf/Makefile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 94825ef813d5..617ae55c3bb5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags
2023-11-25 8:42 [PATCH bpf-next v5 0/3] selftests/bpf: Use pkg-config to determine ld flags Akihiko Odaki
` (2 preceding siblings ...)
2023-11-25 8:42 ` [PATCH bpf-next v5 3/3] selftests/bpf: Use pkg-config for libelf Akihiko Odaki
@ 2023-11-29 6:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-29 6:20 UTC (permalink / raw)
To: Akihiko Odaki
Cc: andrii, mykolal, ast, daniel, martin.lau, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, terrelln, bpf,
linux-kselftest, linux-kernel
Hello:
This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Sat, 25 Nov 2023 17:42:49 +0900 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [bpf-next,v5,1/3] selftests/bpf: Choose pkg-config for the target
https://git.kernel.org/bpf/bpf-next/c/2ce344b68916
- [bpf-next,v5,2/3] selftests/bpf: Override PKG_CONFIG for static builds
https://git.kernel.org/bpf/bpf-next/c/18f6f9de98d1
- [bpf-next,v5,3/3] selftests/bpf: Use pkg-config for libelf
https://git.kernel.org/bpf/bpf-next/c/8998a479fd96
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread