#[path = "support/objects.rs"]
mod objects;
use std::sync::{Arc, Mutex};
use qld::args::{InputAttrs, InputKind, LinkOptions, OutputKind, TextOutput};
use qld::diag::Collect;
fn main() -> qld::Result<()> {
let mut options = LinkOptions::new();
options.kind = OutputKind::StaticExecutable;
options.push_input(
InputKind::bytes("main.o", objects::main_object()),
InputAttrs::default(),
);
options.push_input(
InputKind::bytes("answer.o", objects::answer_object(42)),
InputAttrs::default(),
);
options.print_map = true;
options.cref = true;
let map = Arc::new(Mutex::new(String::new()));
let collected = Arc::clone(&map);
options.map_output = Some(TextOutput::new(move |text| {
collected.lock().unwrap().push_str(text);
}));
let image = qld::link_to_memory(&options, &Collect::new())?;
let map = map.lock().unwrap();
println!("linked {} bytes, {} of map", image.len(), map.len());
for line in map.lines().take(8) {
println!(" {line}");
}
let mut as_the_binary = options.clone();
as_the_binary.use_process_defaults();
println!(
"\nhermetic: map_output {}, LD_LIBRARY_PATH {} entries, timing {}",
if options.map_output.is_some() {
"set by this program"
} else {
"unset"
},
options.env_library_path.len(),
if options.timing.is_some() {
"on"
} else {
"off"
},
);
println!(
"as the binary: LD_LIBRARY_PATH {} entries, timing {}",
as_the_binary.env_library_path.len(),
if as_the_binary.timing.is_some() {
"on"
} else {
"off"
},
);
Ok(())
}