Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Add feature test for libelf with ZSTD

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.

Reviewed-by: Quentin Monnet <qmo@kernel.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Quentin Monnet <qmo@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Guilherme Amadio <amadio@gentoo.org>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Song Liu <song@kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20241215221223.293205-2-leo.yan@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
d557814c ea3683fd

+18
+1
tools/build/Makefile.feature
··· 77 77 libelf-getphdrnum \ 78 78 libelf-gelf_getnote \ 79 79 libelf-getshdrstrndx \ 80 + libelf-zstd \ 80 81 libnuma \ 81 82 numa_num_possible_cpus \ 82 83 libperl \
+4
tools/build/feature/Makefile
··· 28 28 test-libelf-getphdrnum.bin \ 29 29 test-libelf-gelf_getnote.bin \ 30 30 test-libelf-getshdrstrndx.bin \ 31 + test-libelf-zstd.bin \ 31 32 test-libdebuginfod.bin \ 32 33 test-libnuma.bin \ 33 34 test-numa_num_possible_cpus.bin \ ··· 196 195 197 196 $(OUTPUT)test-libelf-getshdrstrndx.bin: 198 197 $(BUILD) -lelf 198 + 199 + $(OUTPUT)test-libelf-zstd.bin: 200 + $(BUILD) -lelf -lz -lzstd 199 201 200 202 $(OUTPUT)test-libdebuginfod.bin: 201 203 $(BUILD) -ldebuginfod
+4
tools/build/feature/test-all.c
··· 58 58 # include "test-libelf-getshdrstrndx.c" 59 59 #undef main 60 60 61 + #define main main_test_libelf_zstd 62 + # include "test-libelf-zstd.c" 63 + #undef main 64 + 61 65 #define main main_test_libslang 62 66 # include "test-libslang.c" 63 67 #undef main
+9
tools/build/feature/test-libelf-zstd.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <stddef.h> 3 + #include <libelf.h> 4 + 5 + int main(void) 6 + { 7 + elf_compress(NULL, ELFCOMPRESS_ZSTD, 0); 8 + return 0; 9 + }