RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
|
A class representing a sequence of sections that must be written to the output file as a group. More...
#include <segment.h>
Public Member Functions | |
Segment (std::string name, offset_t base_address=0) | |
bool | IsMissing () |
Segment that contains neither non zero filled, nor zero filled, nor optional extra data. | |
void | Fill () |
Fills zero filled sections with zero data, making them non-zero filled in the sense that they have to be written to disk. | |
void | RealignEnd (offset_t align) |
Aligns end of segment by increasing size of last section. | |
void | Append (std::shared_ptr< Section > section) |
Appends section to segment. | |
offset_t | WriteFile (std::ostream &out, offset_t size, offset_t offset=0) const |
Writes data of non-zero filled sections. | |
offset_t | WriteFile (std::ostream &out) const |
Writes data of non-zero filled sections. | |
offset_t | WriteFile (Writer &wr, offset_t count, offset_t offset=0) const override |
Writes data of non-zero filled sections. | |
offset_t | WriteFile (Writer &wr) const override |
Writes data of non-zero filled sections. | |
size_t | ReadData (size_t bytes, offset_t offset, void *buffer) const override |
Attempts to fill a buffer with data. | |
offset_t | TotalSize () |
Retrieves total size of segment. | |
offset_t | ImageSize () const override |
Retrieves size of all data in segment, as present in the binary image. | |
offset_t | GetStartAddress () |
Returns starting address (base_address) | |
offset_t | GetEndAddress () |
Returns end address (GetStartAddress() + TotalSize()) | |
void | SetEndAddress (offset_t address) |
Increases final section to end on specified address. | |
void | AlignEndAddress (offset_t align) |
Aligns the end of the segment. | |
void | SetStartAddress (offset_t address) |
Forcibly resets starting address of segment. | |
![]() | |
std::shared_ptr< const ActualImage > | AsImage () const override |
Retrieves a randomly accessible image. | |
uint64_t | ReadUnsigned (size_t bytes, offset_t offset, EndianType endiantype) const |
Reads an unsigned number at a specific offset. | |
uint64_t | ReadUnsigned (size_t bytes, offset_t offset) const |
Reads an unsigned number at a specific offset with the default endianness. | |
int64_t | ReadSigned (size_t bytes, offset_t offset, EndianType endiantype) const |
Reads a signed number at a specific offset. | |
int64_t | ReadSigned (size_t bytes, offset_t offset) const |
Reads a signed number at a specific offset with the default endianness. | |
int | GetByte (offset_t offset) const |
Retrieve byte at a certain offset (optional, might not be defined) | |
![]() | |
std::shared_ptr< ActualImage > | AsImage () |
Retrieves a randomly accessible image. | |
Public Attributes | |
std::string | name |
The name of the segment. | |
std::vector< std::shared_ptr< Section > > | sections |
Sequence of sections belonging to the segment. | |
offset_t | base_address |
Address where segment starts. | |
offset_t | align = 1 |
Alignment requirements of segment. | |
offset_t | data_size = 0 |
Cached value of the non-filled data for the entire segment. | |
offset_t | zero_fill = 0 |
Extra zero filled space following filled data. | |
offset_t | optional_extra = 0 |
Optional extra space after zero filled data. | |
Protected Member Functions | |
void | ShiftAddress (int64_t amount) |
std::shared_ptr< Segment > | shared_from_this () |
A class representing a sequence of sections that must be written to the output file as a group.
A segment represents a collection of sections that appear within the same addressing space. It also makes it easier to write several sections into the output file consecutively.
Only sections that appear consecutively in memory (or with known displacements at linking time) may be stored in the same segment.
void Segment::Append | ( | std::shared_ptr< Section > | section | ) |
Appends section to segment.
This action might require aligning end of last section, possibly zero filling it, and setting the base address and bias of the new section.
|
overridevirtual |
Retrieves size of all data in segment, as present in the binary image.
This function should always return the same value as data_size. This is checked by an assert value.
Implements Linker::Image.
|
overridevirtual |
Attempts to fill a buffer with data.
bytes | The (maximum) number of bytes to place in buffer |
offset | The offset in the image to start reading the data |
buffer | A byte buffer |
Implements Linker::ActualImage.
void Segment::SetEndAddress | ( | offset_t | address | ) |
Increases final section to end on specified address.
Note that decreasing a segment is not possible
|
overridevirtual |
Writes data of non-zero filled sections.
Reimplemented from Linker::Image.
|
overridevirtual |
Writes data of non-zero filled sections.
Implements Linker::Image.
offset_t Linker::Segment::data_size = 0 |
Cached value of the non-filled data for the entire segment.
This should be equal to the sum of all sizes of sections are not zero filled. Note that a non zero filled section may not follow a zero filled one.
offset_t Linker::Segment::zero_fill = 0 |
Extra zero filled space following filled data.
This should be equal to the sum of all sizes of sections are zero filled. Note that a non zero filled section may not follow a zero filled one.