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 "target.h"
7
8namespace Linker
9{
10 class Resolution;
11
27 {
28 public:
30 {
50 SelectorIndex, // TODO: unimplemented
54 GOTOffset, // TODO: unimplemented
58 PLTOffset, // TODO: unimplemented
62 SizeOf, // TODO: unimplemented
63 }
71 size_t size;
87 uint64_t addend;
91 EndianType endiantype;
95 int shift;
99 uint64_t mask;
104
107 shift(0), mask(-1), subtract(false)
108 {
109 }
110
117 static Relocation Empty();
118
122 static Relocation Absolute(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
123
127 static Relocation Absolute(size_t size, Location source, Target target, uint64_t addend = 0);
128
132 static Relocation Offset(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
133
137 static Relocation Offset(size_t size, Location source, Target target, uint64_t addend = 0);
138
142 static Relocation OffsetFrom(size_t size, Location source, Target target, Target reference, uint64_t addend, EndianType endiantype);
143
148
152 static Relocation Relative(size_t size, Location source, Target target, uint64_t addend, EndianType endiantype);
153
157 static Relocation Relative(size_t size, Location source, Target target, uint64_t addend = 0);
158
162 static Relocation Paragraph(Location source, Target target, uint64_t addend = 0);
163
167 static Relocation Selector(Location source, Target target, uint64_t addend = 0);
168
172 static Relocation Segment(size_t size, Location source, Target target, uint64_t addend = 0);
173
181
185 Relocation& SetMask(uint64_t new_mask);
186
190 Relocation& SetShift(int new_shift);
191
195 Relocation& SetSubtract(bool to_subtract = true);
196
200 bool Displace(const Displacement& displacement);
201
205 bool Resolve(Module& object, Resolution& resolution);
206
210 uint64_t ReadUnsigned();
211
215 int64_t ReadSigned();
216
220 void WriteWord(uint64_t value);
221
229 void AddCurrentValue();
230
237 bool IsRelative() const;
238 };
239
240 std::ostream& operator<<(std::ostream& out, const Relocation& relocation);
241}
242
243#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:24
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:56
Relocation & SetShift(int new_shift)
The value stored in the word must be shifted by this to give the actual value.
Definition relocation.cc:86
Location source
The location where the value of the symbol should be stored.
Definition relocation.h:75
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:109
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:24
enum Linker::Relocation::reference_kind kind
Specifies the way the target is used to derive the resolve value, typically Direct.
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:46
void AddCurrentValue()
Updates the addend with the value stored in the section data.
Definition relocation.cc:188
reference_kind
Definition relocation.h:30
@ SegmentIndex
The 8-bit segment of value is used, obtained via shifting it by 16 to the right.
Definition relocation.h:44
@ PLTOffset
An offset within the Procedure Linkage Table is used instead of the actual value.
Definition relocation.h:58
@ SelectorIndex
A selector index is used to reference this target.
Definition relocation.h:50
@ Direct
The value of the target is used.
Definition relocation.h:32
@ SegmentAddress
The paragraph of value is used, obtained via shifting it by 4 to the right.
Definition relocation.h:38
@ SizeOf
Size of the target.
Definition relocation.h:62
@ GOTOffset
An offset within the Global Offset Table is used instead of the actual value.
Definition relocation.h:54
Relocation & SetSubtract(bool to_subtract=true)
The value stored in the word must be negated before adding the addend and storing.
Definition relocation.cc:92
EndianType endiantype
The endianness of the stored value.
Definition relocation.h:91
int64_t ReadSigned()
Accesses the value within the section data.
Definition relocation.cc:163
Target target
The symbol or location referenced by the relocation.
Definition relocation.h:79
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:74
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:14
Relocation & SetMask(uint64_t new_mask)
Instead of the full word, only modify the following bits.
Definition relocation.cc:80
uint64_t addend
A value to be added.
Definition relocation.h:87
Target reference
The symbol or location whose value is subtracted from the final value, used for self-relative and seg...
Definition relocation.h:83
static Relocation Selector(Location source, Target target, uint64_t addend=0)
Creates a relocation that stores a 16-bit selector value referencing the target (Intel 8086 specific)
Definition relocation.cc:62
uint64_t mask
The bitmask of the value within the word.
Definition relocation.h:99
bool Displace(const Displacement &displacement)
Recalculates the source, target and reference locations after a section has moved.
Definition relocation.cc:98
void WriteWord(uint64_t value)
Accesses the value within the section data.
Definition relocation.cc:174
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:36
bool subtract
Set to true if value must be negated first.
Definition relocation.h:103
static Relocation Empty()
Creates an empty relocation.
Definition relocation.cc:9
bool IsRelative() const
Determines if a relocation is self-relative.
Definition relocation.cc:194
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:68
uint64_t ReadUnsigned()
Accesses the value within the section data.
Definition relocation.cc:152
size_t size
The size of the value when stored at the source, in bytes (for example, 2 for 16-bit,...
Definition relocation.h:71
int shift
The amount of bits the value should be shifted by.
Definition relocation.h:95
Representing a resolved relocation.
Definition resolution.h:17
Represents a possible target or reference frame of a relocation.
Definition target.h:24