mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
fix padding computations in ELF file read-in
Not sure how this even worked in the first place....I think we always just got lucky with the size of .gcc_except_table. However, something changed in the last rustc update that causes this section to align to a 256-byte boundary instead of a 4-byte boundary, which exposes downstream alignment issues. This patch now captures the actual offset alignment + padding, which is somewhat complicated by the fact that we throw away the first section (not sure why??? it doesn't seem to have a valid name or header, but the first 0x114 bytes are non-existent) so we have to factor this into all the downstream padding efforts.
This commit is contained in:
parent
9ca720f188
commit
9499a41739
1 changed files with 13 additions and 5 deletions
|
|
@ -295,12 +295,17 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
||||||
// This keeps a running offset of where data is getting copied.
|
// This keeps a running offset of where data is getting copied.
|
||||||
let mut program_offset = 0;
|
let mut program_offset = 0;
|
||||||
let mut section_iter = elf.section_iter().peekable();
|
let mut section_iter = elf.section_iter().peekable();
|
||||||
|
let mut init_offset = 0;
|
||||||
while let Some(s) = section_iter.next() {
|
while let Some(s) = section_iter.next() {
|
||||||
let mut flags = MiniElfFlags::NONE;
|
let mut flags = MiniElfFlags::NONE;
|
||||||
let name = s.get_name(&elf).unwrap_or("<<error>>");
|
let name = s.get_name(&elf).unwrap_or("<<error>>");
|
||||||
|
|
||||||
if s.address() == 0 {
|
if s.address() == 0 {
|
||||||
debug!("(Skipping section {} -- invalid address)", name);
|
debug!("(Skipping section {} -- invalid address)", name);
|
||||||
|
// only extract the initial offset once per ELF file
|
||||||
|
if init_offset == 0 {
|
||||||
|
init_offset = if let Some(s) = section_iter.peek() { s.offset() } else { 0 };
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if alignment_offset == 0 {
|
if alignment_offset == 0 {
|
||||||
|
|
@ -308,8 +313,7 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Section {}:", name);
|
debug!("Section {}:", name);
|
||||||
debug!("Official header:");
|
debug!("{} official header: {:x?}", name, s);
|
||||||
debug!("{:?}", s);
|
|
||||||
debug!("Interpreted:");
|
debug!("Interpreted:");
|
||||||
debug!(" flags: {:?}", s.flags());
|
debug!(" flags: {:?}", s.flags());
|
||||||
debug!(" type: {:?}", s.get_type());
|
debug!(" type: {:?}", s.get_type());
|
||||||
|
|
@ -354,9 +358,13 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
||||||
if s.get_type() != Ok(ShType::NoBits) {
|
if s.get_type() != Ok(ShType::NoBits) {
|
||||||
let section_data = s.raw_data(&elf);
|
let section_data = s.raw_data(&elf);
|
||||||
let pad_amount = if let Some(next_section) = section_iter.peek() {
|
let pad_amount = if let Some(next_section) = section_iter.peek() {
|
||||||
if section_data.len() % next_section.align() as usize != 0 {
|
if (section_data.len() + program_offset as usize + init_offset as usize)
|
||||||
let pad_amount =
|
% next_section.align() as usize
|
||||||
next_section.align() as usize - (section_data.len() % next_section.align() as usize);
|
!= 0
|
||||||
|
{
|
||||||
|
let pad_amount = next_section.align() as usize
|
||||||
|
- ((section_data.len() + program_offset as usize + init_offset as usize)
|
||||||
|
% next_section.align() as usize);
|
||||||
if s.address() + size + pad_amount as u64 > next_section.address() {
|
if s.address() + size + pad_amount as u64 > next_section.address() {
|
||||||
(next_section.address() - (s.address() + size)) as usize
|
(next_section.address() - (s.address() + size)) as usize
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue