Print a diagnostic warning when bitfields are accessed directly in
structures that are marked with preserve_access_index attribute. Such
bitfields should be accessed using BPF_CORE_READ_BITFIELD and
BPF_CORE_READ_BITFIELD_PROBED macro.
These macro generate a specific pattern:
struct foo {
int field:2;
} *ctx;
BPF_CORE_READ_BITFIELD(ctx, field)is expanded as:
({ const void *p = (void*) ctx + __builtin_preserve_field_info(...);
unsigned long long val;
... val = *(<cast>)p; ...
val;
})Note that ptr->field is not referenced, instead an address is
computed starting from ctx. This commit exploits this fact and simply
warns about usage of ptr->field in load instructions.