pub struct Object<'a> {
pub flags: FileFlags,
pub mangling: Mangling,
/* private fields */
}
Expand description
A writable object file.
Fields§
§flags: FileFlags
File flags that are specific to each file format.
mangling: Mangling
The symbol name mangling scheme.
Implementations§
source§impl<'a> Object<'a>
impl<'a> Object<'a>
sourcepub fn add_coff_exports(&mut self, style: CoffExportStyle)
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.
source§impl<'a> Object<'a>
impl<'a> Object<'a>
sourcepub fn new(
format: BinaryFormat,
architecture: Architecture,
endian: Endianness,
) -> Object<'a>
pub fn new( format: BinaryFormat, architecture: Architecture, endian: Endianness, ) -> Object<'a>
Create an empty object file.
sourcepub fn format(&self) -> BinaryFormat
pub fn format(&self) -> BinaryFormat
Return the file format.
sourcepub fn architecture(&self) -> Architecture
pub fn architecture(&self) -> Architecture
Return the architecture.
sourcepub fn set_mangling(&mut self, mangling: Mangling)
pub fn set_mangling(&mut self, mangling: Mangling)
Specify the mangling setting.
sourcepub fn segment_name(&self, segment: StandardSegment) -> &'static [u8] ⓘ
pub fn segment_name(&self, segment: StandardSegment) -> &'static [u8] ⓘ
Return the name for a standard segment.
This will vary based on the file format.
sourcepub fn section(&self, section: SectionId) -> &Section<'a>
pub fn section(&self, section: SectionId) -> &Section<'a>
Get the section with the given SectionId
.
sourcepub fn section_mut(&mut self, section: SectionId) -> &mut Section<'a>
pub fn section_mut(&mut self, section: SectionId) -> &mut Section<'a>
Mutably get the section with the given SectionId
.
sourcepub fn set_section_data<T>(&mut self, section: SectionId, data: T, align: u64)
pub fn set_section_data<T>(&mut self, section: SectionId, data: T, align: u64)
Set the data for an existing section.
Must not be called for sections that already have data, or that contain uninitialized data.
sourcepub fn append_section_data(
&mut self,
section: SectionId,
data: &[u8],
align: u64,
) -> u64
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.
sourcepub fn append_section_bss(
&mut self,
section: SectionId,
size: u64,
align: u64,
) -> u64
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.
sourcepub fn section_id(&mut self, section: StandardSection) -> SectionId
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.
sourcepub fn add_section(
&mut self,
segment: Vec<u8>,
name: Vec<u8>,
kind: SectionKind,
) -> SectionId
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.
sourcepub fn add_subsection(
&mut self,
section: StandardSection,
name: &[u8],
data: &[u8],
align: u64,
) -> (SectionId, u64)
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.
sourcepub fn comdat(&self, comdat: ComdatId) -> &Comdat
pub fn comdat(&self, comdat: ComdatId) -> &Comdat
Get the COMDAT section group with the given ComdatId
.
sourcepub fn comdat_mut(&mut self, comdat: ComdatId) -> &mut Comdat
pub fn comdat_mut(&mut self, comdat: ComdatId) -> &mut Comdat
Mutably get the COMDAT section group with the given ComdatId
.
sourcepub fn add_comdat(&mut self, comdat: Comdat) -> ComdatId
pub fn add_comdat(&mut self, comdat: Comdat) -> ComdatId
Add a new COMDAT section group and return its ComdatId
.
sourcepub fn symbol_id(&self, name: &[u8]) -> Option<SymbolId>
pub fn symbol_id(&self, name: &[u8]) -> Option<SymbolId>
Get the SymbolId
of the symbol with the given name.
sourcepub fn symbol_mut(&mut self, symbol: SymbolId) -> &mut Symbol
pub fn symbol_mut(&mut self, symbol: SymbolId) -> &mut Symbol
Mutably get the symbol with the given SymbolId
.
sourcepub fn add_symbol(&mut self, symbol: Symbol) -> SymbolId
pub fn add_symbol(&mut self, symbol: Symbol) -> SymbolId
Add a new symbol and return its SymbolId
.
sourcepub fn has_uninitialized_tls(&self) -> bool
pub fn has_uninitialized_tls(&self) -> bool
Return true if the file format supports StandardSection::UninitializedTls
.
sourcepub fn has_common(&self) -> bool
pub fn has_common(&self) -> bool
Return true if the file format supports StandardSection::Common
.
sourcepub fn add_common_symbol(
&mut self,
symbol: Symbol,
size: u64,
align: u64,
) -> SymbolId
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.
sourcepub fn add_file_symbol(&mut self, name: Vec<u8>) -> SymbolId
pub fn add_file_symbol(&mut self, name: Vec<u8>) -> SymbolId
Add a new file symbol and return its SymbolId
.
sourcepub fn section_symbol(&mut self, section_id: SectionId) -> SymbolId
pub fn section_symbol(&mut self, section_id: SectionId) -> SymbolId
Get the symbol for a section.
sourcepub fn add_symbol_data(
&mut self,
symbol_id: SymbolId,
section: SectionId,
data: &[u8],
align: u64,
) -> u64
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.
sourcepub fn add_symbol_bss(
&mut self,
symbol_id: SymbolId,
section: SectionId,
size: u64,
align: u64,
) -> u64
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.
sourcepub fn set_symbol_data(
&mut self,
symbol_id: SymbolId,
section: SectionId,
offset: u64,
size: u64,
)
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.
sourcepub fn symbol_section_and_offset(
&mut self,
symbol_id: SymbolId,
) -> Option<(SymbolId, u64)>
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.
sourcepub fn add_relocation(
&mut self,
section: SectionId,
relocation: Relocation,
) -> Result<(), Error>
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).