Struct wasmer_compiler::object::Object

pub struct Object<'a> {
Show 15 fields format: BinaryFormat, architecture: Architecture, sub_architecture: Option<SubArchitecture>, endian: Endianness, sections: Vec<Section<'a>>, standard_sections: HashMap<StandardSection, SectionId>, symbols: Vec<Symbol>, symbol_map: HashMap<Vec<u8>, SymbolId>, stub_symbols: HashMap<SymbolId, SymbolId>, comdats: Vec<Comdat>, pub flags: FileFlags, pub mangling: Mangling, tlv_bootstrap: Option<SymbolId>, macho_cpu_subtype: Option<u32>, macho_build_version: Option<MachOBuildVersion>,
}
Expand description

A writable relocatable object file.

Fields§

§format: BinaryFormat§architecture: Architecture§sub_architecture: Option<SubArchitecture>§endian: Endianness§sections: Vec<Section<'a>>§standard_sections: HashMap<StandardSection, SectionId>§symbols: Vec<Symbol>§symbol_map: HashMap<Vec<u8>, SymbolId>§stub_symbols: HashMap<SymbolId, SymbolId>§comdats: Vec<Comdat>§flags: FileFlags

File flags that are specific to each file format.

§mangling: Mangling

The symbol name mangling scheme.

§tlv_bootstrap: Option<SymbolId>§macho_cpu_subtype: Option<u32>§macho_build_version: Option<MachOBuildVersion>

Implementations§

§

impl<'a> Object<'a>

pub fn add_coff_exports(&mut self, style: CoffExportStyle)

Appends linker directives to the .drectve section to tell the linker to export all symbols with SymbolScope::Dynamic.

This must be called after all symbols have been defined.

§

impl<'a> Object<'a>

pub fn add_elf_gnu_property_u32(&mut self, property: u32, value: u32)

Add a property with a u32 value to the ELF “.note.gnu.property” section.

Requires feature = "elf".

§

impl<'a> Object<'a>

pub fn set_macho_cpu_subtype(&mut self, cpu_subtype: u32)

Specify the Mach-O CPU subtype.

Requires feature = "macho".

pub fn set_macho_build_version(&mut self, info: MachOBuildVersion)

Specify information for a Mach-O LC_BUILD_VERSION command.

Requires feature = "macho".

§

impl<'a> Object<'a>

pub fn new( format: BinaryFormat, architecture: Architecture, endian: Endianness, ) -> Object<'a>

Create an empty object file.

pub fn format(&self) -> BinaryFormat

Return the file format.

pub fn architecture(&self) -> Architecture

Return the architecture.

pub fn sub_architecture(&self) -> Option<SubArchitecture>

Return the sub-architecture.

pub fn set_sub_architecture( &mut self, sub_architecture: Option<SubArchitecture>, )

Specify the sub-architecture.

pub fn mangling(&self) -> Mangling

Return the current mangling setting.

pub fn set_mangling(&mut self, mangling: Mangling)

Specify the mangling setting.

pub fn segment_name(&self, segment: StandardSegment) -> &'static [u8]

Return the name for a standard segment.

This will vary based on the file format.

pub fn section(&self, section: SectionId) -> &Section<'a>

Get the section with the given SectionId.

pub fn section_mut(&mut self, section: SectionId) -> &mut Section<'a>

Mutably get the section with the given SectionId.

pub fn set_section_data<T>(&mut self, section: SectionId, data: T, align: u64)
where T: Into<Cow<'a, [u8]>>,

Set the data for an existing section.

Must not be called for sections that already have data, or that contain uninitialized data.

pub fn append_section_data( &mut self, section: SectionId, data: &[u8], align: u64, ) -> u64

Append data to an existing section. Returns the section offset of the data.

pub fn append_section_bss( &mut self, section: SectionId, size: u64, align: u64, ) -> u64

Append zero-initialized data to an existing section. Returns the section offset of the data.

pub fn section_id(&mut self, section: StandardSection) -> SectionId

Return the SectionId of a standard section.

If the section doesn’t already exist then it is created.

pub fn add_section( &mut self, segment: Vec<u8>, name: Vec<u8>, kind: SectionKind, ) -> SectionId

Add a new section and return its SectionId.

This also creates a section symbol.

pub fn add_subsection( &mut self, section: StandardSection, name: &[u8], data: &[u8], align: u64, ) -> (SectionId, u64)

Add a subsection. Returns the SectionId and section offset of the data.

pub fn comdat(&self, comdat: ComdatId) -> &Comdat

Get the COMDAT section group with the given ComdatId.

pub fn comdat_mut(&mut self, comdat: ComdatId) -> &mut Comdat

Mutably get the COMDAT section group with the given ComdatId.

pub fn add_comdat(&mut self, comdat: Comdat) -> ComdatId

Add a new COMDAT section group and return its ComdatId.

pub fn symbol_id(&self, name: &[u8]) -> Option<SymbolId>

Get the SymbolId of the symbol with the given name.

pub fn symbol(&self, symbol: SymbolId) -> &Symbol

Get the symbol with the given SymbolId.

pub fn symbol_mut(&mut self, symbol: SymbolId) -> &mut Symbol

Mutably get the symbol with the given SymbolId.

pub fn add_symbol(&mut self, symbol: Symbol) -> SymbolId

Add a new symbol and return its SymbolId.

pub fn has_uninitialized_tls(&self) -> bool

Return true if the file format supports StandardSection::UninitializedTls.

pub fn has_common(&self) -> bool

Return true if the file format supports StandardSection::Common.

pub fn add_common_symbol( &mut self, symbol: Symbol, size: u64, align: u64, ) -> SymbolId

Add a new common symbol and return its SymbolId.

For Mach-O, this appends the symbol to the __common section.

pub fn add_file_symbol(&mut self, name: Vec<u8>) -> SymbolId

Add a new file symbol and return its SymbolId.

pub fn section_symbol(&mut self, section_id: SectionId) -> SymbolId

Get the symbol for a section.

pub fn add_symbol_data( &mut self, symbol_id: SymbolId, section: SectionId, data: &[u8], align: u64, ) -> u64

Append data to an existing section, and update a symbol to refer to it.

For Mach-O, this also creates a __thread_vars entry for TLS symbols, and the symbol will indirectly point to the added data via the __thread_vars entry.

Returns the section offset of the data.

pub fn add_symbol_bss( &mut self, symbol_id: SymbolId, section: SectionId, size: u64, align: u64, ) -> u64

Append zero-initialized data to an existing section, and update a symbol to refer to it.

For Mach-O, this also creates a __thread_vars entry for TLS symbols, and the symbol will indirectly point to the added data via the __thread_vars entry.

Returns the section offset of the data.

pub fn set_symbol_data( &mut self, symbol_id: SymbolId, section: SectionId, offset: u64, size: u64, )

Update a symbol to refer to the given data within a section.

For Mach-O, this also creates a __thread_vars entry for TLS symbols, and the symbol will indirectly point to the data via the __thread_vars entry.

pub fn symbol_section_and_offset( &mut self, symbol_id: SymbolId, ) -> Option<(SymbolId, u64)>

Convert a symbol to a section symbol and offset.

Returns None if the symbol does not have a section.

pub fn add_relocation( &mut self, section: SectionId, relocation: Relocation, ) -> Result<(), Error>

Add a relocation to a section.

Relocations must only be added after the referenced symbols have been added and defined (if applicable).

pub fn write(&self) -> Result<Vec<u8>, Error>

Write the object to a Vec.

pub fn write_stream<W>(&self, w: W) -> Result<(), Box<dyn Error>>
where W: Write,

Write the object to a Write implementation.

Also flushes the writer.

It is advisable to use a buffered writer like BufWriter instead of an unbuffered writer like File.

pub fn emit(&self, buffer: &mut dyn WritableBuffer) -> Result<(), Error>

Write the object to a WritableBuffer.

Trait Implementations§

§

impl<'a> Debug for Object<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Object<'a>

§

impl<'a> RefUnwindSafe for Object<'a>

§

impl<'a> Send for Object<'a>

§

impl<'a> Sync for Object<'a>

§

impl<'a> Unpin for Object<'a>

§

impl<'a> UnwindSafe for Object<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn