Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 1 | //===-- RuntimeDyldMachO.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // MachO support for MC-JIT runtime dynamic linker. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_RUNTIME_DYLD_MACHO_H |
| 15 | #define LLVM_RUNTIME_DYLD_MACHO_H |
| 16 | |
Lang Hames | 951b235 | 2014-03-08 18:45:12 +0000 | [diff] [blame] | 17 | #include "ObjectImageCommon.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 18 | #include "RuntimeDyldImpl.h" |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/IndexedMap.h" |
Rafael Espindola | 6e040c0 | 2013-04-26 20:07:33 +0000 | [diff] [blame] | 20 | #include "llvm/Object/MachO.h" |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Format.h" |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | using namespace llvm::object; |
| 25 | |
| 26 | |
| 27 | namespace llvm { |
| 28 | class RuntimeDyldMachO : public RuntimeDyldImpl { |
Sean Callanan | a375943 | 2012-03-26 20:45:52 +0000 | [diff] [blame] | 29 | bool resolveI386Relocation(uint8_t *LocalAddress, |
| 30 | uint64_t FinalAddress, |
| 31 | uint64_t Value, |
| 32 | bool isPCRel, |
| 33 | unsigned Type, |
| 34 | unsigned Size, |
| 35 | int64_t Addend); |
Sean Callanan | ca92a3d | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 36 | bool resolveX86_64Relocation(uint8_t *LocalAddress, |
| 37 | uint64_t FinalAddress, |
| 38 | uint64_t Value, |
| 39 | bool isPCRel, |
| 40 | unsigned Type, |
| 41 | unsigned Size, |
| 42 | int64_t Addend); |
| 43 | bool resolveARMRelocation(uint8_t *LocalAddress, |
| 44 | uint64_t FinalAddress, |
| 45 | uint64_t Value, |
| 46 | bool isPCRel, |
| 47 | unsigned Type, |
| 48 | unsigned Size, |
| 49 | int64_t Addend); |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 50 | |
Rafael Espindola | f1f1c62 | 2013-04-29 17:24:34 +0000 | [diff] [blame] | 51 | void resolveRelocation(const SectionEntry &Section, |
| 52 | uint64_t Offset, |
| 53 | uint64_t Value, |
| 54 | uint32_t Type, |
| 55 | int64_t Addend, |
| 56 | bool isPCRel, |
| 57 | unsigned Size); |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 58 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 59 | unsigned getMaxStubSize() override { |
Andrew Kaylor | 2ba21c5 | 2013-10-15 21:32:56 +0000 | [diff] [blame] | 60 | if (Arch == Triple::arm || Arch == Triple::thumb) |
| 61 | return 8; // 32-bit instruction and 32-bit address |
| 62 | else if (Arch == Triple::x86_64) |
| 63 | return 8; // GOT entry |
| 64 | else |
| 65 | return 0; |
| 66 | } |
| 67 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 68 | unsigned getStubAlignment() override { |
Andrew Kaylor | 2ba21c5 | 2013-10-15 21:32:56 +0000 | [diff] [blame] | 69 | return 1; |
| 70 | } |
| 71 | |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 72 | struct EHFrameRelatedSections { |
| 73 | EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID), |
| 74 | TextSID(RTDYLD_INVALID_SECTION_ID), |
| 75 | ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {} |
NAKAMURA Takumi | 87e0880 | 2013-12-07 11:21:42 +0000 | [diff] [blame] | 76 | EHFrameRelatedSections(SID EH, SID T, SID Ex) |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 77 | : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {} |
| 78 | SID EHFrameSID; |
| 79 | SID TextSID; |
| 80 | SID ExceptTabSID; |
| 81 | }; |
| 82 | |
| 83 | // When a module is loaded we save the SectionID of the EH frame section |
| 84 | // in a table until we receive a request to register all unregistered |
| 85 | // EH frame sections with the memory manager. |
| 86 | SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections; |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 87 | public: |
| 88 | RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {} |
| 89 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 90 | void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override; |
Juergen Ributzka | 046709f | 2014-03-21 07:26:41 +0000 | [diff] [blame^] | 91 | relocation_iterator |
| 92 | processRelocationRef(unsigned SectionID, relocation_iterator RelI, |
| 93 | ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, |
| 94 | const SymbolTableMap &Symbols, StubMap &Stubs) override; |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 95 | bool isCompatibleFormat(const ObjectBuffer *Buffer) const override; |
| 96 | bool isCompatibleFile(const object::ObjectFile *Obj) const override; |
| 97 | void registerEHFrames() override; |
| 98 | void finalizeLoad(ObjSectionToIDMap &SectionMap) override; |
Lang Hames | 951b235 | 2014-03-08 18:45:12 +0000 | [diff] [blame] | 99 | |
| 100 | |
| 101 | static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) { |
| 102 | return new ObjectImageCommon(InputBuffer); |
| 103 | } |
| 104 | |
| 105 | static ObjectImage *createObjectImageFromFile(object::ObjectFile *InputObject) { |
| 106 | return new ObjectImageCommon(InputObject); |
| 107 | } |
Eli Bendersky | 058d647 | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // end namespace llvm |
| 111 | |
| 112 | #endif |