monistode_binutils/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pub mod address;
pub mod definition;
pub mod executable;
pub mod object_file;
pub mod serializable;
pub mod symbols;

pub use address::Address;
pub use definition::{Definition, RawDefinition};
pub use executable::Executable;
pub use object_file::ObjectFile;
pub use serializable::{Architecture, Serializable, SerializationError};
pub use symbols::{Symbol, SymbolTable};

use object_file::placed::{LinkerError, PlacedSection, Placement};

impl TryFrom<ObjectFile> for Executable {
    type Error = LinkerError;

    fn try_from(object: ObjectFile) -> Result<Self, Self::Error> {
        let architecture = object.architecture();
        let mut placed = Placement::new(
            object
                .sections()
                .into_iter()
                .map(|section| PlacedSection::new(section))
                .collect(),
            architecture,
        );
        placed.place();
        return Ok(Executable::new(architecture, placed.as_segments()?));
    }
}