refactor loadable to be generic

master
Ales Katona 4 years ago
parent 3b3f834a2f
commit 0b5f013323
Signed by: almindor
GPG Key ID: 2F773149BF38B48F

@ -1,10 +1,12 @@
mod lazy; mod lazy;
mod loadable;
mod output; mod output;
mod relocatable; mod relocatable;
mod section; mod section;
mod symbol; mod symbol;
pub use lazy::*; pub use lazy::*;
pub use loadable::*;
pub use output::*; pub use output::*;
pub use relocatable::*; pub use relocatable::*;
pub use section::*; pub use section::*;

@ -4,8 +4,6 @@ use crate::common::SectionInfo;
use crate::common::{Relocatable, Section}; use crate::common::{Relocatable, Section};
use crate::error::Error; use crate::error::Error;
use super::ElfObject;
pub enum SegmentType { pub enum SegmentType {
Text, Text,
Data, Data,
@ -43,9 +41,9 @@ impl Loadable {
text.chain(rodata).chain(data).chain(bss) text.chain(rodata).chain(data).chain(bss)
} }
pub fn program_bytes<'l>( pub fn program_bytes<'l, R: Relocatable>(
&'l self, &'l self,
objects: &'l [ElfObject], objects: &'l [R],
) -> impl Iterator<Item = Result<&'l [u8], Error>> { ) -> impl Iterator<Item = Result<&'l [u8], Error>> {
let text_iter = self.text.iter(); let text_iter = self.text.iter();
let rodata_iter = self.rodata.iter(); let rodata_iter = self.rodata.iter();
@ -62,9 +60,9 @@ impl Loadable {
data1.chain(data2) data1.chain(data2)
} }
pub fn data_bytes<'l>( pub fn data_bytes<'l, R: Relocatable>(
&'l self, &'l self,
objects: &'l [ElfObject], objects: &'l [R],
) -> impl Iterator<Item = Result<&'l [u8], Error>> { ) -> impl Iterator<Item = Result<&'l [u8], Error>> {
let iter = self.data.iter().filter_map(move |si| match si.data_index { let iter = self.data.iter().filter_map(move |si| match si.data_index {
None => None, None => None,

@ -6,7 +6,6 @@ use crate::linker::Linker;
mod object; mod object;
mod output; mod output;
mod loadable;
use elf_utilities::file::ELF64; use elf_utilities::file::ELF64;
pub use object::*; pub use object::*;

@ -14,12 +14,8 @@ use elf_utilities::{
segment::{Phdr64, Segment64, Type as SeType, PF_R, PF_W, PF_X}, segment::{Phdr64, Segment64, Type as SeType, PF_R, PF_W, PF_X},
}; };
use crate::{ use crate::{common::{Loadable, Output, Section, SegmentType}, error::Error};
common::{Output, Section},
error::Error,
};
use super::loadable::*;
use super::ElfObject; use super::ElfObject;
pub struct ElfOutput { pub struct ElfOutput {

Loading…
Cancel
Save