| 1 |
|
| 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; |
| 31 |
volatile unsigned int key2 = 1; |
| 32 |
volatile const unsigned int key3 = 2; |
| 33 |
|
| 34 |
|
| 35 |
volatile const uint32_t arg = 1; |
| 36 |
|
| 37 |
volatile const uint32_t arg2 __section(".rodata.test") = 2; |
| 38 |
|
| 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 |
|
| 49 |
__section("socket") int no_relocation() { |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 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 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
__section("socket/4") int anon_const() { |
| 88 |
volatile int ctx = 0; |
| 89 |
|
| 90 |
|
| 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 |
} |