-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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())?; |
There was a problem hiding this comment.
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())?); |
There was a problem hiding this comment.
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.
@vadorovsky do you plan on posting an update for this? |
@anakryiko Yes, sorry, I will address your comments later today. |
(still working on that - I will try to wrap during during holidays) |
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.