RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
bflt.h
1#ifndef BFLT_H
2#define BFLT_H
3
4#include <vector>
5#include "../common.h"
6#include "../dumper/dumper.h"
7#include "../linker/module_collector.h"
8#include "../linker/options.h"
9#include "../linker/reader.h"
10#include "../linker/segment.h"
11#include "../linker/segment_manager.h"
12#include "../linker/writer.h"
13
14namespace BFLT
15{
21 class BFLTFormat : public virtual Linker::SegmentManager
22 {
23 public:
24 /* * * General members * * */
25
26 ::EndianType endian_type = ::UndefinedEndian;
27 uint32_t format_version = 4;
28 uint32_t entry = 0;
29 uint32_t data_offset = 0;
30 uint32_t bss_offset = 0;
31 uint32_t bss_end_offset = 0;
32 uint32_t stack_size = 0;
33 uint32_t relocation_offset = 0;
34
35 std::shared_ptr<Linker::Image> code, data;
36
41 {
42 enum relocation_type
43 {
44 Text = 0,
45 Data = 1,
46 Bss = 2,
47 }
50 offset_t offset;
51 };
52
53 std::vector<Relocation> relocations;
54 uint32_t flags = 0;
55 static constexpr uint32_t FLAG_RAM = 0x0001;
56 static constexpr uint32_t FLAG_GOTPIC = 0x0002;
57 static constexpr uint32_t FLAG_GZIP = 0x0004;
58
59 BFLTFormat(uint32_t format_version = 4)
60 : format_version(format_version)
61 {
62 }
63
64 void Clear() override;
65
67 {
68 Clear();
69 }
70
71 void ReadFile(Linker::Reader& rd) override;
72
74 offset_t WriteFile(Linker::Writer& wr) const override;
75
76 void Dump(Dumper::Dumper& dump) const override;
77
78 void CalculateValues() override;
79
80 /* * * Writer members * * */
81
83 {
84 public:
85 Linker::Option<bool> ram{"ram", "File should be fully loaded into RAM"};
86 Linker::Option<bool> got{"got", "Program is position independent and has GOT"};
87
89 {
90 InitializeFields(ram, got);
91 }
92 };
93
94 std::shared_ptr<Linker::Segment> bss, stack;
95 std::shared_ptr<Linker::GlobalOffsetTable> got;
96
97 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
98
99 void SetOptions(std::map<std::string, std::string>& options) override;
100
101 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
102
103 void CreateDefaultSegments();
104
105 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options) override;
106
107 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
108
109 void ProcessModule(Linker::Module& module) override;
110
111 void GenerateFile(std::string filename, Linker::Module& module) override;
112
114 std::string GetDefaultExtension(Linker::Module& module) const override;
115 };
116}
117
118#endif /* BFLT_H */
BFLT Binary flat format.
Definition bflt.h:22
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Selects a script file to use for linking.
Definition bflt.cc:148
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition bflt.cc:298
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition bflt.cc:291
std::shared_ptr< Linker::OptionCollector > GetOptions() override
Returns object containing a sequence of option fields provided with the -S command line flag.
Definition bflt.cc:86
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition bflt.cc:29
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition bflt.cc:11
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition bflt.cc:91
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition bflt.cc:24
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition bflt.cc:108
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition bflt.cc:75
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition bflt.cc:198
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition bflt.cc:70
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
Helper class that contains the options interpreted by the format.
Definition options.h:308
Documents and handles command line options.
Definition options.h:196
virtual std::string GetDefaultExtension(Module &module, std::string filename) const
Appends a default extension to the filename.
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class to collect sections into segments.
Definition segment_manager.h:32
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Represents a relocation within the image.
Definition bflt.h:41
enum BFLT::BFLTFormat::Relocation::relocation_type type
Whether the target references the text, data or bss segment, only relevant up to and including versio...