Skip to content

Commit 3b812c2

Browse files
committed
mirror: Add probe for libelf-zstd feature
Add the probe to test whether we need to link against the zstd library to use libelf in bpftool. This should ideally have been merged before commit 67f1758 ("bpftool: Link zstd lib required by libelf"), where we have the Makefile use the actual feature, but I forgot to add the probe when synchronising the repository. Elfutils commit a5b07cdf9c49 adds support for ZSTD compression, first shipped with elfutils 0.189. Distros now have it; for example, Ubuntu 22.04 ships version 0.186 (or 0.188 in backports), but Ubuntu 24.04 has 0.189 or 0.190 depending on the arch. Link: https://sourceware.org/git/?p=elfutils.git;a=commit;h=a5b07cdf9c491fb7a4a16598c482c68b718f59b9 Signed-off-by: Quentin Monnet <[email protected]>
1 parent 368a1a5 commit 3b812c2

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/Makefile.feature

+35-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,41 @@ feature-clang-bpf-co-re := \
3434
$(findstring 1,$(call detect,$(CLANG_BPF_CO_RE_PROBE_CMD)))
3535
endif # clang-bpf-co-re
3636

37+
### feature-libelf-zstd
38+
39+
# Define these unconditionally so we can also use the probe for feature-libbfd
40+
LIBELF_ZSTD_PROBE := '$(pound)include <libelf.h>\n'
41+
LIBELF_ZSTD_PROBE += 'int main(void) {'
42+
LIBELF_ZSTD_PROBE += ' elf_compress(0, ELFCOMPRESS_ZSTD, 0);'
43+
LIBELF_ZSTD_PROBE += ' return 0;'
44+
LIBELF_ZSTD_PROBE += '}'
45+
46+
LIBELF_ZSTD_PROBE_CMD = printf '%b\n' $(LIBELF_ZSTD_PROBE) | \
47+
$(CC) $(CFLAGS) -Wall -Werror -x c - -lelf -lz -lzstd -o - >/dev/null
48+
49+
define libelf_zstd_build
50+
$(call detect,$(LIBELF_ZSTD_PROBE_CMD))
51+
endef
52+
53+
ifneq ($(findstring libelf-zstd,$(FEATURE_TESTS)),)
54+
$(call LOG,Probing: feature-libelf-zstd)
55+
feature-libelf-zstd := $(findstring 1, $(call libelf_zstd_build))
56+
endif # libelf-zstd
57+
3758
### feature-libbfd
3859

3960
ifneq ($(findstring libbfd,$(FEATURE_TESTS)),)
61+
62+
# Check whether feature-libbfd probe needs libzstd
63+
ifneq ($(findstring libelf-zstd,$(FEATURE_TESTS)),)
64+
need_libzstd := $(feature-libelf-zstd)
65+
else
66+
need_libzstd := $(findstring 1, $(call libelf_zstd_build))
67+
endif
68+
ifeq ($(need_libzstd),1)
69+
LIBZSTD_FLAG := -lzstd
70+
endif
71+
4072
LIBBFD_PROBE := '$(pound)include <bfd.h>\n'
4173
LIBBFD_PROBE += 'int main(void) {'
4274
LIBBFD_PROBE += ' bfd_demangle(0, 0, 0);'
@@ -51,15 +83,15 @@ endef
5183

5284
$(call LOG,Probing: feature-libbfd)
5385
feature-libbfd := \
54-
$(findstring 1,$(call libbfd_build,-lbfd -ldl))
86+
$(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl))
5587
ifneq ($(feature-libbfd),1)
5688
$(call LOG,Probing: feature-libbfd-liberty)
5789
feature-libbfd-liberty := \
58-
$(findstring 1,$(call libbfd_build,-lbfd -ldl -liberty))
90+
$(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl -liberty))
5991
ifneq ($(feature-libbfd-liberty),1)
6092
$(call LOG,Probing: feature-libbfd-liberty-z)
6193
feature-libbfd-liberty-z := \
62-
$(findstring 1,$(call libbfd_build,-lbfd -ldl -liberty -lz))
94+
$(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl -liberty -lz))
6395
endif
6496
endif
6597
HAS_LIBBFD := $(findstring 1, \

0 commit comments

Comments
 (0)