1//===-- RuntimeDyldCOFF.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// COFF support for MC-JIT runtime dynamic linker.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_RUNTIME_DYLD_COFF_H
14#define LLVM_RUNTIME_DYLD_COFF_H
15
16#include "RuntimeDyldImpl.h"
17#include "llvm/Support/MathExtras.h"
18
19namespace llvm {
20
21// Common base class for COFF dynamic linker support.
22// Concrete subclasses for each target can be found in ./Targets.
23class RuntimeDyldCOFF : public RuntimeDyldImpl {
24
25public:
26 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
27 loadObject(const object::ObjectFile &Obj) override;
28 bool isCompatibleFile(const object::ObjectFile &Obj) const override;
29
30 static std::unique_ptr<RuntimeDyldCOFF>
31 create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr,
32 JITSymbolResolver &Resolver);
33
34protected:
35 RuntimeDyldCOFF(RuntimeDyld::MemoryManager &MemMgr,
36 JITSymbolResolver &Resolver, unsigned PointerSize,
37 uint32_t PointerReloc)
38 : RuntimeDyldImpl(MemMgr, Resolver), PointerSize(PointerSize),
39 PointerReloc(PointerReloc) {
40 assert((PointerSize == 4 || PointerSize == 8) && "Unexpected pointer size");
41 }
42
43 uint64_t getSymbolOffset(const SymbolRef &Sym);
44 uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs,
45 StringRef Name, bool SetSectionIDMinus1 = false);
46
47 static constexpr StringRef getImportSymbolPrefix() { return "__imp_"; }
48
49 bool relocationNeedsDLLImportStub(const RelocationRef &R) const override;
50
51 unsigned sizeAfterAddingDLLImportStub(unsigned Size) const override {
52 return alignTo(Value: Size, Align: PointerSize) + PointerSize;
53 }
54
55private:
56 unsigned PointerSize;
57 uint32_t PointerReloc;
58};
59
60} // end namespace llvm
61
62#endif // LLVM_RUNTIME_DYLD_COFF_H
63