8#include "../linker/module.h"
9#include "../linker/options.h"
10#include "../linker/reader.h"
11#include "../linker/segment.h"
12#include "../linker/segment_manager.h"
13#include "../linker/writer.h"
14#include "../dumper/dumper.h"
16namespace DigitalResearch
20 template <
typename SizeType>
21 offset_t MeasureRelocations(
const std::map<uint32_t, SizeType>& relocations)
25 offset_t last_relocation = 0;
26 for(
auto it : relocations)
28 offset_t difference = it.first - last_relocation;
29 if(difference != 0 && difference <= 0x7C)
33 else if(difference < 0x100)
37 else if(difference < 0x10000)
49 template <
typename SizeType>
50 void WriteRelocations(
const std::shared_ptr<Linker::Writer>& wr,
const std::map<uint32_t, SizeType>& relocations)
53 offset_t last_relocation = 0;
54 for(
auto it : relocations)
56 offset_t difference = it.first - last_relocation;
57 uint8_t highbit = it.second == 2 ? 0x80 : 0x00;
58 if(difference != 0 && difference <= 0x7C)
60 wr->WriteWord(1, highbit | difference);
62 else if(difference < 0x100)
64 wr->WriteWord(1, highbit | 0x7D);
65 wr->WriteWord(1, difference);
67 else if(difference < 0x10000)
69 wr->WriteWord(1, highbit | 0x7E);
70 wr->WriteWord(2, difference);
74 wr->WriteWord(1, highbit | 0x7F);
75 wr->WriteWord(4, difference);
77 last_relocation = it.first;
82 template <
typename SizeType,
typename Format>
83 void ReadRelocations(
const std::shared_ptr<Linker::Reader>& rd, std::map<uint32_t, SizeType>& relocations,
const Format& format)
89 uint8_t
byte = rd->ReadUnsigned(1);
90 size_t size = (
byte & 0x80) ? 2 : 4;
100 else if(
byte == 0x7D)
102 offset += rd->ReadUnsigned(1);
104 else if(
byte == 0x7E)
106 offset += rd->ReadUnsigned(2);
110 offset += rd->ReadUnsigned(4);
112 relocations[offset] = SizeType::Create(size, offset, format);
204 std::shared_ptr<Linker::Contents>
code =
nullptr;
208 std::shared_ptr<Linker::Contents>
data =
nullptr;
221 operator size_t()
const;
235 LIBRARY_START = 0x0040,
236 OBJECT_START = 0x0080,
249 static Symbol ReadFile(
const std::shared_ptr<Linker::Reader>& rd);
250 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const;
252 std::vector<Symbol> symbols;
294 void Clear()
override;
307 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
309 offset_t MeasureRelocations()
const;
314 offset_t
WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
332 InitializeFields(noreloc, reloc);
348 std::shared_ptr<const Linker::Segment>
CodeSegment()
const;
352 std::shared_ptr<const Linker::Segment>
DataSegment()
const;
354 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
356 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
359 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
361 void SetOptions(std::map<std::string, std::string>& options)
override;
363 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
365 void CreateDefaultSegments();
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:1009
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:499
Documents and handles command line options.
Definition options.h:306
A helper class to collect sections into segments.
Definition segment_manager.h:32