Rewrite: Add elf library for elf_sections.rs#292
Conversation
…tionHeaderTable.into_iter()` & type alias
…nto SectionHeaderTable
…with an extension trait for elf::section::SectionHeader
…tionsTag was set to an invalid entry size causing the test to fail
… `ElfSectionFlags`
|
Any progress on this? |
|
Hey! thanks for pinging me! Will look into this soon - I'll put it on my list |
phip1611
left a comment
There was a problem hiding this comment.
Lovely - thanks! This is a great contribution! Only a few nits. Also, please update the changelog.
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a ElfSectionsTag> for SectionHeaderTable<'a, NativeEndian> { |
There was a problem hiding this comment.
I'm unsure about the value-add of this. It feels like a misuse of From - could you please add a motivation to the commit?
| addralign: u32, | ||
| entry_size: u32, | ||
| } | ||
| /// Extension trait for [SectionHeader] containing getters for rust-native types |
There was a problem hiding this comment.
/// Extension trait for [`SectionHeader`] containing getters for rust-native types
| entry_size: u32, | ||
| } | ||
| /// Extension trait for [SectionHeader] containing getters for rust-native types | ||
| pub trait ElfSectionExt { |
There was a problem hiding this comment.
There is only one impl for this trait. You do this to extend the type SectionHeader which comes from the elf library, yes?
| }; | ||
|
|
||
| let strtab_hdr = shdr_table.get(strtab_index).ok()?; | ||
| // todo: Should this check that `strtab_hdr.sh_type == elf::abi::SHT_STRTAB`? |
| // Casting through `usize` will not truncate data on 32bit systems because the multiboot2 loads all sections below u32::MAX | ||
| Some(unsafe { | ||
| core::slice::from_raw_parts( | ||
| strtab_hdr.sh_addr as usize as *const u8, |
There was a problem hiding this comment.
I think this should be:
core::ptr::with_exposed_provenance(strtab_hdr.sh_addr as usize)
which is the more future-proof API
This is a complete rewrite from #290, using
elf::sections::SectionHeaderTableto construct the iterator. Unlike #290 however, I decided not to care about version compatibility. This removes or replaces a number of existing functions.One change in particular is how to fetch the section name. The existing method in my opinion is flawed, if the ELF sections are relocated then it's not possible to get the name. I've changed this so the string table must be fetched separately, which can then be passed to a helper. This helper returns a
&core::ffi::CStrinstead of a&str, the ELF specification doesn't define the character encoding so we should not force it to be Unicode.An important behavioral change that isn't obvious is that "unused" (
SHT_NULL) sections are no longer skipped. This threw me for a loop during testing. If they're there it's probably there for a reason, so I think its a bad idea to skip it, especially if you can just use.filter(_).