diff mbox series

[bpf-next] selftests/bpf: Use pkg-config to determine ld flags

Message ID 20231015133916.257197-1-akihiko.odaki@daynix.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Use pkg-config to determine ld flags | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
bpf/vmtest-bpf-next-PR success PR summary
netdev/cc_maintainers success CCed 16 of 16 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-7 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for build for s390x with gcc

Commit Message

Akihiko Odaki Oct. 15, 2023, 1:39 p.m. UTC
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   | 3 ++-
 tools/testing/selftests/bpf/README.rst | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Daniel Borkmann Oct. 16, 2023, 11:39 a.m. UTC | #1
On 10/15/23 3:39 PM, Akihiko Odaki 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.

Is this not covered via -lz or is it that the name differs?

Anyway, this change breaks selftest build for BPF CI (see below), could this
either be made optional or detected differently?

https://github.com/kernel-patches/bpf/actions/runs/6524480596/job/17716170021

[...]
   make: pkg-config: Command not found
     CC       bench.o
   make: pkg-config: Command not found
   make: pkg-config: Command not found
     CC       bench_count.o
   make: pkg-config: Command not found
     BINARY   xdp_redirect_multi
     HOSTLD  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/fixdep-in.o
     LINK    /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/fixdep
     CC       veristat.o
     INSTALL /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd//include/subcmd/exec-cmd.h
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/exec-cmd.o
   make: pkg-config: Command not found
     INSTALL /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd//include/subcmd/help.h
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/help.o
     INSTALL /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd//include/subcmd/pager.h
   make: pkg-config: Command not found
     BINARY   test_verifier
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/pager.o
     BINARY   test_tag
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/parse-options.o
   make: pkg-config: Command not found
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/run-command.o
     INSTALL /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd//include/subcmd/parse-options.h
   make: pkg-config: Command not found
     INSTALL /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd//include/subcmd/run-command.h
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/sigchain.o
     BINARY   flow_dissector_load
     CC      /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/build/resolve_btfids/libsubcmd/subcmd-config.o
   make: pkg-config: Command not found
     BINARY   test_lirc_mode2_user
     INSTALL libsubcmd_headers
     BINARY   xdping
   make: pkg-config: Command not found

>   tools/testing/selftests/bpf/Makefile   | 3 ++-
>   tools/testing/selftests/bpf/README.rst | 2 +-
>   2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index caede9b574cb..833134aa2eda 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -4,6 +4,7 @@ include ../../../scripts/Makefile.arch
>   include ../../../scripts/Makefile.include
>   
>   CXX ?= $(CROSS_COMPILE)g++
> +PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
>   
>   CURDIR := $(abspath .)
>   TOOLSDIR := $(abspath ../../..)
> @@ -31,7 +32,7 @@ CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_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 += $(shell $(PKG_CONFIG) --libs libelf zlib) -lrt -lpthread
>   
>   ifneq ($(LLVM),)
>   # Silence some warnings when compiled with clang
> 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.
>   
>
Akihiko Odaki Oct. 16, 2023, 11:57 a.m. UTC | #2
On 2023/10/16 20:39, Daniel Borkmann wrote:
> On 10/15/23 3:39 PM, Akihiko Odaki 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.
> 
> Is this not covered via -lz or is it that the name differs?

libelf may not only be linked with zlib but also with zstandard.

> 
> Anyway, this change breaks selftest build for BPF CI (see below), could 
> this
> either be made optional or detected differently?
> 
> https://github.com/kernel-patches/bpf/actions/runs/6524480596/job/17716170021

I sent v2 (I forgot to add bpf-next to the subject for this).
This version implements a fallback just in the same way done for 
HOSTPKG_CONFIG.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index caede9b574cb..833134aa2eda 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -4,6 +4,7 @@  include ../../../scripts/Makefile.arch
 include ../../../scripts/Makefile.include
 
 CXX ?= $(CROSS_COMPILE)g++
+PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
 
 CURDIR := $(abspath .)
 TOOLSDIR := $(abspath ../../..)
@@ -31,7 +32,7 @@  CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_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 += $(shell $(PKG_CONFIG) --libs libelf zlib) -lrt -lpthread
 
 ifneq ($(LLVM),)
 # Silence some warnings when compiled with clang
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.