pub struct Writer<'a> { /* private fields */ }
Expand description

A helper for writing ELF files.

Writing uses a two phase approach. The first phase builds up all of the information that may need to be known ahead of time:

  • build string tables
  • reserve section indices
  • reserve symbol indices
  • reserve file ranges for headers and sections

Some of the information has ordering requirements. For example, strings must be added to string tables before reserving the file range for the string table. Symbol indices must be reserved after reserving the section indices they reference. There are debug asserts to check some of these requirements.

The second phase writes everything out in order. Thus the caller must ensure writing is in the same order that file ranges were reserved. There are debug asserts to assist with checking this.

Implementations

Create a new Writer for the given endianness and ELF class.

Return the current file length that has been reserved.

Return the current file length that has been written.

Reserve a file range with the given size and starting alignment.

Returns the aligned offset of the start of the range.

Write alignment padding bytes.

Write data.

This is typically used to write section data.

Reserve the file range up to the given file offset.

Write padding up to the given file offset.

Reserve the range for the file header.

This must be at the start of the file.

Write the file header.

This must be at the start of the file.

Fields that can be derived from known information are automatically set by this function.

Reserve the range for the program headers.

Write alignment padding bytes prior to the program headers.

Write a program header.

Reserve the section index for the null section header.

The null section header is usually automatically reserved, but this can be used to force an empty section table.

This must be called before Self::reserve_section_headers.

Reserve a section table index.

Automatically also reserves the null section header if required.

This must be called before Self::reserve_section_headers.

Reserve the range for the section headers.

This function does nothing if no sections were reserved. This must be called after Self::reserve_section_index and other functions that reserve section indices.

Write the null section header.

This must be the first section header that is written. This function does nothing if no sections were reserved.

Write a section header.

Add a section name to the section header string table.

This will be stored in the .shstrtab section.

This must be called before Self::reserve_shstrtab.

Reserve the range for the section header string table.

This range is used for a section named .shstrtab.

This function does nothing if no sections were reserved. This must be called after Self::add_section_name. and other functions that reserve section names and indices.

Write the section header string table.

This function does nothing if the section was not reserved.

Reserve the section index for the section header string table.

This must be called before Self::reserve_shstrtab and Self::reserve_section_headers.

Write the section header for the section header string table.

This function does nothing if the section index was not reserved.

Add a string to the string table.

This will be stored in the .strtab section.

This must be called before Self::reserve_strtab.

Return true if .strtab is needed.

Reserve the range for the string table.

This range is used for a section named .strtab.

This function does nothing if no strings or symbols were defined. This must be called after Self::add_string.

Write the string table.

This function does nothing if the section was not reserved.

Reserve the section index for the string table.

This must be called before Self::reserve_section_headers.

Write the section header for the string table.

This function does nothing if the section index was not reserved.

Reserve the null symbol table entry.

This will be stored in the .symtab section.

The null symbol table entry is usually automatically reserved, but this can be used to force an empty symbol table.

This must be called before Self::reserve_symtab.

Reserve a symbol table entry.

This will be stored in the .symtab section.

section_index is used to determine whether .symtab_shndx is required.

Automatically also reserves the null symbol if required. Callers may assume that the returned indices will be sequential starting at 1.

This must be called before Self::reserve_symtab and Self::reserve_symtab_shndx.

Return the number of reserved symbol table entries.

Includes the null symbol.

Reserve the range for the symbol table.

This range is used for a section named .symtab. This function does nothing if no symbols were reserved. This must be called after Self::reserve_symbol_index.

Write the null symbol.

This must be the first symbol that is written. This function does nothing if no symbols were reserved.

Write a symbol.

Reserve the section index for the symbol table.

This must be called before Self::reserve_section_headers.

Return the section index of the symbol table.

Write the section header for the symbol table.

This function does nothing if the section index was not reserved.

Return true if .symtab_shndx is needed.

Reserve the range for the extended section indices for the symbol table.

This range is used for a section named .symtab_shndx. This also reserves a section index.

This function does nothing if extended section indices are not needed. This must be called after Self::reserve_symbol_index.

Write the extended section indices for the symbol table.

This function does nothing if the section was not reserved.

Reserve the section index for the extended section indices symbol table.

You should check Self::symtab_shndx_needed before calling this unless you have other means of knowing if this section is needed.

This must be called before Self::reserve_section_headers.

Write the section header for the extended section indices for the symbol table.

This function does nothing if the section index was not reserved.

Add a string to the dynamic string table.

This will be stored in the .dynstr section.

This must be called before Self::reserve_dynstr.

Get a string that was previously added to the dynamic string table.

Panics if the string was not added.

Return true if .dynstr is needed.

Reserve the range for the dynamic string table.

This range is used for a section named .dynstr.

This function does nothing if no dynamic strings or symbols were defined. This must be called after Self::add_dynamic_string.

Write the dynamic string table.

This function does nothing if the section was not reserved.

Reserve the section index for the dynamic string table.

This must be called before Self::reserve_section_headers.

Return the section index of the dynamic string table.

Write the section header for the dynamic string table.

This function does nothing if the section index was not reserved.

Reserve the null dynamic symbol table entry.

This will be stored in the .dynsym section.

The null dynamic symbol table entry is usually automatically reserved, but this can be used to force an empty dynamic symbol table.

This must be called before Self::reserve_dynsym.

Reserve a dynamic symbol table entry.

This will be stored in the .dynsym section.

Automatically also reserves the null symbol if required. Callers may assume that the returned indices will be sequential starting at 1.

This must be called before Self::reserve_dynsym.

Return the number of reserved dynamic symbols.

Includes the null symbol.

Reserve the range for the dynamic symbol table.

This range is used for a section named .dynsym.

This function does nothing if no dynamic symbols were reserved. This must be called after Self::reserve_dynamic_symbol_index.

Write the null dynamic symbol.

This must be the first dynamic symbol that is written. This function does nothing if no dynamic symbols were reserved.

Write a dynamic symbol.

Reserve the section index for the dynamic symbol table.

This must be called before Self::reserve_section_headers.

Return the section index of the dynamic symbol table.

Write the section header for the dynamic symbol table.

This function does nothing if the section index was not reserved.

Reserve the range for the .dynamic section.

This function does nothing if dynamic_num is zero.

Write alignment padding bytes prior to the .dynamic section.

This function does nothing if the section was not reserved.

Write a dynamic string entry.

Write a dynamic value entry.

Reserve the section index for the dynamic table.

Write the section header for the dynamic table.

This function does nothing if the section index was not reserved.

Reserve a file range for a SysV hash section.

symbol_count is the number of symbols in the hash, not the total number of symbols.

Write a SysV hash section.

chain_count is the number of symbols in the hash. The argument to hash will be in the range 0..chain_count.

Reserve the section index for the SysV hash table.

Write the section header for the SysV hash table.

This function does nothing if the section index was not reserved.

Reserve a file range for a GNU hash section.

symbol_count is the number of symbols in the hash, not the total number of symbols.

Write a GNU hash section.

symbol_count is the number of symbols in the hash. The argument to hash will be in the range 0..symbol_count.

This requires that symbols are already sorted by bucket.

Reserve the section index for the GNU hash table.

Write the section header for the GNU hash table.

This function does nothing if the section index was not reserved.

Reserve the range for the .gnu.version section.

This function does nothing if no dynamic symbols were reserved.

Write the null symbol version entry.

This must be the first symbol version that is written. This function does nothing if no dynamic symbols were reserved.

Write a symbol version entry.

Reserve the section index for the .gnu.version section.

Write the section header for the .gnu.version section.

This function does nothing if the section index was not reserved.

Reserve the range for the .gnu.version_d section.

Write alignment padding bytes prior to a .gnu.version_d section.

Write a version definition entry.

Write a version definition auxiliary entry.

Reserve the section index for the .gnu.version_d section.

Write the section header for the .gnu.version_d section.

This function does nothing if the section index was not reserved.

Reserve the range for the .gnu.version_r section.

Write alignment padding bytes prior to a .gnu.version_r section.

Write a version need entry.

Write a version need auxiliary entry.

Reserve the section index for the .gnu.version_r section.

Write the section header for the .gnu.version_r section.

This function does nothing if the section index was not reserved.

Reserve a file range for the given number of relocations.

Returns the offset of the range.

Write alignment padding bytes prior to a relocation section.

Write a relocation.

Write the section header for a relocation section.

section is the index of the section the relocations apply to, or 0 if none.

symtab is the index of the symbol table the relocations refer to, or 0 if none.

offset is the file offset of the relocations.

Reserve a file range for a COMDAT section.

count is the number of sections in the COMDAT group.

Returns the offset of the range.

Write GRP_COMDAT at the start of the COMDAT section.

source

pub fn write_comdat_entry(&mut self, entry: SectionIndex)

Write an entry in a COMDAT section.

Write the section header for a COMDAT section.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.