Skip to main content

write

Function write 

Source
pub fn write(object: &Object) -> Result<Vec<u8>, WriteError>
Expand description

Writes an object as an ELF file and returns the bytes.

The object is validated first. The output is deterministic.

§Errors

§Examples

use object_lang::{Architecture, Object, Section, SectionKind, Symbol};

let mut obj = Object::relocatable(Architecture::X86_64);
let text = obj.add_section(Section::new(".text", SectionKind::Text).with_data(vec![0xc3]));
obj.add_symbol(Symbol::function("ret", text, 0, 1));

let bytes = object_lang::elf::write(&obj)?;
assert_eq!(&bytes[..4], b"\x7fELF");
assert_eq!(object_lang::elf::read(&bytes)?, obj);