* [PATCH v3 0/3] bpftool: Fix the static linkage failure
@ 2024-12-15 22:12 Leo Yan
2024-12-15 22:12 ` [PATCH v3 1/3] tools build: Add feature test for libelf with ZSTD Leo Yan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Leo Yan @ 2024-12-15 22:12 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Quentin Monnet, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Nick Terrell,
Namhyung Kim, Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
Guilherme Amadio, linux-kernel, bpf, linux-perf-users
Cc: Leo Yan
This series follows up on the discussion in [1] for fixing the static
linkage issue in bpftool.
Patch 01 introduces a new feature for libelf-zstd. If this feature
is detected, it means the zstd lib is required by libelf.
Patch 02 is a minor improvement for linking the zstd lib in the perf.
Patch 03 fixes the static build failure by linking the zstd lib when
the feature-libelf-zstd is detected.
[1] https://lore.kernel.org/linux-perf-users/Z1H9-9xrWM4FBbNI@mini-arch/T/#m2300b127424e9e2ace7da497a20d88534eb6866f
Changes from v2:
- Refined commit log in patch 01 for recording info that from which
libelf version it requires to link libzstd. (Quentin)
- Removed to display feature 'libelf-zstd' in bpftool. (Quentin)
- Added Test and Ack tags. Thanks all! (Quentin/Jiri/Namhyung/Andrii)
Leo Yan (3):
tools build: Add feature test for libelf with ZSTD
perf: build: Minor improvement for linking libzstd
bpftool: Link zstd lib required by libelf
tools/bpf/bpftool/Makefile | 7 +++++++
tools/build/Makefile.feature | 1 +
tools/build/feature/Makefile | 4 ++++
tools/build/feature/test-all.c | 4 ++++
tools/build/feature/test-libelf-zstd.c | 9 +++++++++
tools/perf/Makefile.config | 8 +++++++-
6 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 tools/build/feature/test-libelf-zstd.c
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/3] tools build: Add feature test for libelf with ZSTD
2024-12-15 22:12 [PATCH v3 0/3] bpftool: Fix the static linkage failure Leo Yan
@ 2024-12-15 22:12 ` Leo Yan
2024-12-15 22:12 ` [PATCH v3 2/3] perf: build: Minor improvement for linking libzstd Leo Yan
2024-12-15 22:12 ` [PATCH v3 3/3] bpftool: Link zstd lib required by libelf Leo Yan
2 siblings, 0 replies; 7+ messages in thread
From: Leo Yan @ 2024-12-15 22:12 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Quentin Monnet, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Nick Terrell,
Namhyung Kim, Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
Guilherme Amadio, linux-kernel, bpf, linux-perf-users
Cc: Leo Yan
The macro ELFCOMPRESS_ZSTD defines the compress algorithm, which was
introduced in the commit ("libelf: Document and make ELFCOMPRESS_ZSTD
usable with old system elf.h") of the repository elfutils-0.188-67.
Therefore, libelf 0.189 and later versions require to link the libzstd
library.
Add a test for checking if libelf supports ZSTD algorithm. Pass the
macro ELFCOMPRESS_ZSTD as an argument to the elf_compress() function.
If the build succeeds, it means the feature is supported.
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Quentin Monnet <qmo@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/build/Makefile.feature | 1 +
tools/build/feature/Makefile | 4 ++++
tools/build/feature/test-all.c | 4 ++++
tools/build/feature/test-libelf-zstd.c | 9 +++++++++
4 files changed, 18 insertions(+)
create mode 100644 tools/build/feature/test-libelf-zstd.c
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index e25cdb7db40e..ce2f37f62dfc 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -77,6 +77,7 @@ FEATURE_TESTS_BASIC := \
libelf-getphdrnum \
libelf-gelf_getnote \
libelf-getshdrstrndx \
+ libelf-zstd \
libnuma \
numa_num_possible_cpus \
libperl \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index cbf751b6f0f7..680f9b07150f 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -28,6 +28,7 @@ FILES= \
test-libelf-getphdrnum.bin \
test-libelf-gelf_getnote.bin \
test-libelf-getshdrstrndx.bin \
+ test-libelf-zstd.bin \
test-libdebuginfod.bin \
test-libnuma.bin \
test-numa_num_possible_cpus.bin \
@@ -196,6 +197,9 @@ $(OUTPUT)test-libelf-gelf_getnote.bin:
$(OUTPUT)test-libelf-getshdrstrndx.bin:
$(BUILD) -lelf
+$(OUTPUT)test-libelf-zstd.bin:
+ $(BUILD) -lelf -lz -lzstd
+
$(OUTPUT)test-libdebuginfod.bin:
$(BUILD) -ldebuginfod
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index 80ac297f8196..67125f967860 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -58,6 +58,10 @@
# include "test-libelf-getshdrstrndx.c"
#undef main
+#define main main_test_libelf_zstd
+# include "test-libelf-zstd.c"
+#undef main
+
#define main main_test_libslang
# include "test-libslang.c"
#undef main
diff --git a/tools/build/feature/test-libelf-zstd.c b/tools/build/feature/test-libelf-zstd.c
new file mode 100644
index 000000000000..a1324a1db3bb
--- /dev/null
+++ b/tools/build/feature/test-libelf-zstd.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stddef.h>
+#include <libelf.h>
+
+int main(void)
+{
+ elf_compress(NULL, ELFCOMPRESS_ZSTD, 0);
+ return 0;
+}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/3] perf: build: Minor improvement for linking libzstd
2024-12-15 22:12 [PATCH v3 0/3] bpftool: Fix the static linkage failure Leo Yan
2024-12-15 22:12 ` [PATCH v3 1/3] tools build: Add feature test for libelf with ZSTD Leo Yan
@ 2024-12-15 22:12 ` Leo Yan
2024-12-15 22:12 ` [PATCH v3 3/3] bpftool: Link zstd lib required by libelf Leo Yan
2 siblings, 0 replies; 7+ messages in thread
From: Leo Yan @ 2024-12-15 22:12 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Quentin Monnet, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Nick Terrell,
Namhyung Kim, Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
Guilherme Amadio, linux-kernel, bpf, linux-perf-users
Cc: Leo Yan
The zstd library will be automatically linked by detecting the feature
libzstd. It is no need to explicitly link it for static builds, so
remove the redundant linkage.
It is contradictory to detect the feature libelf-zstd while the build
configuration NO_LIBZSTD is set. Report an error for reminding users
not to set NO_LIBZSTD.
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/perf/Makefile.config | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 0e4f6a860ae2..155cb9d20011 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -171,7 +171,7 @@ ifdef LIBDW_DIR
endif
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
- DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd
+ DWARFLIBS += -lelf -lz -llzma -lbz2
LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0
LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
@@ -566,6 +566,12 @@ ifndef NO_LIBELF
CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
endif
+ ifeq ($(feature-libelf-zstd), 1)
+ ifdef NO_LIBZSTD
+ $(error Error: libzstd is required by libelf, please do not set NO_LIBZSTD)
+ endif
+ endif
+
ifndef NO_LIBDEBUGINFOD
$(call feature_check,libdebuginfod)
ifeq ($(feature-libdebuginfod), 1)
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/3] bpftool: Link zstd lib required by libelf
2024-12-15 22:12 [PATCH v3 0/3] bpftool: Fix the static linkage failure Leo Yan
2024-12-15 22:12 ` [PATCH v3 1/3] tools build: Add feature test for libelf with ZSTD Leo Yan
2024-12-15 22:12 ` [PATCH v3 2/3] perf: build: Minor improvement for linking libzstd Leo Yan
@ 2024-12-15 22:12 ` Leo Yan
2024-12-16 11:23 ` Quentin Monnet
2 siblings, 1 reply; 7+ messages in thread
From: Leo Yan @ 2024-12-15 22:12 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Quentin Monnet, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Nick Terrell,
Namhyung Kim, Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
Guilherme Amadio, linux-kernel, bpf, linux-perf-users
Cc: Leo Yan
When the feature libelf-zstd is detected, the zstd lib is required by
libelf. Link the zstd lib in this case.
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/Makefile | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index a4263dfb5e03..dd9f3ec84201 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -106,6 +106,7 @@ FEATURE_TESTS += libbfd-liberty
FEATURE_TESTS += libbfd-liberty-z
FEATURE_TESTS += disassembler-four-args
FEATURE_TESTS += disassembler-init-styled
+FEATURE_TESTS += libelf-zstd
FEATURE_DISPLAY := clang-bpf-co-re
FEATURE_DISPLAY += llvm
@@ -132,6 +133,12 @@ endif
LIBS = $(LIBBPF) -lelf -lz
LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
+
+ifeq ($(feature-libelf-zstd),1)
+LIBS += -lzstd
+LIBS_BOOTSTRAP += -lzstd
+endif
+
ifeq ($(feature-libcap), 1)
CFLAGS += -DUSE_LIBCAP
LIBS += -lcap
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/3] bpftool: Link zstd lib required by libelf
2024-12-15 22:12 ` [PATCH v3 3/3] bpftool: Link zstd lib required by libelf Leo Yan
@ 2024-12-16 11:23 ` Quentin Monnet
2024-12-16 16:30 ` Leo Yan
0 siblings, 1 reply; 7+ messages in thread
From: Quentin Monnet @ 2024-12-16 11:23 UTC (permalink / raw)
To: Leo Yan, Arnaldo Carvalho de Melo, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Nick Terrell,
Namhyung Kim, Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
Guilherme Amadio, linux-kernel, bpf, linux-perf-users
2024-12-15 22:12 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> When the feature libelf-zstd is detected, the zstd lib is required by
> libelf. Link the zstd lib in this case.
>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> Tested-by: Namhyung Kim <namhyung@kernel.org>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Thank you! And thanks for the updated commit description in your first
patch, looks great.
Quentin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/3] bpftool: Link zstd lib required by libelf
2024-12-16 11:23 ` Quentin Monnet
@ 2024-12-16 16:30 ` Leo Yan
2024-12-16 21:06 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 7+ messages in thread
From: Leo Yan @ 2024-12-16 16:30 UTC (permalink / raw)
To: Quentin Monnet
Cc: Arnaldo Carvalho de Melo, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Nick Terrell, Namhyung Kim, Ian Rogers,
Adrian Hunter, Liang, Kan, James Clark, Guilherme Amadio,
linux-kernel, bpf, linux-perf-users
On Mon, Dec 16, 2024 at 11:23:29AM +0000, Quentin Monnet wrote:
>
> 2024-12-15 22:12 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> > When the feature libelf-zstd is detected, the zstd lib is required by
> > libelf. Link the zstd lib in this case.
> >
> > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > Tested-by: Namhyung Kim <namhyung@kernel.org>
> > Acked-by: Andrii Nakryiko <andrii@kernel.org>
>
> Reviewed-by: Quentin Monnet <qmo@kernel.org>
>
> Thank you! And thanks for the updated commit description in your first
> patch, looks great.
Thank you for continuous review, Quentin!
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/3] bpftool: Link zstd lib required by libelf
2024-12-16 16:30 ` Leo Yan
@ 2024-12-16 21:06 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-12-16 21:06 UTC (permalink / raw)
To: Leo Yan
Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Nick Terrell, Namhyung Kim, Ian Rogers,
Adrian Hunter, Liang, Kan, James Clark, Guilherme Amadio,
linux-kernel, bpf, linux-perf-users
On Mon, Dec 16, 2024 at 04:30:33PM +0000, Leo Yan wrote:
> On Mon, Dec 16, 2024 at 11:23:29AM +0000, Quentin Monnet wrote:
> >
> > 2024-12-15 22:12 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> > > When the feature libelf-zstd is detected, the zstd lib is required by
> > > libelf. Link the zstd lib in this case.
> > >
> > > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > > Tested-by: Namhyung Kim <namhyung@kernel.org>
> > > Acked-by: Andrii Nakryiko <andrii@kernel.org>
> >
> > Reviewed-by: Quentin Monnet <qmo@kernel.org>
> >
> > Thank you! And thanks for the updated commit description in your first
> > patch, looks great.
>
> Thank you for continuous review, Quentin!
Applied locally and test building now, please holler if someone thinks
this should be processed somewhere else.
- Arnaldo
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-12-16 21:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-15 22:12 [PATCH v3 0/3] bpftool: Fix the static linkage failure Leo Yan
2024-12-15 22:12 ` [PATCH v3 1/3] tools build: Add feature test for libelf with ZSTD Leo Yan
2024-12-15 22:12 ` [PATCH v3 2/3] perf: build: Minor improvement for linking libzstd Leo Yan
2024-12-15 22:12 ` [PATCH v3 3/3] bpftool: Link zstd lib required by libelf Leo Yan
2024-12-16 11:23 ` Quentin Monnet
2024-12-16 16:30 ` Leo Yan
2024-12-16 21:06 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox