RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
relocation.h
1#ifndef RELOCATION_H
2#define RELOCATION_H
3
4#include "../common.h"
5#include "location.h"
6#include "resolution.h"
7#include "section.h"
8#include "target.h"
9
10namespace Linker
11{
27 {
28 public:
39 size_t size;
55 uint64_t addend;
59 EndianType endiantype;
63 int shift;
67 uint64_t mask;
72
75 shift(0), mask(-1), subtract(false)
76 {
77 }
78
85 static Relocation Empty();
86
90 static Relocation Absolute(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
91
95 static Relocation Absolute(size_t size, Location source, Target target, uint64_t addend = 0);
96
100 static Relocation Offset(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
101
105 static Relocation Offset(size_t size, Location source, Target target, uint64_t addend = 0);
106
110 static Relocation OffsetFrom(size_t size, Location source, Target target, Target reference, uint64_t addend, EndianType endiantype);
111
116
120 static Relocation Relative(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
121
125 static Relocation Relative(size_t size, Location source, Target target, uint64_t addend = 0);
126
130 static Relocation Paragraph(Location source, Target target, uint64_t addend = 0);
131
135 static Relocation Selector(Location source, Target target, uint64_t addend = 0);
136
140 static Relocation Segment(size_t size, Location source, Target target, uint64_t addend = 0);
141
149
153 Relocation& SetMask(uint64_t new_mask);
154
158 Relocation& SetShift(int new_shift);
159
163 Relocation& SetSubtract(bool to_subtract = true);
164
168 bool Displace(const Displacement& displacement);
169
173 bool Resolve(Module& object, Resolution& resolution);
174
178 uint64_t ReadUnsigned();
179
183 int64_t ReadSigned();
184
188 void WriteWord(uint64_t value);
189
197 void AddCurrentValue();
198
205 bool IsRelative() const;
206 };
207
208 std::ostream& operator<<(std::ostream& out, const Relocation& relocation);
209}
210
211#endif /* RELOCATION_H */
Represents a single offset within a section, or an absolute location in memory if the section is null...
Definition location.h:17
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:20
A representation of a value within some binary data that has to be fixed up once the exact position o...
Definition relocation.h:27
static Relocation Paragraph(Location source, Target target, uint64_t addend=0)
Creates a relocation that stores the 16-bit paragraph (shifted right by 4) of the target (Intel 8086 ...
Definition relocation.cc:53
Relocation & SetShift(int new_shift)
The value stored in the word must be shifted by this to give the actual value.
Definition relocation.cc:83
Location source
The location where the value of the symbol should be stored.
Definition relocation.h:43
bool Resolve(Module &object, Resolution &resolution)
If the target and reference symbols can be resolved, return the value with some additional informatio...
Definition relocation.cc:100
bool segment_of
Set when the value to be stored is the segment selector instead of the segment start (Intel 8086 spec...
Definition relocation.h:35
static Relocation Offset(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype)
Creates a relocation that references the offset of a target within its preferred segment (Intel 8086 ...
Definition relocation.cc:21
static Relocation Relative(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype)
Creates a relocation that references the offset of a target from the source.
Definition relocation.cc:43
void AddCurrentValue()
Updates the addend with the value stored in the section data.
Definition relocation.cc:164
Relocation & SetSubtract(bool to_subtract=true)
The value stored in the word must be negated before adding the addend and storing.
Definition relocation.cc:89
EndianType endiantype
The endianness of the stored value.
Definition relocation.h:59
int64_t ReadSigned()
Accesses the value within the section data.
Definition relocation.cc:139
Target target
The symbol or location referenced by the relocation.
Definition relocation.h:47
static Relocation ParagraphDifference(Location source, Target target, Target reference, uint64_t addend=0)
Creates a relocation that stores the 16-bit paragraph difference (shifted right by 4) between the tar...
Definition relocation.cc:71
static Relocation Absolute(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype)
Creates a relocation referencing the absolute address of a target.
Definition relocation.cc:11
Relocation & SetMask(uint64_t new_mask)
Instead of the full word, only modify the following bits.
Definition relocation.cc:77
uint64_t addend
A value to be added.
Definition relocation.h:55
Target reference
The symbol or location whose value is subtracted from the final value, used for self-relative and seg...
Definition relocation.h:51
static Relocation Selector(Location source, Target target, uint64_t addend=0)
Creates a relocation that stores the 16-bit paragraph (shifted right by 4) of the target (Intel 8086 ...
Definition relocation.cc:59
uint64_t mask
The bitmask of the value within the word.
Definition relocation.h:67
bool Displace(const Displacement &displacement)
Recalculates the source, target and reference locations after a section has moved.
Definition relocation.cc:95
void WriteWord(uint64_t value)
Accesses the value within the section data.
Definition relocation.cc:150
static Relocation OffsetFrom(size_t size, Location source, Target target, Target reference, uint64_t addend, EndianType endiantype)
Creates a relocation that references the offset of a target from a specific reference point.
Definition relocation.cc:33
bool subtract
Set to true if value must be negated first.
Definition relocation.h:71
static Relocation Empty()
Creates an empty relocation.
Definition relocation.cc:6
bool IsRelative() const
Determines if a relocation is self-relative.
Definition relocation.cc:170
static Relocation Segment(size_t size, Location source, Target target, uint64_t addend=0)
Creates a relocation that stores the 8-bit segment number of the target (Zilog Z8000 specific)
Definition relocation.cc:65
uint64_t ReadUnsigned()
Accesses the value within the section data.
Definition relocation.cc:128
size_t size
The size of the value when stored at the source, in bytes (for example, 2 for 16-bit,...
Definition relocation.h:39
int shift
The amount of bits the value should be shifted by.
Definition relocation.h:63
Representing a resolved relocation.
Definition resolution.h:17
Represents a possible target or reference frame of a relocation.
Definition target.h:24