bpf: refactor skeleton generation

This should hopefully fix cross compilation for the bpf programs.
This commit is contained in:
James Hilliard
2021-12-07 18:37:17 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent d4f8cd4d83
commit d40ce01814
12 changed files with 155 additions and 157 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
/* libbpf, clang, llvm and bpftool compile time dependencies are satisfied */
#include "bpf-dlopen.h"
#include "bpf-link.h"
#include "bpf/socket_bind/socket-bind.skel.h"
#include "bpf/socket_bind/socket-bind-skel.h"
#include "bpf/socket_bind/socket-bind-api.bpf.h"
static struct socket_bind_bpf *socket_bind_bpf_free(struct socket_bind_bpf *obj) {
+61
View File
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: LGPL-2.1+
if conf.get('BPF_FRAMEWORK') == 1
clang_flags = [
'-Wno-compare-distinct-pointer-types',
'-O2',
'-target',
'bpf',
'-g',
'-c',
]
clang_arch_flag = '-D__@0@__'.format(host_machine.cpu_family())
if meson.version().version_compare('>= 0.58')
libbpf_include_dir = libbpf.get_variable('includedir')
else
libbpf_include_dir = libbpf.get_variable(pkgconfig : 'includedir')
endif
bpf_o_unstripped_cmd = [
clang,
clang_flags,
clang_arch_flag,
'-I.'
]
if not meson.is_cross_build()
target_triplet_cmd = run_command('gcc', '-dumpmachine', check: false)
if target_triplet_cmd.returncode() == 0
target_triplet = target_triplet_cmd.stdout().strip()
bpf_o_unstripped_cmd += [
'-isystem',
'/usr/include/@0@'.format(target_triplet)
]
endif
endif
bpf_o_unstripped_cmd += [
'-idirafter',
libbpf_include_dir,
'@INPUT@',
'-o',
'@OUTPUT@'
]
bpf_o_cmd = [
llvm_strip,
'-g',
'@INPUT@',
'-o',
'@OUTPUT@'
]
skel_h_cmd = [
bpftool,
'g',
's',
'@INPUT@'
]
endif
+17 -9
View File
@@ -1,14 +1,22 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
if conf.get('BPF_FRAMEWORK') == 1
restrict_fs_skel_h = custom_target(
'restrict-fs-skel.h',
restrict_fs_bpf_o_unstripped = custom_target(
'restrict-fs.bpf.unstripped.o',
input : 'restrict-fs.bpf.c',
output : 'restrict-fs-skel.h',
command : [build_bpf_skel_py,
'--clang_exec', clang.path(),
'--llvm_strip_exec', llvm_strip.path(),
'--bpftool_exec', bpftool.path(),
'--arch', host_machine.cpu_family(),
'@INPUT@', '@OUTPUT@'])
output : 'restrict-fs.bpf.unstripped.o',
command : bpf_o_unstripped_cmd)
restrict_fs_bpf_o = custom_target(
'restrict-fs.bpf.o',
input : restrict_fs_bpf_o_unstripped,
output : 'restrict-fs.bpf.o',
command : bpf_o_cmd)
restrict_fs_skel_h = custom_target(
'restrict-fs.skel.h',
input : restrict_fs_bpf_o,
output : 'restrict-fs.skel.h',
command : skel_h_cmd,
capture : true)
endif
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* The SPDX header above is actually correct in claiming this was
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
* compatible with GPL we will claim this to be GPL however, which should be
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
*/
/* libbpf is used via dlopen(), so rename symbols */
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
#include "bpf/restrict_fs/restrict-fs.skel.h"
+15 -7
View File
@@ -1,14 +1,22 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
if conf.get('BPF_FRAMEWORK') == 1
restrict_ifaces_bpf_o_unstripped = custom_target(
'restrict-ifaces.bpf.unstripped.o',
input : 'restrict-ifaces.bpf.c',
output : 'restrict-ifaces.bpf.unstripped.o',
command : bpf_o_unstripped_cmd)
restrict_ifaces_bpf_o = custom_target(
'restrict-ifaces.bpf.o',
input : restrict_ifaces_bpf_o_unstripped,
output : 'restrict-ifaces.bpf.o',
command : bpf_o_cmd)
restrict_ifaces_skel_h = custom_target(
'restrict-ifaces.skel.h',
input : 'restrict-ifaces.bpf.c',
input : restrict_ifaces_bpf_o,
output : 'restrict-ifaces.skel.h',
command : [build_bpf_skel_py,
'--clang_exec', clang.path(),
'--llvm_strip_exec', llvm_strip.path(),
'--bpftool_exec', bpftool.path(),
'--arch', host_machine.cpu_family(),
'@INPUT@', '@OUTPUT@'])
command : skel_h_cmd,
capture : true)
endif
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* The SPDX header above is actually correct in claiming this was
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
* compatible with GPL we will claim this to be GPL however, which should be
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
*/
/* libbpf is used via dlopen(), so rename symbols */
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
#include "bpf/restrict_ifaces/restrict-ifaces.skel.h"
+15 -7
View File
@@ -1,14 +1,22 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
if conf.get('BPF_FRAMEWORK') == 1
socket_bind_bpf_o_unstripped = custom_target(
'socket-bind.bpf.unstripped.o',
input : 'socket-bind.bpf.c',
output : 'socket-bind.bpf.unstripped.o',
command : bpf_o_unstripped_cmd)
socket_bind_bpf_o = custom_target(
'socket-bind.bpf.o',
input : socket_bind_bpf_o_unstripped,
output : 'socket-bind.bpf.o',
command : bpf_o_cmd)
socket_bind_skel_h = custom_target(
'socket-bind.skel.h',
input : 'socket-bind.bpf.c',
input : socket_bind_bpf_o,
output : 'socket-bind.skel.h',
command : [build_bpf_skel_py,
'--clang_exec', clang.path(),
'--llvm_strip_exec', llvm_strip.path(),
'--bpftool_exec', bpftool.path(),
'--arch', host_machine.cpu_family(),
'@INPUT@', '@OUTPUT@'])
command : skel_h_cmd,
capture : true)
endif
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* The SPDX header above is actually correct in claiming this was
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
* compatible with GPL we will claim this to be GPL however, which should be
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
*/
/* libbpf is used via dlopen(), so rename symbols */
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
#include "bpf/socket_bind/socket-bind.skel.h"
+2
View File
@@ -133,6 +133,8 @@ libcore_sources = '''
unit.h
'''.split()
subdir('bpf')
subdir('bpf/socket_bind')
if conf.get('BPF_FRAMEWORK') == 1
libcore_sources += [socket_bind_skel_h]
+1 -1
View File
@@ -10,7 +10,7 @@
#include "bpf-dlopen.h"
#include "bpf-link.h"
#include "bpf/restrict_ifaces/restrict-ifaces.skel.h"
#include "bpf/restrict_ifaces/restrict-ifaces-skel.h"
static struct restrict_ifaces_bpf *restrict_ifaces_bpf_free(struct restrict_ifaces_bpf *obj) {
restrict_ifaces_bpf__destroy(obj);