diff --git a/src/common/output.rs b/src/common/output.rs index b3efc8c..00f52e7 100644 --- a/src/common/output.rs +++ b/src/common/output.rs @@ -11,19 +11,3 @@ where fn finalize(self, objects: &[R]) -> Result; } - -pub struct DummyOutput; - -impl Output for DummyOutput -where - R: Relocatable, -{ - fn process_section(&mut self, section: Section) -> Result<(), Error> { - eprintln!("Appending section: {}", section); - Ok(()) - } - - fn finalize(self, _objects: &[R]) -> Result { - todo!(); - } -} diff --git a/src/formats/elf.rs b/src/formats/elf.rs index ce423ad..2766567 100644 --- a/src/formats/elf.rs +++ b/src/formats/elf.rs @@ -6,7 +6,7 @@ use crate::linker::Linker; mod object; mod output; -mod segment; +mod loadable; use elf_utilities::file::ELF64; pub use object::*; diff --git a/src/formats/elf/segment.rs b/src/formats/elf/loadable.rs similarity index 94% rename from src/formats/elf/segment.rs rename to src/formats/elf/loadable.rs index cbb8c18..a95bd7b 100644 --- a/src/formats/elf/segment.rs +++ b/src/formats/elf/loadable.rs @@ -15,15 +15,15 @@ pub enum SegmentType { type SegmentSections = Vec>; #[derive(Default)] -pub struct SegmentView { +pub struct Loadable { text: SegmentSections, rodata: SegmentSections, data: SegmentSections, bss: SegmentSections, } -impl<'data> SegmentView { - pub fn append_section(&mut self, section: Section<(usize, usize)>) -> Result<(), Error> { +impl<'data> Loadable { + pub fn process_section(&mut self, section: Section<(usize, usize)>) -> Result<(), Error> { match section { Section::Text(si) => self.text.push(si), Section::Data(si, true) => self.rodata.push(si), diff --git a/src/formats/elf/output.rs b/src/formats/elf/output.rs index d75ee24..6557799 100644 --- a/src/formats/elf/output.rs +++ b/src/formats/elf/output.rs @@ -19,13 +19,13 @@ use crate::{ error::Error, }; -use super::segment::*; +use super::loadable::*; use super::ElfObject; pub struct ElfOutput { destination: PathBuf, file: ELF64, - segment_view: SegmentView, + loadable: Loadable, writer: BufWriter, } @@ -48,7 +48,7 @@ impl ElfOutput { let result = Self { destination, file: elf, - segment_view: SegmentView::default(), + loadable: Loadable::default(), writer, }; @@ -59,7 +59,7 @@ impl ElfOutput { let mut names = Vec::new(); let mut name_idx = 0usize; - for (name, sections) in self.segment_view.sections_mut() { + for (name, sections) in self.loadable.sections_mut() { let mut data_size = 0; for t in sections.iter() { @@ -131,17 +131,17 @@ impl ElfOutput { // contains .text + .rodata as one segment self.populate_segment( &mut offset, - self.segment_view.program_size(), + self.loadable.program_size(), SegmentType::Text, ); // contains .data as one segment self.populate_segment( &mut offset, - self.segment_view.data_size(), + self.loadable.data_size(), SegmentType::Data, ); // contains .bss as one segment - self.populate_segment(&mut offset, self.segment_view.bss_size(), SegmentType::Bss); + self.populate_segment(&mut offset, self.loadable.bss_size(), SegmentType::Bss); Ok(offset) } @@ -149,7 +149,7 @@ impl ElfOutput { impl Output for ElfOutput { fn process_section(&mut self, section: Section<(usize, usize)>) -> Result<(), Error> { - self.segment_view.append_section(section) + self.loadable.process_section(section) } fn finalize(mut self, objects: &[ElfObject]) -> Result { @@ -195,13 +195,13 @@ impl Output for ElfOutput { offset += pad_to_next_page(&mut self.writer, offset)?; eprintln!("Prog start: {}", offset); // write section/segment data - for bytes in self.segment_view.program_bytes(objects) { + for bytes in self.loadable.program_bytes(objects) { offset += self.writer.write(bytes?)?; } offset += pad_to_next_page(&mut self.writer, offset)?; eprintln!("Data start: {}", offset); - for bytes in self.segment_view.data_bytes(objects) { + for bytes in self.loadable.data_bytes(objects) { offset += self.writer.write(bytes?)?; }