Similarly to a0d7da26ce86 ("libbpf: Fix call relocation offset calculation bug"), relocations against global variables need to take into account referenced symbol's st_value, which holds offset into a corresponding data section (and, subsequently, offset into internal backing map). For static variables this offset is always zero and data offset is completely described by respective instruction's imm field. Convert a bunch of selftests to global variables. Previously they were relying on `static volatile` trick to ensure Clang doesn't inline static variables, which with global variables is not necessary anymore. Fixes: 393cdfbee809 ("libbpf: Support initialized global variables") Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20191127200651.1381348-1-andriin@fb.com
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2019 Facebook */
|
|
#include <linux/bpf.h>
|
|
#include "bpf_helpers.h"
|
|
#include "bpf_trace_helpers.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
__u64 test1_result = 0;
|
|
BPF_TRACE_1("fentry/bpf_fentry_test1", test1, int, a)
|
|
{
|
|
test1_result = a == 1;
|
|
return 0;
|
|
}
|
|
|
|
__u64 test2_result = 0;
|
|
BPF_TRACE_2("fentry/bpf_fentry_test2", test2, int, a, __u64, b)
|
|
{
|
|
test2_result = a == 2 && b == 3;
|
|
return 0;
|
|
}
|
|
|
|
__u64 test3_result = 0;
|
|
BPF_TRACE_3("fentry/bpf_fentry_test3", test3, char, a, int, b, __u64, c)
|
|
{
|
|
test3_result = a == 4 && b == 5 && c == 6;
|
|
return 0;
|
|
}
|
|
|
|
__u64 test4_result = 0;
|
|
BPF_TRACE_4("fentry/bpf_fentry_test4", test4,
|
|
void *, a, char, b, int, c, __u64, d)
|
|
{
|
|
test4_result = a == (void *)7 && b == 8 && c == 9 && d == 10;
|
|
return 0;
|
|
}
|
|
|
|
__u64 test5_result = 0;
|
|
BPF_TRACE_5("fentry/bpf_fentry_test5", test5,
|
|
__u64, a, void *, b, short, c, int, d, __u64, e)
|
|
{
|
|
test5_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
|
|
e == 15;
|
|
return 0;
|
|
}
|
|
|
|
__u64 test6_result = 0;
|
|
BPF_TRACE_6("fentry/bpf_fentry_test6", test6,
|
|
__u64, a, void *, b, short, c, int, d, void *, e, __u64, f)
|
|
{
|
|
test6_result = a == 16 && b == (void *)17 && c == 18 && d == 19 &&
|
|
e == (void *)20 && f == 21;
|
|
return 0;
|
|
}
|