diff --git a/src/common/output.rs b/src/common/output.rs index e81eb34..3dd12a8 100644 --- a/src/common/output.rs +++ b/src/common/output.rs @@ -5,7 +5,7 @@ use crate::error::Error; pub trait Output where - R: Relocatable + R: Relocatable, { fn process_section(&mut self, section: Section) -> Result<(), Error>; @@ -16,7 +16,7 @@ pub struct DummyOutput; impl Output for DummyOutput where - R: Relocatable + R: Relocatable, { fn process_section(&mut self, section: Section) -> Result<(), Error> { eprintln!("Appending section: {}", section); diff --git a/src/formats/elf/object.rs b/src/formats/elf/object.rs index a3f1868..2436fb0 100644 --- a/src/formats/elf/object.rs +++ b/src/formats/elf/object.rs @@ -1,4 +1,8 @@ -use std::{convert::TryFrom, fmt::Display, path::{Path, PathBuf}}; +use std::{ + convert::TryFrom, + fmt::Display, + path::{Path, PathBuf}, +}; use crate::common::{Relocatable, Section, SectionInfo}; use crate::{common::BSI, error::Error}; @@ -41,46 +45,46 @@ impl Relocatable for ElfObject { fn sections<'iter>(self: &'iter Self) -> BSI<'iter, (usize, usize)> { use elf_utilities::section::{Contents64, Type}; - let iter = self - .elf - .sections - .iter() - .enumerate() - .filter_map(|(i, s)| match s.header.get_type() { - Type::ProgBits => { - if s.header.sh_size > 0 { - if let Some(di) = match &s.contents { - Contents64::Raw(v) => Some(v), - _ => None, - } { - let si = SectionInfo { - file_size: s.header.sh_size, - data_size: s.header.sh_size, - data_index: Some((0, i)), // TODO - offset: s.header.sh_offset, - }; - let s_name: &str = &s.name; - - match Section::try_from((s_name, si)) { - Ok(s) => Some(Ok(s)), - Err(Error::InvalidSectionName) => None, // skip - Err(err) => Some(Err(err)), + let iter = + self.elf + .sections + .iter() + .enumerate() + .filter_map(|(i, s)| match s.header.get_type() { + Type::ProgBits => { + if s.header.sh_size > 0 { + if let Some(di) = match &s.contents { + Contents64::Raw(v) => Some(v), + _ => None, + } { + let si = SectionInfo { + file_size: s.header.sh_size, + data_size: s.header.sh_size, + data_index: Some((0, i)), // TODO + offset: s.header.sh_offset, + }; + let s_name: &str = &s.name; + + match Section::try_from((s_name, si)) { + Ok(s) => Some(Ok(s)), + Err(Error::InvalidSectionName) => None, // skip + Err(err) => Some(Err(err)), + } + } else { + Some(Err(Error::InvalidSectionData)) } } else { - Some(Err(Error::InvalidSectionData)) + None } - } else { - None } - } - Type::NoBits => Some(Ok(Section::Bss(SectionInfo { - file_size: 0, - data_size: s.header.sh_size, - data_index: None, - offset: s.header.sh_offset, - }))), - _ => None, - }); + Type::NoBits => Some(Ok(Section::Bss(SectionInfo { + file_size: 0, + data_size: s.header.sh_size, + data_index: None, + offset: s.header.sh_offset, + }))), + _ => None, + }); Box::new(iter) } @@ -91,7 +95,7 @@ impl Relocatable for ElfObject { match §ion.contents { Contents64::Raw(v) => Ok(&v), - _ => Err(Error::InvalidSectionData) + _ => Err(Error::InvalidSectionData), } } } diff --git a/src/formats/elf/segment.rs b/src/formats/elf/segment.rs index 3d7769f..d122127 100644 --- a/src/formats/elf/segment.rs +++ b/src/formats/elf/segment.rs @@ -1,5 +1,5 @@ -use crate::common::{Relocatable, Section}; use crate::common::SectionInfo; +use crate::common::{Relocatable, Section}; use crate::error::Error; use super::ElfObject; @@ -44,7 +44,10 @@ impl<'data> OutputData { .map(|(i, s)| (SEGMENT_NAMES[i], s)) } - pub fn program_bytes<'l>(&'l self, objects: &'l Vec) -> impl Iterator> { + pub fn program_bytes<'l>( + &'l self, + objects: &'l Vec, + ) -> impl Iterator> { let text_iter = self.0[SI_TEXT].iter(); let rodata_iter = self.0[SI_RODATA].iter(); @@ -62,11 +65,16 @@ impl<'data> OutputData { iter } - pub fn data_bytes<'l>(&'l self, objects: &'l Vec) -> impl Iterator> { - let iter = self.0[SI_DATA].iter().filter_map(move |si| match si.data_index { - None => None, - Some(di) => Some(objects[di.0].section_data(di)), - }); + pub fn data_bytes<'l>( + &'l self, + objects: &'l Vec, + ) -> impl Iterator> { + let iter = self.0[SI_DATA] + .iter() + .filter_map(move |si| match si.data_index { + None => None, + Some(di) => Some(objects[di.0].section_data(di)), + }); iter } diff --git a/src/linker.rs b/src/linker.rs index 3c7d94e..7638c9e 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -1,4 +1,8 @@ -use std::{fmt::Display, io::ErrorKind, path::{Path, PathBuf}}; +use std::{ + fmt::Display, + io::ErrorKind, + path::{Path, PathBuf}, +}; use crate::{ common::{Output, Relocatable},