From 7d861e12637892f1fcf7bbd69e4aec5a096f4bcb Mon Sep 17 00:00:00 2001 From: Julia Kartseva Date: Fri, 13 Nov 2020 17:08:15 -0800 Subject: [PATCH] meson, bpf: add HAVE_LIBBPF, BPF_FRAMEWORK options * Add `bpf-framework` feature gate with 'auto', 'true' and 'false' choices * Add libbpf [0] dependency * Search for clang llvm-strip and bpftool binaries in compile time to generate bpf skeleton. For libbpf [0], make 0.2.0 [1] the minimum required version. If libbpf is satisfied, set HAVE_LIBBPF config option to 1. If `bpf-framework` feature gate is set to 'auto', means that whether bpf feature is enabled or now is defined by the presence of all of libbpf, clang, llvm and bpftool in build environment. With 'auto' all dependencies are optional. If the gate is set to `true`, make all of the libbpf, clang and llvm dependencies mandatory. If it's set to `false`, set `BPF_FRAMEWORK` to false and make libbpf dependency optional. libbpf dependency is dynamic followed by the common pattern in systemd. meson, bpf: add build rule for socket_bind program --- meson.build | 23 +++++++++++++++++++++++ meson_options.txt | 3 +++ 2 files changed, 26 insertions(+) diff --git a/meson.build b/meson.build index 81db2d27ab..93d3c26a22 100644 --- a/meson.build +++ b/meson.build @@ -937,6 +937,25 @@ if not libcap.found() libcap = cc.find_library('cap') endif +want_bpf_framework = get_option('bpf-framework') +bpf_framework_required = want_bpf_framework == 'true' + +libbpf = dependency('libbpf', required : bpf_framework_required, version : '>= 0.2') +conf.set10('HAVE_LIBBPF', libbpf.found()) + +if want_bpf_framework == 'false' + conf.set10('BPF_FRAMEWORK', 0) +else + clang = find_program('clang', required : bpf_framework_required) + llvm_strip = find_program('llvm-strip', required : bpf_framework_required) + bpftool = find_program('bpftool', required : bpf_framework_required) + bpf_arches = ['x86_64'] + deps_found = libbpf.found() and clang.found() and llvm_strip.found() and bpftool.found() + # Can build BPF program from source code in restricted C + conf.set10('BPF_FRAMEWORK', + bpf_arches.contains(host_machine.cpu_family()) and deps_found) +endif + libmount = dependency('mount', version : fuzzer_build ? '>= 0' : '>= 2.30') @@ -1604,6 +1623,7 @@ conf.set10('ENABLE_EFI', have) ############################################################ +build_bpf_skel_py = find_program('tools/build-bpf-skel.py') generate_gperfs = find_program('tools/generate-gperfs.py') make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py') make_directive_index_py = find_program('tools/make-directive-index.py') @@ -1696,6 +1716,7 @@ install_libsystemd_static = static_library( libxz, libzstd, liblz4, + libbpf, libcap, libblkid, libmount, @@ -3766,6 +3787,7 @@ foreach tuple : [ ['elfutils'], ['gcrypt'], ['gnutls'], + ['libbpf'], ['libcryptsetup'], ['libcurl'], ['libfdisk'], @@ -3792,6 +3814,7 @@ foreach tuple : [ # components ['backlight'], ['binfmt'], + ['bpf-framework', conf.get('BPF_FRAMEWORK') == 1], ['coredump'], ['environment.d'], ['efi'], diff --git a/meson_options.txt b/meson_options.txt index 9441b88dec..ad7174cf69 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -403,3 +403,6 @@ option('kernel-install', type: 'boolean', value: 'true', description : 'install kernel-install and associated files') option('analyze', type: 'boolean', value: 'true', description : 'install systemd-analyze') + +option('bpf-framework', type : 'combo', choices : ['auto', 'true', 'false'], + description: 'build BPF programs from source code in restricted C')