[−][src]Struct faerie::artifact::Artifact
An abstract binary artifact, which contains code, data, imports, and relocations
Fields
name: String
The name of this artifact
target: Triple
The machine target this is intended for
is_library: bool
Whether this is a static library or not
Implementations
impl Artifact
[src]
pub fn new(target: Triple, name: String) -> Self
[src]
Create a new binary Artifact, with target
and optional name
pub fn imports<'a>(
&'a self
) -> Box<dyn Iterator<Item = (&'a str, &'a ImportKind)> + 'a>
[src]
&'a self
) -> Box<dyn Iterator<Item = (&'a str, &'a ImportKind)> + 'a>
Get an iterator over this artifact's imports
pub fn declare_with<T: AsRef<str>, D: Into<Decl>>(
&mut self,
name: T,
decl: D,
definition: Vec<u8>
) -> Result<(), ArtifactError>
[src]
&mut self,
name: T,
decl: D,
definition: Vec<u8>
) -> Result<(), ArtifactError>
Declare and define a new symbolic reference with the given decl
and given definition
.
This is sugar for declare
and then define
pub fn declare<T: AsRef<str>, D: Into<Decl>>(
&mut self,
name: T,
decl: D
) -> Result<(), ArtifactError>
[src]
&mut self,
name: T,
decl: D
) -> Result<(), ArtifactError>
Declare a new symbolic reference, with the given decl
.
Note: All declarations must precede their definitions.
pub fn declarations<T: AsRef<str>, D: Iterator<Item = (T, Decl)>>(
&mut self,
declarations: D
) -> Result<(), ArtifactError>
[src]
&mut self,
declarations: D
) -> Result<(), ArtifactError>
pub fn define<T: AsRef<str>>(
&mut self,
name: T,
data: Vec<u8>
) -> Result<(), ArtifactError>
[src]
&mut self,
name: T,
data: Vec<u8>
) -> Result<(), ArtifactError>
Defines a previously declared program object with the given data. NB: If you attempt to define an import, this will return an error. If you attempt to define something which has not been declared, this will return an error.
See the documentation for Data
for the difference
from define_zero_init
.
pub fn define_zero_init<T: AsRef<str>>(
&mut self,
name: T,
size: usize
) -> Result<(), ArtifactError>
[src]
&mut self,
name: T,
size: usize
) -> Result<(), ArtifactError>
Defines a previously declared program object with all zeros. NB: If you attempt to define an import, this will return an error. If you attempt to define something which has not been declared, this will return an error.
pub fn define_with_symbols<T: AsRef<str>, D: Into<Data>>(
&mut self,
name: T,
data: D,
symbols: BTreeMap<String, u64>
) -> Result<(), ArtifactError>
[src]
&mut self,
name: T,
data: D,
symbols: BTreeMap<String, u64>
) -> Result<(), ArtifactError>
Same as define
but also allows to add custom symbols referencing a section decl.
Examples
Create a MachO file with a section called .my_section
. This section has the content
de ad be ef
, with the symbol a_symbol
referencing to be
.
let mut artifact = Artifact::new(target_lexicon::triple!("x86_64-apple-darwin"), "example".to_string()); artifact.declare(".my_section", Decl::section(SectionKind::Data)).unwrap(); let mut section_symbols = BTreeMap::new(); section_symbols.insert("a_symbol".to_string(), 2); artifact.define_with_symbols(".my_section", Data::Blob(vec![0xde, 0xad, 0xbe, 0xef]), section_symbols).unwrap(); let _blob = artifact.emit().unwrap();
pub fn import<T: AsRef<str>>(
&mut self,
import: T,
kind: ImportKind
) -> Result<(), ArtifactError>
[src]
&mut self,
import: T,
kind: ImportKind
) -> Result<(), ArtifactError>
Declare import
to be an import with kind
.
This is just sugar for declare("name", Decl::FunctionImport)
or declare("data", Decl::DataImport)
pub fn link<'a>(&mut self, link: Link<'a>) -> Result<(), ArtifactError>
[src]
Link a relocation at link.at
from link.from
to link.to
NB: If either link.from
or link.to
is undeclared, then this will return an error.
If link.from
is an import you previously declared, this will also return an error.
pub fn link_with<'a>(
&mut self,
link: Link<'a>,
reloc: Reloc
) -> Result<(), ArtifactError>
[src]
&mut self,
link: Link<'a>,
reloc: Reloc
) -> Result<(), ArtifactError>
A variant of link
with a Reloc
provided. Has all of the same invariants as
link
.
pub fn undefined_symbols(&self) -> Vec<String>
[src]
Get set of non-import declarations that have not been defined. This must be an empty set in
order to emit
the artifact.
pub fn emit(&self) -> Result<Vec<u8>, ArtifactError>
[src]
Emit a blob of bytes representing the object file in the format specified in the target the
Artifact
was constructed with.
pub fn emit_as(&self, format: BinaryFormat) -> Result<Vec<u8>, ArtifactError>
[src]
Emit a blob of bytes representing an object file in the given format.
pub fn write(&self, sink: File) -> Result<(), ArtifactError>
[src]
Emit and write to disk a blob of bytes representing the object file in the format specified
in the target the Artifact
was constructed with.
pub fn write_as(
&self,
sink: File,
format: BinaryFormat
) -> Result<(), ArtifactError>
[src]
&self,
sink: File,
format: BinaryFormat
) -> Result<(), ArtifactError>
Emit and write to disk a blob of bytes representing an object file in the given format.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Artifact
impl Send for Artifact
impl Sync for Artifact
impl Unpin for Artifact
impl UnwindSafe for Artifact
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,