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::Writable

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)
 Writes data of non-zero filled sections.
 
offset_t WriteFile (std::ostream &out)
 Writes data of non-zero filled sections.
 
offset_t WriteFile (Writer &wr, offset_t count, offset_t offset=0) override
 Writes data of non-zero filled sections.
 
offset_t WriteFile (Writer &wr)
 Writes data of non-zero filled sections.
 
int GetByte (offset_t offset) override
 Retrieve byte at a certain offset (optional, might not be defined)
 
offset_t TotalSize ()
 Retrieves total size of segment.
 
offset_t ActualDataSize () override
 Retrieves size of all data in segment.
 
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::Writable
offset_t WriteFile (Writer &wr)
 Writes data of non-zero filled sections.
 

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)
 

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

◆ ActualDataSize()

offset_t Segment::ActualDataSize ( )
overridevirtual

Retrieves size of all data in segment.

This function should always return the same value as data_size. This is checked by an assert value.

Implements Linker::Writable.

◆ 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.

◆ GetByte()

int Segment::GetByte ( offset_t offset)
overridevirtual

Retrieve byte at a certain offset (optional, might not be defined)

Reimplemented from Linker::Writable.

◆ SetEndAddress()

void Segment::SetEndAddress ( offset_t address)

Increases final section to end on specified address.

Note that decreasing a segment is not possible

◆ WriteFile()

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

Writes data of non-zero filled sections.

Implements Linker::Writable.

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: