Skip to content
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

btfdump: Allow to dump from /sys/kernel/btf/vmlinux #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vadorovsky
Copy link

Support dumping BTF not only from ELF files, but also from raw BTF information (which starts directly with BTF magic number) like the one peresent in /sys/kernel/btf/vmlinux.

This way, btfdump can be used for generating the vmlinux.h for the given kernel.

Also, don't use mmap, since it doesn't work on sysfs.

Support dumping BTF not only from ELF files, but also from raw BTF
information (which starts directly with BTF magic number) like the
one peresent in /sys/kernel/btf/vmlinux.

This way, btfdump can be used for generating the vmlinux.h for the
given kernel.

Also, don't use mmap, since it doesn't work on sysfs.
Copy link
Owner

@anakryiko anakryiko left a comment

Choose a reason for hiding this comment

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

Great feature, let's generalize it a bit. Thanks for contributing!

// Read the magic number first.
let mut buffer = [0u8; 2];
file.read_exact(&mut buffer)?;
let magic_number: u16 = u16::from_le_bytes(buffer);
Copy link
Owner

Choose a reason for hiding this comment

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

this should take into account host endianness, no?

} else {
// Otherwise, assume it's an object file and parse BTF from
// the `.BTF` section.
let file = object::File::parse(contents.as_slice())?;
Copy link
Owner

Choose a reason for hiding this comment

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

can you please keep mmap way for ELF case? ELF file can potentially be very big, there is no need to allocate so much memory for the buffer

let magic_number: u16 = u16::from_le_bytes(buffer);

// And then the full file content.
let mut contents = Vec::with_capacity(usize::try_from(file.metadata()?.len())?);
Copy link
Owner

Choose a reason for hiding this comment

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

can you add BTF::load_file() API which would detect raw vs ELF internally and just return BTF? And then use that at least for Stat command below as well. Both dump and state are frequently used (by me, at least), so would be good to keep them both in sync in terms of what they support.

@anakryiko
Copy link
Owner

@vadorovsky do you plan on posting an update for this?

@vadorovsky
Copy link
Author

@anakryiko Yes, sorry, I will address your comments later today.

@vadorovsky
Copy link
Author

(still working on that - I will try to wrap during during holidays)

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.

2 participants