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

Configure Feed

Select the types of activity you want to include in your feed.

bpftool: Allow explicitly skip llvm, libbfd and libcrypto dependencies

Introduce SKIP_LLVM, SKIP_LIBBFD, and SKIP_CRYPTO build flags that let
users build bpftool without these optional dependencies.

SKIP_LLVM=1 skips LLVM even when detected. SKIP_LIBBFD=1 prevents the
libbfd JIT disassembly fallback when LLVM is absent. Together, they
produce a bpftool with no disassembly support.

SKIP_CRYPTO=1 excludes sign.c and removes the -lcrypto link dependency.
Inline stubs in main.h return errors with a clear message if signing
functions are called at runtime.

Use BPFTOOL_WITHOUT_CRYPTO (not HAVE_LIBCRYPTO_SUPPORT) as the C
define, following the BPFTOOL_WITHOUT_SKELETONS naming convention for
bpftool-internal build config, leaving HAVE_LIBCRYPTO_SUPPORT free for
proper feature detection in the future.

All three flags are propagated through the selftests Makefile to bpftool
sub-builds.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20260312-b4-bpftool_build-v2-1-4c9d57133644@meta.com

authored by

Mykyta Yatsenko and committed by
Andrii Nakryiko
c73a2443 6c8e1a9e

+55 -4
+26 -4
tools/bpf/bpftool/Makefile
··· 97 97 98 98 FEATURE_USER = .bpftool 99 99 100 + # Skip optional dependencies: LLVM (JIT disasm), libbfd (fallback 101 + # disasm), libcrypto (program signing). 102 + SKIP_LLVM ?= 103 + SKIP_LIBBFD ?= 104 + SKIP_CRYPTO ?= 105 + ifneq ($(SKIP_CRYPTO),1) 106 + CRYPTO_LIBS := -lcrypto 107 + endif 108 + 100 109 FEATURE_TESTS := clang-bpf-co-re 101 110 FEATURE_TESTS += llvm 102 111 FEATURE_TESTS += libcap ··· 139 130 endif 140 131 endif 141 132 142 - LIBS = $(LIBBPF) -lelf -lcrypto -lz 143 - LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lcrypto -lz 133 + LIBS = $(LIBBPF) -lelf $(CRYPTO_LIBS) -lz 134 + LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf $(CRYPTO_LIBS) -lz 144 135 145 136 ifeq ($(feature-libelf-zstd),1) 146 137 LIBS += -lzstd ··· 159 150 SRCS := $(wildcard *.c) 160 151 161 152 ifeq ($(feature-llvm),1) 162 - # If LLVM is available, use it for JIT disassembly 153 + ifneq ($(SKIP_LLVM),1) 154 + HAS_LLVM := 1 155 + endif 156 + endif 157 + 158 + ifeq ($(HAS_LLVM),1) 163 159 CFLAGS += -DHAVE_LLVM_SUPPORT 164 160 LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets 165 161 # llvm-config always adds -D_GNU_SOURCE, however, it may already be in CFLAGS ··· 179 165 endif 180 166 LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags) 181 167 else 168 + ifneq ($(SKIP_LIBBFD),1) 182 169 # Fall back on libbfd 183 170 ifeq ($(feature-libbfd),1) 184 171 LIBS += -lbfd -ldl -lopcodes ··· 201 186 CFLAGS += -DDISASM_INIT_STYLED 202 187 endif 203 188 endif 189 + endif # SKIP_LIBBFD 204 190 endif 205 191 ifeq ($(filter -DHAVE_LLVM_SUPPORT -DHAVE_LIBBFD_SUPPORT,$(CFLAGS)),) 206 192 # No support for JIT disassembly 207 193 SRCS := $(filter-out jit_disasm.c,$(SRCS)) 208 194 endif 209 195 196 + ifeq ($(SKIP_CRYPTO),1) 197 + CFLAGS += -DBPFTOOL_WITHOUT_CRYPTO 198 + HOST_CFLAGS += -DBPFTOOL_WITHOUT_CRYPTO 199 + SRCS := $(filter-out sign.c,$(SRCS)) 200 + endif 201 + 210 202 BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool 211 203 212 - BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o sign.o) 204 + BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o $(if $(CRYPTO_LIBS),sign.o)) 213 205 $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) 214 206 215 207 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
+7
tools/bpf/bpftool/main.c
··· 132 132 #else 133 133 const bool has_skeletons = true; 134 134 #endif 135 + #ifdef BPFTOOL_WITHOUT_CRYPTO 136 + const bool has_crypto = false; 137 + #else 138 + const bool has_crypto = true; 139 + #endif 135 140 bool bootstrap = false; 136 141 int i; 137 142 ··· 168 163 jsonw_start_object(json_wtr); /* features */ 169 164 jsonw_bool_field(json_wtr, "libbfd", has_libbfd); 170 165 jsonw_bool_field(json_wtr, "llvm", has_llvm); 166 + jsonw_bool_field(json_wtr, "crypto", has_crypto); 171 167 jsonw_bool_field(json_wtr, "skeletons", has_skeletons); 172 168 jsonw_bool_field(json_wtr, "bootstrap", bootstrap); 173 169 jsonw_end_object(json_wtr); /* features */ ··· 187 181 printf("features:"); 188 182 print_feature("libbfd", has_libbfd, &nb_features); 189 183 print_feature("llvm", has_llvm, &nb_features); 184 + print_feature("crypto", has_crypto, &nb_features); 190 185 print_feature("skeletons", has_skeletons, &nb_features); 191 186 print_feature("bootstrap", bootstrap, &nb_features); 192 187 printf("\n");
+14
tools/bpf/bpftool/main.h
··· 293 293 int read_kernel_config(const struct kernel_config_option *requested_options, 294 294 size_t num_options, char **out_values, 295 295 const char *define_prefix); 296 + #ifndef BPFTOOL_WITHOUT_CRYPTO 296 297 int bpftool_prog_sign(struct bpf_load_and_run_opts *opts); 297 298 __u32 register_session_key(const char *key_der_path); 299 + #else 300 + static inline int bpftool_prog_sign(struct bpf_load_and_run_opts *opts) 301 + { 302 + p_err("bpftool was built without signing support"); 303 + return -ENOTSUP; 304 + } 305 + 306 + static inline __u32 register_session_key(const char *key_der_path) 307 + { 308 + p_err("bpftool was built without signing support"); 309 + return -1; 310 + } 311 + #endif 298 312 #endif
+8
tools/testing/selftests/bpf/Makefile
··· 41 41 42 42 SKIP_DOCS ?= 43 43 SKIP_LLVM ?= 44 + SKIP_LIBBFD ?= 45 + SKIP_CRYPTO ?= 44 46 45 47 ifeq ($(srctree),) 46 48 srctree := $(patsubst %/,%,$(dir $(CURDIR))) ··· 335 333 OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ 336 334 LIBBPF_OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \ 337 335 LIBBPF_DESTDIR=$(HOST_SCRATCH_DIR)/ \ 336 + SKIP_LLVM=$(SKIP_LLVM) \ 337 + SKIP_LIBBFD=$(SKIP_LIBBFD) \ 338 + SKIP_CRYPTO=$(SKIP_CRYPTO) \ 338 339 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install-bin 339 340 340 341 ifneq ($(CROSS_COMPILE),) ··· 350 345 OUTPUT=$(BUILD_DIR)/bpftool/ \ 351 346 LIBBPF_OUTPUT=$(BUILD_DIR)/libbpf/ \ 352 347 LIBBPF_DESTDIR=$(SCRATCH_DIR)/ \ 348 + SKIP_LLVM=$(SKIP_LLVM) \ 349 + SKIP_LIBBFD=$(SKIP_LIBBFD) \ 350 + SKIP_CRYPTO=$(SKIP_CRYPTO) \ 353 351 prefix= DESTDIR=$(SCRATCH_DIR)/ install-bin 354 352 endif 355 353