LLVM: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
15
20
21#define DEBUG_TYPE "dyld"
22
23namespace llvm {
24
29 if (!SymTypeOrErr) {
30 std::string Buf;
34 }
35
37 return false;
38
39
40
42 .getCOFFSection(*Section)
43 ->Characteristics &
45}
46
48public:
52
56
58
60
61 if (!Flags) {
62 return Flags.takeError();
63 }
64 auto SectionIterOrErr = SR.getSection();
65 if (!SectionIterOrErr) {
66 return SectionIterOrErr.takeError();
67 }
68 SectionRef Sec = *SectionIterOrErr.get();
73
74 Flags->getTargetFlags() = isThumb;
75
76 return Flags;
77 }
78
80
86 StubMap &Stubs) override {
88 if (Symbol == Obj.symbol_end())
90
92 if (!TargetNameOrErr)
93 return TargetNameOrErr.takeError();
94 StringRef TargetName = *TargetNameOrErr;
95
96 auto SectionOrErr = Symbol->getSection();
97 if (!SectionOrErr)
99 auto Section = *SectionOrErr;
100
103
104
109
110 switch (RelType) {
115 break;
116 default:
117 break;
118 }
119
120#if !defined(NDEBUG)
123#endif
125 << " RelType: " << RelTypeName << " TargetName: "
126 << TargetName << " Addend " << Addend << "\n");
127
128 bool IsExtern = Section == Obj.section_end();
129 unsigned TargetSectionID = -1;
131
133 TargetSectionID = SectionID;
134 TargetOffset = getDLLImportOffset(SectionID, Stubs, TargetName, true);
136 IsExtern = false;
137 } else if (!IsExtern) {
138 if (auto TargetSectionIDOrErr =
139 findOrEmitSection(Obj, *Section, Section->isText(), ObjSectionToID))
140 TargetSectionID = *TargetSectionIDOrErr;
141 else
142 return TargetSectionIDOrErr.takeError();
145 }
146
147 if (IsExtern) {
150 } else {
151
152
153
154 bool IsTargetThumbFunc = isThumbFunc(Symbol, Obj, Section);
155
156 switch (RelType) {
159
160 break;
164 TargetOffset, 0, 0, false, 0, IsTargetThumbFunc);
166 break;
167 }
171 TargetOffset, 0, 0, false, 0);
173 break;
174 }
179 break;
180 }
185 break;
186 }
190 TargetOffset, 0, 0, false, 0, IsTargetThumbFunc);
192 break;
193 }
198 TargetOffset + Addend, true, 0);
200 break;
201 }
202 }
203 }
204
205 return ++RelI;
206 }
207
212
216
217 break;
219
224 Result |= ISASelectionBit;
225 assert(Result <= UINT32_MAX && "relocation overflow");
227 << " RelType: IMAGE_REL_ARM_ADDR32"
229 << " Value: " << format("0x%08" PRIx32, Result)
230 << '\n');
232 break;
233 }
235
236
239 assert(Result <= UINT32_MAX && "relocation overflow");
241 << " RelType: IMAGE_REL_ARM_ADDR32NB"
243 << " Value: " << format("0x%08" PRIx32, Result)
244 << '\n');
245 Result |= ISASelectionBit;
247 break;
248 }
250
252 "relocation overflow");
254 << " RelType: IMAGE_REL_ARM_SECTION Value: "
257 break;
259
261 "relocation overflow");
263 << " RelType: IMAGE_REL_ARM_SECREL Value: " << RE.Addend
264 << '\n');
266 break;
268
271 assert(Result <= UINT32_MAX && "relocation overflow");
273 << " RelType: IMAGE_REL_ARM_MOV32T"
275 << " Value: " << format("0x%08" PRIx32, Result)
276 << '\n');
277
278
279
280
281
282
283 auto EncodeImmediate = [](uint8_t *Bytes, uint16_t Immediate) {
284 Bytes[0] |= ((Immediate & 0xf000) >> 12);
285 Bytes[1] |= ((Immediate & 0x0800) >> 11);
286 Bytes[2] |= ((Immediate & 0x00ff) >> 0);
287 Bytes[3] |= (((Immediate & 0x0700) >> 8) << 4);
288 };
289
290 EncodeImmediate(&Target[0],
291 (static_cast<uint32_t>(Result) >> 00) | ISASelectionBit);
292 EncodeImmediate(&Target[4], static_cast<uint32_t>(Result) >> 16);
293 break;
294 }
296
299 assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
300 "relocation overflow");
301 assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
302 "relocation underflow");
304 << " RelType: IMAGE_REL_ARM_BRANCH20T"
305 << " Value: " << static_cast<int32_t>(Value) << '\n');
306 static_cast<void>(Value);
308 break;
309 }
311
314 assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
315 "relocation overflow");
316 assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
317 "relocation underflow");
319 << " RelType: IMAGE_REL_ARM_BRANCH24T"
320 << " Value: " << static_cast<int32_t>(Value) << '\n');
321 static_cast<void>(Value);
323 break;
324 }
326
329 assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
330 "relocation overflow");
331 assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
332 "relocation underflow");
334 << " RelType: IMAGE_REL_ARM_BLX23T"
335 << " Value: " << static_cast<int32_t>(Value) << '\n');
336 static_cast<void>(Value);
338 break;
339 }
340 }
341 }
342
344};
345
346}
347
348#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isThumb(const MCSubtargetInfo &STI)
This file defines the SmallString class.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Symbol resolution interface.
RelocationEntry - used to represent relocations internally in the dynamic linker.
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
unsigned SectionID
SectionID - the section this relocation points to.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Expected< object::relocation_iterator > processRelocationRef(unsigned SectionID, object::relocation_iterator RelI, const object::ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
Definition RuntimeDyldCOFFThumb.h:82
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Definition RuntimeDyldCOFFThumb.h:208
Align getStubAlignment() override
Definition RuntimeDyldCOFFThumb.h:79
unsigned getMaxStubSize() const override
Definition RuntimeDyldCOFFThumb.h:53
Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &SR) override
Generate JITSymbolFlags from a libObject symbol.
Definition RuntimeDyldCOFFThumb.h:57
void registerEHFrames() override
Definition RuntimeDyldCOFFThumb.h:343
RuntimeDyldCOFFThumb(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
Definition RuntimeDyldCOFFThumb.h:49
uint64_t getSymbolOffset(const SymbolRef &Sym)
static constexpr StringRef getImportSymbolPrefix()
RuntimeDyldCOFF(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, unsigned PointerSize, uint32_t PointerReloc)
uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs, StringRef Name, bool SetSectionIDMinus1=false)
std::map< SectionRef, unsigned > ObjSectionToIDMap
std::map< RelocationValueRef, uintptr_t > StubMap
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
SectionEntry - represents a section emitted into memory by the dynamic linker.
uintptr_t getObjAddress() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
const coff_section * getCOFFSection(const SectionRef &Section) const
This class is the base class for all object file types.
uint64_t getOffset() const
symbol_iterator getSymbol() const
void getTypeName(SmallVectorImpl< char > &Result) const
Get a string that represents the type of this relocation.
This is a value type class that represents a single section in the list of sections in the object fil...
const ObjectFile * getObject() const
This is a value type class that represents a single symbol in the list of symbols in the object file.
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_ARM_BRANCH20T
@ IMAGE_REL_ARM_BRANCH24T
content_iterator< SectionRef > section_iterator
content_iterator< RelocationRef > relocation_iterator
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
static bool isThumbFunc(object::symbol_iterator Symbol, const object::ObjectFile &Obj, object::section_iterator Section)
Definition RuntimeDyldCOFFThumb.h:25
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
This struct is a compact representation of a valid (non-zero power of two) alignment.
support::ulittle32_t Characteristics