On Fri, 2021-10-22 at 01:46 +0200, Ilya Leoshkevich wrote: > This is the same as commit c9e982b87946 ("libbpf: Fix dumping > big-endian bitfields"), but for CO-RE. Make the code structure as > similar as possible to that of btf_dump_get_bitfield_value(). > > Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx> > --- > tools/lib/bpf/relo_core.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c > index b5b8956a1be8..fd814b985e1e 100644 > --- a/tools/lib/bpf/relo_core.c > +++ b/tools/lib/bpf/relo_core.c > @@ -661,13 +661,18 @@ static int bpf_core_calc_field_relo(const char > *prog_name, > if (validate) > *validate = true; /* signedness is never > ambiguous */ > break; > - case BPF_FIELD_LSHIFT_U64: > + case BPF_FIELD_LSHIFT_U64: { > + __u32 bits_offset = bit_off - byte_off * 8; > + __u8 nr_copy_bits; > + > #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > - *val = 64 - (bit_off + bit_sz - byte_off * 8); > + nr_copy_bits = bit_sz + bits_offset; > #else > - *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8); > + nr_copy_bits = byte_sz * 8 - bits_offset; > #endif > + *val = 64 - nr_copy_bits; > break; > + } > case BPF_FIELD_RSHIFT_U64: > *val = 64 - bit_sz; > if (validate) At a closer look this patch is not necessary: the new and the old expressions yield the same result. Please disregard it. Best regards, Ilya