1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "callx_rodata.lskel.h"
#if defined(__x86_64__) || defined(__aarch64__)
static void run(int prog_fd, int expected, const char *name)
{
LIBBPF_OPTS(bpf_test_run_opts, topts);
char pkt[64] = {};
topts.data_in = pkt;
topts.data_size_in = sizeof(pkt);
if (ASSERT_OK(bpf_prog_test_run_opts(prog_fd, &topts), name))
ASSERT_EQ(topts.retval, expected, name);
}
/*
* Every program that has callx gets its own copy of .rodata with the offsets
* of its functions. The copies have what user space puts into .rodata before
* the load. The program that doesn't have callx uses .rodata.
*/
static void __test_callx_rodata_lskel(void)
{
struct callx_rodata_lskel *skel;
/* there is no support for callx in the interpreter */
if (!is_jit_enabled()) {
test__skip();
return;
}
skel = callx_rodata_lskel__open();
if (!ASSERT_OK_PTR(skel, "open"))
return;
/* gcc doesn't support indirect calls */
if (skel->rodata->skip) {
test__skip();
goto out;
}
skel->rodata->bias = 7;
if (!ASSERT_OK(callx_rodata_lskel__load(skel), "load"))
goto out;
skel->bss->op_idx = 0;
run(skel->progs.select_op.prog_fd, 17, "add_bias");
skel->bss->op_idx = 1;
run(skel->progs.select_op.prog_fd, 30, "mul3");
skel->bss->op_idx = 2;
run(skel->progs.select_op.prog_fd, -1, "out_of_range");
/* mul3(add_bias(4)) */
run(skel->progs.both_ops.prog_fd, 33, "both_ops");
run(skel->progs.read_bias.prog_fd, 7, "read_bias");
out:
callx_rodata_lskel__destroy(skel);
}
#else
static void __test_callx_rodata_lskel(void)
{
test__skip();
}
#endif
void test_callx_rodata_lskel(void)
{
__test_callx_rodata_lskel();
}
|