Skip to content

Commit 093effc

Browse files
christycyleeYucong Sun
authored andcommitted
perf: Stop using deprecated bpf_load_program() API
bpf_load_program() API is deprecated, remove perf's usage of the deprecated function. Add a __weak function declaration for libbpf version compatibility. Signed-off-by: Christy Lee <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]>
1 parent 8da9017 commit 093effc

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

tools/perf/tests/bpf.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,28 +281,22 @@ static int __test__bpf(int idx)
281281

282282
static int check_env(void)
283283
{
284+
LIBBPF_OPTS(bpf_prog_load_opts, opts);
284285
int err;
285-
unsigned int kver_int;
286286
char license[] = "GPL";
287287

288288
struct bpf_insn insns[] = {
289289
BPF_MOV64_IMM(BPF_REG_0, 1),
290290
BPF_EXIT_INSN(),
291291
};
292292

293-
err = fetch_kernel_version(&kver_int, NULL, 0);
293+
err = fetch_kernel_version(&opts.kern_version, NULL, 0);
294294
if (err) {
295295
pr_debug("Unable to get kernel version\n");
296296
return err;
297297
}
298-
299-
/* temporarily disable libbpf deprecation warnings */
300-
#pragma GCC diagnostic push
301-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
302-
err = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns,
303-
ARRAY_SIZE(insns),
304-
license, kver_int, NULL, 0);
305-
#pragma GCC diagnostic pop
298+
err = bpf_prog_load(BPF_PROG_TYPE_KPROBE, NULL, license, insns,
299+
ARRAY_SIZE(insns), &opts);
306300
if (err < 0) {
307301
pr_err("Missing basic BPF support, skip this test: %s\n",
308302
strerror(errno));

tools/perf/util/bpf-event.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ struct btf * __weak btf__load_from_kernel_by_id(__u32 id)
3333
return err ? ERR_PTR(err) : btf;
3434
}
3535

36+
int __weak bpf_prog_load(enum bpf_prog_type prog_type,
37+
const char *prog_name __maybe_unused,
38+
const char *license,
39+
const struct bpf_insn *insns, size_t insn_cnt,
40+
const struct bpf_prog_load_opts *opts)
41+
{
42+
#pragma GCC diagnostic push
43+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44+
return bpf_load_program(prog_type, insns, insn_cnt, license,
45+
opts->kern_version, opts->log_buf, opts->log_size);
46+
#pragma GCC diagnostic pop
47+
}
48+
3649
struct bpf_program * __weak
3750
bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
3851
{

0 commit comments

Comments
 (0)