Bitfield offsets can be negative, if field "borrows" few bits from following aligned field. This causes a bunch of surprises down the line in pahole's logic (e.g., for hole calculation logic), so instead of waiting till printf routines adjust this for display, adjust them early and keep less surprising semantics. Signed-off-by: Andrii Nakryiko <andriin@xxxxxx> --- btf_loader.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/btf_loader.c b/btf_loader.c index e04175e..e98505b 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -482,6 +482,12 @@ static int class__fixup_btf_bitfields(struct tag *tag, struct cu *cu, struct btf pos->bitfield_offset = pos->bit_offset - pos->byte_offset * 8; if (!btfe->is_big_endian) pos->bitfield_offset = pos->bit_size - pos->bitfield_offset - pos->bitfield_size; + /* re-adjust bitfield offset if it is negative */ + if (pos->bitfield_offset < 0) { + pos->bitfield_offset += pos->bit_size; + pos->byte_offset += pos->byte_size; + pos->bit_offset = pos->byte_offset * 8 + pos->bitfield_offset; + } } else { pos->byte_offset = pos->bit_offset / 8; } -- 2.17.1