RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Linker::Segment Class Reference

A class representing a sequence of sections that must be written to the output file as a group. More...

#include <segment.h>

Inheritance diagram for Linker::Segment:
Linker::ActualImage Linker::Image

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.
 
- Public Member Functions inherited from Linker::ActualImage
std::shared_ptr< const ActualImageAsImage () 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)
 
- Public Member Functions inherited from Linker::Image
std::shared_ptr< ActualImageAsImage ()
 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< Segmentshared_from_this ()
 

Detailed Description

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.

Member Function Documentation

◆ Append()

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.

◆ ImageSize()

offset_t Segment::ImageSize ( ) const
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.

◆ ReadData()

size_t Segment::ReadData ( size_t bytes,
offset_t offset,
void * buffer ) const
overridevirtual

Attempts to fill a buffer with data.

Parameters
bytesThe (maximum) number of bytes to place in buffer
offsetThe offset in the image to start reading the data
bufferA byte buffer
Returns
Actual number of bytes copied into buffer

Implements Linker::ActualImage.

◆ SetEndAddress()

void Segment::SetEndAddress ( offset_t address)

Increases final section to end on specified address.

Note that decreasing a segment is not possible

◆ WriteFile() [1/2]

offset_t Segment::WriteFile ( Writer & wr) const
overridevirtual

Writes data of non-zero filled sections.

Reimplemented from Linker::Image.

◆ WriteFile() [2/2]

offset_t Segment::WriteFile ( Writer & wr,
offset_t count,
offset_t offset = 0 ) const
overridevirtual

Writes data of non-zero filled sections.

Implements Linker::Image.

Member Data Documentation

◆ data_size

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.

◆ zero_fill

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.


The documentation for this class was generated from the following files: