You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
use crate::{common::Relocatable, error::Error};
|
|
|
|
|
|
|
|
pub struct LinkState<'data> {
|
|
|
|
pub relocatables: Vec<Box<dyn Relocatable + 'data>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'data> LinkState<'data> {
|
|
|
|
pub fn add_relocatable(
|
|
|
|
&mut self,
|
|
|
|
relocatable: Box<dyn Relocatable + 'data>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
self.relocatables.push(relocatable);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn total_size(&self) -> Result<u64, Error> {
|
|
|
|
let mut result = 0u64;
|
|
|
|
|
|
|
|
for o in self.relocatables.iter() {
|
|
|
|
for s in o.sections() {
|
|
|
|
result += s?.size()?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for LinkState<'_> {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
writeln!(f, "===Relocatables===")?;
|
|
|
|
|
|
|
|
for r in &self.relocatables {
|
|
|
|
write!(f, "{}", r)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|