|
|
|
@ -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<File>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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<ElfObject> 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<PathBuf, Error> {
|
|
|
|
@ -195,13 +195,13 @@ impl Output<ElfObject> 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?)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|