Skip to content

libbpf-rs: Fix BTF int offset extraction from aux word#1367

Closed
cuiweixie wants to merge 1 commit into
libbpf:masterfrom
cuiweixie:fix/btf-int-offset-shift
Closed

libbpf-rs: Fix BTF int offset extraction from aux word#1367
cuiweixie wants to merge 1 commit into
libbpf:masterfrom
cuiweixie:fix/btf-int-offset-shift

Conversation

@cuiweixie
Copy link
Copy Markdown

What

Correct the shift applied after masking bits 16–23 of the BTF KIND_INT auxiliary u32 when building Int::offset. The mask 0x00_ff_00_00 must be paired with a shift of 16, not 24, so the field matches the layout used by BTF_INT_ENCODING in the kernel UAPI.

Why

With shift 24, the masked value was decoded from the wrong bit positions, so Int::offset did not reflect the encoded offset.

The auxiliary u32 for BTF_KIND_INT packs several fields; the offset lives
in bits 16–23 (see BTF_INT_ENCODING in the kernel UAPI). After masking
with 0x00_ff_00_00, shifting by 24 decodes the wrong bit range, so
Int::offset was effectively wrong. Shift by 16 to align the mask with
the documented layout.
Copy link
Copy Markdown
Collaborator

@d-e-s-o d-e-s-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mask 0x00_ff_00_00 must be paired with a shift of 16, not 24, so the field matches the layout used by BTF_INT_ENCODING in the kernel UAPI.

Shouldn't this be about BTF_INT_OFFSET? BTF_INT_ENCODING seems to use 24.

Looks good to me other than that. Thanks!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

This pull request is considered stale because it has been open 30 days with no activity. Remove stale label or comment or it will be closed in 5 days.

@github-actions github-actions Bot added the Stale label May 7, 2026
@github-actions
Copy link
Copy Markdown

Closing pull request as it is stale.

@github-actions github-actions Bot closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants