Debian Codegraph @

testdata/loader.c

raw symbols SCIP
1 /* This file excercises the ELF loader.
2 */
3
4 #include "common.h"
5
6 char __license[] __section("license") = "MIT";
7
8 #ifdef __NOBTF__
9 #include "loader_nobtf.h"
10 #else
11 #include "loader.h"
12 #endif
13
14 static int __attribute__((noinline)) __section("static") static_fn(uint32_t arg) {
15 return arg - 1;
16 }
17
18 int __attribute__((noinline)) global_fn2(uint32_t arg) {
19 return arg + 2;
20 }
21
22 int __attribute__((noinline)) __section("other") global_fn3(uint32_t arg) {
23 return arg + 1;
24 }
25
26 int __attribute__((noinline)) global_fn(uint32_t arg) {
27 return static_fn(arg) + global_fn2(arg) + global_fn3(arg);
28 }
29
30 volatile unsigned int key1 = 0; // .bss
31 volatile unsigned int key2 = 1; // .data
32 volatile const unsigned int key3 = 2; // .rodata
33
34 // .rodata
35 volatile const uint32_t arg = 1;
36 // custom .rodata section
37 volatile const uint32_t arg2 __section(".rodata.test") = 2;
38 // custom .data section
39 volatile uint32_t arg3 __section(".data.test");
40
41 __section("xdp") int xdp_prog() {
42 bpf_map_lookup_elem(&hash_map, (void *)&key1);
43 bpf_map_lookup_elem(&hash_map2, (void *)&key2);
44 bpf_map_lookup_elem(&hash_map2, (void *)&key3);
45 return static_fn(arg) + global_fn(arg) + arg2 + arg3;
46 }
47
48 // This function has no relocations, and is thus parsed differently.
49 __section("socket") int no_relocation() {
50 return 0;
51 }
52
53 // Make sure we allow relocations generated by inline assembly.
54 __section("socket/2") int asm_relocation() {
55 int my_const;
56 asm("%0 = MY_CONST ll" : "=r"(my_const));
57 return my_const;
58 }
59
60 volatile const unsigned int uneg = -1;
61 volatile const int neg = -2;
62 static volatile const unsigned int static_uneg = -3;
63 static volatile const int static_neg = -4;
64
65 __section("socket/3") int data_sections() {
66 if (uneg != (unsigned int)-1)
67 return __LINE__;
68
69 if (neg != -2)
70 return __LINE__;
71
72 if (static_uneg != (unsigned int)-3)
73 return __LINE__;
74
75 if (static_neg != -4)
76 return __LINE__;
77
78 return 0;
79 }
80
81 /*
82 * Up until LLVM 14, this program results in an .rodata.cst32 section
83 * that is accessed by 'return values[i]'. For this section, no BTF is
84 * emitted. 'values' cannot be rewritten, since there is no BTF info
85 * describing the data section.
86 */
87 __section("socket/4") int anon_const() {
88 volatile int ctx = 0;
89
90 // 32 bytes wide results in a .rodata.cst32 section.
91 #define values (uint64_t[]){0x0, 0x1, 0x2, 0x3}
92
93 int i;
94 for (i = 0; i < 3; i++) {
95 if (ctx == values[i]) {
96 return values[i];
97 }
98 }
99
100 return 0;
101 }