X Tutup
Skip to content

Commit d40ce01

Browse files
jameshilliardkeszybz
authored andcommitted
bpf: refactor skeleton generation
This should hopefully fix cross compilation for the bpf programs.
1 parent d4f8cd4 commit d40ce01

File tree

12 files changed

+155
-157
lines changed

12 files changed

+155
-157
lines changed

meson.build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,9 @@ else
10081008
# We check for 'bpftool' first, honouring $PATH, and in /usr/sbin/ for Debian.
10091009
bpftool = find_program('bpftool', '/usr/sbin/bpftool', required : bpf_framework_required)
10101010

1011-
bpf_arches = ['x86_64']
10121011
deps_found = libbpf.found() and clang.found() and llvm_strip.found() and bpftool.found()
10131012
# Can build BPF program from source code in restricted C
1014-
conf.set10('BPF_FRAMEWORK',
1015-
bpf_arches.contains(host_machine.cpu_family()) and deps_found)
1013+
conf.set10('BPF_FRAMEWORK', deps_found)
10161014
endif
10171015

10181016
libmount = dependency('mount',
@@ -1685,7 +1683,6 @@ subdir('src/boot/efi')
16851683

16861684
############################################################
16871685

1688-
build_bpf_skel_py = find_program('tools/build-bpf-skel.py')
16891686
generate_gperfs = find_program('tools/generate-gperfs.py')
16901687
make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py')
16911688
make_directive_index_py = find_program('tools/make-directive-index.py')

src/core/bpf-socket-bind.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* libbpf, clang, llvm and bpftool compile time dependencies are satisfied */
1212
#include "bpf-dlopen.h"
1313
#include "bpf-link.h"
14-
#include "bpf/socket_bind/socket-bind.skel.h"
14+
#include "bpf/socket_bind/socket-bind-skel.h"
1515
#include "bpf/socket_bind/socket-bind-api.bpf.h"
1616

1717
static struct socket_bind_bpf *socket_bind_bpf_free(struct socket_bind_bpf *obj) {

src/core/bpf/meson.build

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-License-Identifier: LGPL-2.1+
2+
3+
if conf.get('BPF_FRAMEWORK') == 1
4+
clang_flags = [
5+
'-Wno-compare-distinct-pointer-types',
6+
'-O2',
7+
'-target',
8+
'bpf',
9+
'-g',
10+
'-c',
11+
]
12+
13+
clang_arch_flag = '-D__@0@__'.format(host_machine.cpu_family())
14+
15+
if meson.version().version_compare('>= 0.58')
16+
libbpf_include_dir = libbpf.get_variable('includedir')
17+
else
18+
libbpf_include_dir = libbpf.get_variable(pkgconfig : 'includedir')
19+
endif
20+
21+
bpf_o_unstripped_cmd = [
22+
clang,
23+
clang_flags,
24+
clang_arch_flag,
25+
'-I.'
26+
]
27+
28+
if not meson.is_cross_build()
29+
target_triplet_cmd = run_command('gcc', '-dumpmachine', check: false)
30+
if target_triplet_cmd.returncode() == 0
31+
target_triplet = target_triplet_cmd.stdout().strip()
32+
bpf_o_unstripped_cmd += [
33+
'-isystem',
34+
'/usr/include/@0@'.format(target_triplet)
35+
]
36+
endif
37+
endif
38+
39+
bpf_o_unstripped_cmd += [
40+
'-idirafter',
41+
libbpf_include_dir,
42+
'@INPUT@',
43+
'-o',
44+
'@OUTPUT@'
45+
]
46+
47+
bpf_o_cmd = [
48+
llvm_strip,
49+
'-g',
50+
'@INPUT@',
51+
'-o',
52+
'@OUTPUT@'
53+
]
54+
55+
skel_h_cmd = [
56+
bpftool,
57+
'g',
58+
's',
59+
'@INPUT@'
60+
]
61+
endif
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

33
if conf.get('BPF_FRAMEWORK') == 1
4-
restrict_fs_skel_h = custom_target(
5-
'restrict-fs-skel.h',
4+
restrict_fs_bpf_o_unstripped = custom_target(
5+
'restrict-fs.bpf.unstripped.o',
66
input : 'restrict-fs.bpf.c',
7-
output : 'restrict-fs-skel.h',
8-
command : [build_bpf_skel_py,
9-
'--clang_exec', clang.path(),
10-
'--llvm_strip_exec', llvm_strip.path(),
11-
'--bpftool_exec', bpftool.path(),
12-
'--arch', host_machine.cpu_family(),
13-
'@INPUT@', '@OUTPUT@'])
7+
output : 'restrict-fs.bpf.unstripped.o',
8+
command : bpf_o_unstripped_cmd)
9+
10+
restrict_fs_bpf_o = custom_target(
11+
'restrict-fs.bpf.o',
12+
input : restrict_fs_bpf_o_unstripped,
13+
output : 'restrict-fs.bpf.o',
14+
command : bpf_o_cmd)
15+
16+
restrict_fs_skel_h = custom_target(
17+
'restrict-fs.skel.h',
18+
input : restrict_fs_bpf_o,
19+
output : 'restrict-fs.skel.h',
20+
command : skel_h_cmd,
21+
capture : true)
1422
endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
/* The SPDX header above is actually correct in claiming this was
4+
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
5+
* compatible with GPL we will claim this to be GPL however, which should be
6+
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
7+
*/
8+
9+
/* libbpf is used via dlopen(), so rename symbols */
10+
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
11+
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
12+
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
13+
14+
#include "bpf/restrict_fs/restrict-fs.skel.h"
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

33
if conf.get('BPF_FRAMEWORK') == 1
4+
restrict_ifaces_bpf_o_unstripped = custom_target(
5+
'restrict-ifaces.bpf.unstripped.o',
6+
input : 'restrict-ifaces.bpf.c',
7+
output : 'restrict-ifaces.bpf.unstripped.o',
8+
command : bpf_o_unstripped_cmd)
9+
10+
restrict_ifaces_bpf_o = custom_target(
11+
'restrict-ifaces.bpf.o',
12+
input : restrict_ifaces_bpf_o_unstripped,
13+
output : 'restrict-ifaces.bpf.o',
14+
command : bpf_o_cmd)
15+
416
restrict_ifaces_skel_h = custom_target(
517
'restrict-ifaces.skel.h',
6-
input : 'restrict-ifaces.bpf.c',
18+
input : restrict_ifaces_bpf_o,
719
output : 'restrict-ifaces.skel.h',
8-
command : [build_bpf_skel_py,
9-
'--clang_exec', clang.path(),
10-
'--llvm_strip_exec', llvm_strip.path(),
11-
'--bpftool_exec', bpftool.path(),
12-
'--arch', host_machine.cpu_family(),
13-
'@INPUT@', '@OUTPUT@'])
20+
command : skel_h_cmd,
21+
capture : true)
1422
endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
/* The SPDX header above is actually correct in claiming this was
4+
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
5+
* compatible with GPL we will claim this to be GPL however, which should be
6+
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
7+
*/
8+
9+
/* libbpf is used via dlopen(), so rename symbols */
10+
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
11+
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
12+
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
13+
14+
#include "bpf/restrict_ifaces/restrict-ifaces.skel.h"
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

33
if conf.get('BPF_FRAMEWORK') == 1
4+
socket_bind_bpf_o_unstripped = custom_target(
5+
'socket-bind.bpf.unstripped.o',
6+
input : 'socket-bind.bpf.c',
7+
output : 'socket-bind.bpf.unstripped.o',
8+
command : bpf_o_unstripped_cmd)
9+
10+
socket_bind_bpf_o = custom_target(
11+
'socket-bind.bpf.o',
12+
input : socket_bind_bpf_o_unstripped,
13+
output : 'socket-bind.bpf.o',
14+
command : bpf_o_cmd)
15+
416
socket_bind_skel_h = custom_target(
517
'socket-bind.skel.h',
6-
input : 'socket-bind.bpf.c',
18+
input : socket_bind_bpf_o,
719
output : 'socket-bind.skel.h',
8-
command : [build_bpf_skel_py,
9-
'--clang_exec', clang.path(),
10-
'--llvm_strip_exec', llvm_strip.path(),
11-
'--bpftool_exec', bpftool.path(),
12-
'--arch', host_machine.cpu_family(),
13-
'@INPUT@', '@OUTPUT@'])
20+
command : skel_h_cmd,
21+
capture : true)
1422
endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
/* The SPDX header above is actually correct in claiming this was
4+
* LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
5+
* compatible with GPL we will claim this to be GPL however, which should be
6+
* fine given that LGPL-2.1-or-later downgrades to GPL if needed.
7+
*/
8+
9+
/* libbpf is used via dlopen(), so rename symbols */
10+
#define bpf_object__open_skeleton sym_bpf_object__open_skeleton
11+
#define bpf_object__load_skeleton sym_bpf_object__load_skeleton
12+
#define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton
13+
14+
#include "bpf/socket_bind/socket-bind.skel.h"

src/core/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ libcore_sources = '''
133133
unit.h
134134
'''.split()
135135

136+
subdir('bpf')
137+
136138
subdir('bpf/socket_bind')
137139
if conf.get('BPF_FRAMEWORK') == 1
138140
libcore_sources += [socket_bind_skel_h]

0 commit comments

Comments
 (0)
X Tutup