1#ifndef SEGMENT_MANAGER_H
2#define SEGMENT_MANAGER_H
10#include "../script/script.h"
39 bool current_is_template =
false;
40 bool current_is_template_head =
false;
41 offset_t template_counter = 0;
42 std::string current_template_name;
72 void ClearSegmentManager();
77 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
113 virtual void OnNewSegment(std::shared_ptr<Segment> segment);
124 std::shared_ptr<Segment>
FetchSegment(std::string name);
136 void ProcessAction(std::unique_ptr<Script::Node>& action,
Module& module);
137 void PostProcessAction(std::unique_ptr<Script::Node>& action,
Module& module);
138 void ProcessCommand(std::unique_ptr<Script::Node>& command,
Module& module);
139 bool CheckPredicate(std::unique_ptr<Script::Node>& predicate, std::shared_ptr<Section> section,
Module& module);
140 offset_t EvaluateExpression(std::unique_ptr<Script::Node>& expression,
Module& module);
143 bool starts_with(std::string str, std::string start);
144 bool ends_with(std::string str, std::string end);
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
A helper class to collect sections into segments.
Definition segment_manager.h:32
std::vector< std::shared_ptr< Segment > > segment_vector
Ordered sequence of segments.
Definition segment_manager.h:54
void ProcessScript(std::unique_ptr< Script::List > &directives, Module &module)
Executes a parsed linker script on a module and collects segments The function OnNewSegment can be de...
Definition segment_manager.cc:151
void AlignCurrentAddress(offset_t align)
Aligns current address to alignment, using SetCurrentAddress.
Definition segment_manager.cc:96
void AppendSection(std::shared_ptr< Section > section)
Adds a new section to the current segment, sets the base to the same as the segment.
Definition segment_manager.cc:145
std::shared_ptr< Segment > AppendSegment(std::string name)
Terminates the current segment (if there is one), creates a new segment and attaches it to the image.
Definition segment_manager.cc:123
std::map< std::string, std::shared_ptr< Segment > > segment_map
Map of segments from their names.
Definition segment_manager.h:58
std::shared_ptr< Segment > current_segment
Currently processed segment.
Definition segment_manager.h:62
void FinishCurrentSegment()
Closes the current segment, sets current_segment to null.
Definition segment_manager.cc:108
std::map< std::string, Location > linker_parameters
Parameters that permit customizing the linker script.
Definition segment_manager.h:66
void SetCurrentAddress(offset_t address)
Moves the current address pointer further, and if the current segment already contains data,...
Definition segment_manager.cc:80
offset_t current_address
Holds the current address value when there is no current_segment.
Definition segment_manager.h:37
void SetLatestBase(offset_t address)
Sets the base of the current section (the value from which offsets are counted from)
Definition segment_manager.cc:101
offset_t GetCurrentAddress() const
Retrieves current address pointer.
Definition segment_manager.cc:68
std::string linker_script
Contents of the linker script.
Definition segment_manager.h:70
offset_t current_base
The base address of the current section.
Definition segment_manager.h:50
std::unique_ptr< Script::List > GetScript(Module &module)
Compiles the linker script into an internal format.
Definition segment_manager.cc:49
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Sets up the linker script and linker parameters.
Definition segment_manager.cc:25
virtual void OnNewSegment(std::shared_ptr< Segment > segment)
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition segment_manager.cc:118
std::shared_ptr< Segment > FetchSegment(std::string name)
Attempts to fetch a segment, returns null if not found.
Definition segment_manager.cc:132