pub struct Image { /* private fields */ }Expand description
The linked image produced by a compile, re-exported from
linker-lang. It carries the laid-out code sections, the resolved
symbol table, and the entry point.
A linked image: the laid-out sections, the resolved symbol table, and the entry point.
An image is what link produces on success. Its
sections are placed at fixed addresses with their relocations
patched; its symbol table maps every defined name to the address it resolved to; and
its entry is the address of the configured entry point, if any. Look
up an address with symbol, or read a section’s bytes with
section.
The Display implementation renders a readable link map: the entry
point, each section with its address and size, and the symbol table sorted by name.
§Examples
use linker_lang::{Linker, Object};
let mut obj = Object::new("o");
obj.section(".text", [0u8; 8]);
obj.define("main", ".text", 0);
obj.define("loop", ".text", 4);
let image = Linker::new().entry("main").link(&[obj]).unwrap();
assert_eq!(image.symbol("main"), Some(0));
assert_eq!(image.symbol("loop"), Some(4));
assert_eq!(image.entry(), Some(0));
assert_eq!(image.symbols().count(), 2);Implementations§
Source§impl Image
impl Image
Sourcepub fn sections(&self) -> &[OutputSection]
pub fn sections(&self) -> &[OutputSection]
Returns the laid-out sections, in address order.
Sourcepub fn section(&self, name: &str) -> Option<&OutputSection>
pub fn section(&self, name: &str) -> Option<&OutputSection>
Returns the section named name, or None if the image has no such section.
§Examples
use linker_lang::{link, Object};
let mut obj = Object::new("o");
obj.section(".data", [7, 7]);
let image = link(&[obj]).unwrap();
assert!(image.section(".data").is_some());
assert!(image.section(".bss").is_none());Sourcepub fn symbol(&self, name: &str) -> Option<u64>
pub fn symbol(&self, name: &str) -> Option<u64>
Returns the resolved address of the symbol named name, or None if no object
defined it.
§Examples
use linker_lang::{link, Object};
let mut obj = Object::new("o");
obj.section(".text", [0u8; 4]);
obj.define("f", ".text", 2);
let image = link(&[obj]).unwrap();
assert_eq!(image.symbol("f"), Some(2));
assert_eq!(image.symbol("missing"), None);Sourcepub fn symbols(&self) -> impl Iterator<Item = (&str, u64)>
pub fn symbols(&self) -> impl Iterator<Item = (&str, u64)>
Returns the symbol table as (name, address) pairs, sorted by name.
§Examples
use linker_lang::{link, Object};
let mut obj = Object::new("o");
obj.section(".text", [0u8; 8]);
obj.define("b", ".text", 4);
obj.define("a", ".text", 0);
let image = link(&[obj]).unwrap();
let names: Vec<&str> = image.symbols().map(|(name, _)| name).collect();
assert_eq!(names, ["a", "b"]); // sorted, not insertion orderSourcepub const fn entry(&self) -> Option<u64>
pub const fn entry(&self) -> Option<u64>
Returns the address of the entry point, or None if the link was not configured
with one. See Linker::entry.