Skip to content

libbpf-cargo: Handle empty unions in BTF types #975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

JoelColledge
Copy link
Contributor

This was noticed because a "vmlinux.h" contained:

struct bio {
...
	union {};
...
};

Which caused the following error when trying to use "struct bio" in a .bpf.c file:

  thread 'main' panicked at /home/jrc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libbpf-cargo-0.24.6/src/gen/btf.rs:769:49:
  index out of bounds: the len is 0 but the index is 0

Fix this by hiding empty unions from the generated types. Rust does not allow union types with zero fields.

Fixes #974.

This was noticed because a "vmlinux.h" contained:

struct bio {
...
	union {};
...
};

Which caused the following error when trying to use "struct bio" in a
.bpf.c file:

  thread 'main' panicked at /home/jrc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libbpf-cargo-0.24.6/src/gen/btf.rs:769:49:
  index out of bounds: the len is 0 but the index is 0

Fix this by hiding empty unions from the generated types. Rust does not
allow union types with zero fields.

Signed-off-by: Joel Colledge <[email protected]>
Copy link
Collaborator

@danielocfb danielocfb left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@danielocfb danielocfb merged commit ba50e9a into libbpf:master Oct 22, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libbpf-cargo: Build fails when a C struct contains an empty union
2 participants