@@ -88,11 +88,19 @@ enum bpf_enum_value_kind {
88
88
const void *p = (const void *)s + __CORE_RELO(s, field, BYTE_OFFSET); \
89
89
unsigned long long val; \
90
90
\
91
+ /* This is a so-called barrier_var() operation that makes specified \
92
+ * variable "a black box" for optimizing compiler. \
93
+ * It forces compiler to perform BYTE_OFFSET relocation on p and use \
94
+ * its calculated value in the switch below, instead of applying \
95
+ * the same relocation 4 times for each individual memory load. \
96
+ */ \
97
+ asm volatile ("" : "=r" (p ) : "0" (p )); \
98
+ \
91
99
switch (__CORE_RELO (s , field , BYTE_SIZE )) { \
92
- case 1: val = *(const unsigned char *)p; \
93
- case 2: val = *(const unsigned short *)p; \
94
- case 4: val = *(const unsigned int *)p; \
95
- case 8: val = *(const unsigned long long *)p; \
100
+ case 1 : val = * (const unsigned char * )p ; break ; \
101
+ case 2 : val = * (const unsigned short * )p ; break ; \
102
+ case 4 : val = * (const unsigned int * )p ; break ; \
103
+ case 8 : val = * (const unsigned long long * )p ; break ; \
96
104
} \
97
105
val <<= __CORE_RELO (s , field , LSHIFT_U64 ); \
98
106
if (__CORE_RELO (s , field , SIGNED )) \
0 commit comments