1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_legacy.h"
6 
7 struct ipv_counts {
8 	unsigned int v4;
9 	unsigned int v6;
10 };
11 
12 /* just to validate we can handle maps in multiple sections */
13 struct bpf_map_def SEC("maps") btf_map_legacy = {
14 	.type = BPF_MAP_TYPE_ARRAY,
15 	.key_size = sizeof(int),
16 	.value_size = sizeof(long long),
17 	.max_entries = 4,
18 };
19 
20 BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
21 
22 struct {
23 	__uint(type, BPF_MAP_TYPE_ARRAY);
24 	__uint(max_entries, 4);
25 	__type(key, int);
26 	__type(value, struct ipv_counts);
27 } btf_map SEC(".maps");
28 
29 __attribute__((noinline))
30 int test_long_fname_2(void)
31 {
32 	struct ipv_counts *counts;
33 	int key = 0;
34 
35 	counts = bpf_map_lookup_elem(&btf_map, &key);
36 	if (!counts)
37 		return 0;
38 
39 	counts->v6++;
40 
41 	/* just verify we can reference both maps */
42 	counts = bpf_map_lookup_elem(&btf_map_legacy, &key);
43 	if (!counts)
44 		return 0;
45 
46 	return 0;
47 }
48 
49 __attribute__((noinline))
50 int test_long_fname_1(void)
51 {
52 	return test_long_fname_2();
53 }
54 
55 SEC("dummy_tracepoint")
56 int _dummy_tracepoint(void *arg)
57 {
58 	return test_long_fname_1();
59 }
60 
61 char _license[] SEC("license") = "GPL";
62