From ea78d2fb11cc745874c93fb41ce29c2aa37e6a6c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Jan 2022 22:42:18 +0900 Subject: [PATCH 1/3] meson: require bpftool version >= 5.6 Closes #22051. --- meson.build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 910862ed36..a0ce462f31 100644 --- a/meson.build +++ b/meson.build @@ -1005,7 +1005,11 @@ else # Debian installs this in /usr/sbin/ which is not in $PATH. # We check for 'bpftool' first, honouring $PATH, and in /usr/sbin/ for Debian. - bpftool = find_program('bpftool', '/usr/sbin/bpftool', required : bpf_framework_required) + # We use 'bpftool gen' subcommand, it was added by 985ead416df39d6fe8e89580cc1db6aa273e0175 (v5.6). + bpftool = find_program('bpftool', + '/usr/sbin/bpftool', + required : bpf_framework_required, + version : '>= 5.6') deps_found = libbpf.found() and clang.found() and llvm_strip.found() and bpftool.found() # Can build BPF program from source code in restricted C From a6ac8b5a4da379d959bfccba255db65b0da0c821 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 13 Jan 2022 15:33:46 +0900 Subject: [PATCH 2/3] meson: check if clang supports bpf --- meson.build | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a0ce462f31..073667ef6c 100644 --- a/meson.build +++ b/meson.build @@ -995,6 +995,14 @@ else clang_bin = 'clang' endif clang = find_program(clang_bin, required : bpf_framework_required) + + if clang.found() + # Check if 'clang -target bpf' is supported. + clang_supports_bpf = run_command(clang, '-target', 'bpf', '--print-supported-cpus', check : false).returncode() == 0 + else + clang_supports_bpf = false + endif + if not meson.is_cross_build() and clang.found() llvm_strip_bin = run_command(clang, '--print-prog-name', 'llvm-strip', check : true).stdout().strip() @@ -1011,7 +1019,7 @@ else required : bpf_framework_required, version : '>= 5.6') - deps_found = libbpf.found() and clang.found() and llvm_strip.found() and bpftool.found() + deps_found = libbpf.found() and clang.found() and clang_supports_bpf and llvm_strip.found() and bpftool.found() # Can build BPF program from source code in restricted C conf.set10('BPF_FRAMEWORK', deps_found) endif From dc7e9c1bc4236f17049112ffaa766f3a5b749171 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 13 Jan 2022 15:43:24 +0900 Subject: [PATCH 3/3] meson: use the compiler command array as is Also check if the flags used when building bpf are supported by clang. --- meson.build | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 073667ef6c..648f47b56c 100644 --- a/meson.build +++ b/meson.build @@ -990,20 +990,32 @@ if want_bpf_framework == 'false' else # Support 'versioned' clang/llvm-strip binaries, as seen on Debian/Ubuntu # (like clang-10/llvm-strip-10) - clang_bin = cc.get_id() == 'clang' ? cc.cmd_array()[0] : 'clang' - if meson.is_cross_build() or clang_bin.contains('afl-clang') or clang_bin.contains('hfuzz-clang') - clang_bin = 'clang' + if meson.is_cross_build() or cc.get_id() != 'clang' or cc.cmd_array()[0].contains('afl-clang') or cc.cmd_array()[0].contains('hfuzz-clang') + r = find_program('clang', required : bpf_framework_required) + clang_found = r.found() + if clang_found + if meson.version().version_compare('>= 0.55') + clang = [r.full_path()] + else + clang = [r.path()] + endif + endif + # Assume that the required flags are supported by the found clang. + clang_supports_flags = clang_found + else + clang_found = true + clang = cc.cmd_array() + clang_supports_flags = cc.has_argument('-Wno-compare-distinct-pointer-types') endif - clang = find_program(clang_bin, required : bpf_framework_required) - if clang.found() + if clang_found # Check if 'clang -target bpf' is supported. clang_supports_bpf = run_command(clang, '-target', 'bpf', '--print-supported-cpus', check : false).returncode() == 0 else clang_supports_bpf = false endif - if not meson.is_cross_build() and clang.found() + if not meson.is_cross_build() and clang_found llvm_strip_bin = run_command(clang, '--print-prog-name', 'llvm-strip', check : true).stdout().strip() else @@ -1019,7 +1031,8 @@ else required : bpf_framework_required, version : '>= 5.6') - deps_found = libbpf.found() and clang.found() and clang_supports_bpf and llvm_strip.found() and bpftool.found() + deps_found = libbpf.found() and clang_found and clang_supports_bpf and clang_supports_flags and llvm_strip.found() and bpftool.found() + # Can build BPF program from source code in restricted C conf.set10('BPF_FRAMEWORK', deps_found) endif