|
|
@ -17,14 +17,14 @@ pub enum SegmentType {
|
|
|
|
|
|
|
|
|
|
|
|
const SEGMENT_NAMES: [&str; 4] = [".text", ".rodata", ".data", ".bss"];
|
|
|
|
const SEGMENT_NAMES: [&str; 4] = [".text", ".rodata", ".data", ".bss"];
|
|
|
|
|
|
|
|
|
|
|
|
pub struct OutputData([Vec<SectionInfo>; 4]);
|
|
|
|
pub struct OutputData([Vec<SectionInfo<(usize, usize)>>; 4]);
|
|
|
|
|
|
|
|
|
|
|
|
impl<'data> OutputData {
|
|
|
|
impl<'data> OutputData {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self([Vec::new(), Vec::new(), Vec::new(), Vec::new()])
|
|
|
|
Self([Vec::new(), Vec::new(), Vec::new(), Vec::new()])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn append_section(&mut self, section: Section) -> Result<(), Error> {
|
|
|
|
pub fn append_section(&mut self, section: Section<(usize, usize)>) -> Result<(), Error> {
|
|
|
|
match section {
|
|
|
|
match section {
|
|
|
|
Section::Text(si) => self.0[SI_TEXT].push(si),
|
|
|
|
Section::Text(si) => self.0[SI_TEXT].push(si),
|
|
|
|
Section::Data(si, false) => self.0[SI_DATA].push(si),
|
|
|
|
Section::Data(si, false) => self.0[SI_DATA].push(si),
|
|
|
@ -37,7 +37,7 @@ impl<'data> OutputData {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sections_mut(
|
|
|
|
pub fn sections_mut(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
) -> impl Iterator<Item = (&'static str, &mut Vec<SectionInfo>)> {
|
|
|
|
) -> impl Iterator<Item = (&'static str, &mut Vec<SectionInfo<(usize, usize)>>)> {
|
|
|
|
self.0
|
|
|
|
self.0
|
|
|
|
.iter_mut()
|
|
|
|
.iter_mut()
|
|
|
|
.enumerate()
|
|
|
|
.enumerate()
|
|
|
@ -50,11 +50,11 @@ impl<'data> OutputData {
|
|
|
|
|
|
|
|
|
|
|
|
let data1 = text_iter.filter_map(move |si| match si.data_index {
|
|
|
|
let data1 = text_iter.filter_map(move |si| match si.data_index {
|
|
|
|
None => None,
|
|
|
|
None => None,
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di.1)),
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di)),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let data2 = rodata_iter.filter_map(move |si| match si.data_index {
|
|
|
|
let data2 = rodata_iter.filter_map(move |si| match si.data_index {
|
|
|
|
None => None,
|
|
|
|
None => None,
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di.1)),
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di)),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let iter = data1.chain(data2);
|
|
|
|
let iter = data1.chain(data2);
|
|
|
@ -65,7 +65,7 @@ impl<'data> OutputData {
|
|
|
|
pub fn data_bytes<'l>(&'l self, objects: &'l Vec<ElfObject>) -> impl Iterator<Item = Result<&'l [u8], Error>> {
|
|
|
|
pub fn data_bytes<'l>(&'l self, objects: &'l Vec<ElfObject>) -> impl Iterator<Item = Result<&'l [u8], Error>> {
|
|
|
|
let iter = self.0[SI_DATA].iter().filter_map(move |si| match si.data_index {
|
|
|
|
let iter = self.0[SI_DATA].iter().filter_map(move |si| match si.data_index {
|
|
|
|
None => None,
|
|
|
|
None => None,
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di.1)),
|
|
|
|
Some(di) => Some(objects[di.0].section_data(di)),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
iter
|
|
|
|
iter
|
|
|
|