| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 1 | //===- Target.h -------------------------------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                             The LLVM Linker | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
|  | 10 | #ifndef LLD_ELF_TARGET_H | 
|  | 11 | #define LLD_ELF_TARGET_H | 
|  | 12 |  | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/StringRef.h" | 
|  | 14 |  | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 15 | #include <memory> | 
|  | 16 |  | 
|  | 17 | namespace lld { | 
|  | 18 | namespace elf2 { | 
|  | 19 | class SymbolBody; | 
|  | 20 |  | 
|  | 21 | class TargetInfo { | 
|  | 22 | public: | 
| Hal Finkel | e3c2626 | 2015-10-08 22:23:54 +0000 | [diff] [blame] | 23 | unsigned getPageSize() const { return PageSize; } | 
| Hal Finkel | 4729064 | 2015-10-08 21:25:04 +0000 | [diff] [blame] | 24 | uint64_t getVAStart() const { return VAStart; } | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 25 | unsigned getPCRelReloc() const { return PCRelReloc; } | 
| Rafael Espindola | 7f07442 | 2015-09-22 21:35:51 +0000 | [diff] [blame] | 26 | unsigned getGotReloc() const { return GotReloc; } | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 27 | unsigned getGotRefReloc() const { return GotRefReloc; } | 
|  | 28 | unsigned getRelativeReloc() const { return RelativeReloc; } | 
| Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 29 | unsigned getPltEntrySize() const { return PltEntrySize; } | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 30 | virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 31 | uint64_t PltEntryAddr) const = 0; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 32 | virtual bool isRelRelative(uint32_t Type) const; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 33 | virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0; | 
| Rafael Espindola | 6d7fcdb | 2015-09-29 13:36:32 +0000 | [diff] [blame] | 34 | virtual bool relocPointsToGot(uint32_t Type) const; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 35 | virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 36 | virtual void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 37 | uint32_t Type, uint64_t BaseAddr, | 
|  | 38 | uint64_t SymVA) const = 0; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 39 |  | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 40 | virtual ~TargetInfo(); | 
|  | 41 |  | 
|  | 42 | protected: | 
| Hal Finkel | e3c2626 | 2015-10-08 22:23:54 +0000 | [diff] [blame] | 43 | unsigned PageSize = 4096; | 
| Hal Finkel | 4729064 | 2015-10-08 21:25:04 +0000 | [diff] [blame] | 44 | uint64_t VAStart; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 45 | unsigned PCRelReloc; | 
| Rafael Espindola | 8acb95c | 2015-09-29 14:42:37 +0000 | [diff] [blame] | 46 | unsigned GotRefReloc; | 
| Rafael Espindola | 7f07442 | 2015-09-22 21:35:51 +0000 | [diff] [blame] | 47 | unsigned GotReloc; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 48 | unsigned RelativeReloc; | 
| Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 49 | unsigned PltEntrySize = 8; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 50 | }; | 
|  | 51 |  | 
|  | 52 | class X86TargetInfo final : public TargetInfo { | 
|  | 53 | public: | 
|  | 54 | X86TargetInfo(); | 
|  | 55 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 56 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 57 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | 6d7fcdb | 2015-09-29 13:36:32 +0000 | [diff] [blame] | 58 | bool relocPointsToGot(uint32_t Type) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 59 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 60 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 61 | uint32_t Type, uint64_t BaseAddr, | 
|  | 62 | uint64_t SymVA) const override; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 63 | }; | 
|  | 64 |  | 
|  | 65 | class X86_64TargetInfo final : public TargetInfo { | 
|  | 66 | public: | 
|  | 67 | X86_64TargetInfo(); | 
|  | 68 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 69 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 70 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 71 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 72 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 73 | uint32_t Type, uint64_t BaseAddr, | 
|  | 74 | uint64_t SymVA) const override; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 75 | bool isRelRelative(uint32_t Type) const override; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 76 | }; | 
|  | 77 |  | 
|  | 78 | class PPC64TargetInfo final : public TargetInfo { | 
|  | 79 | public: | 
|  | 80 | PPC64TargetInfo(); | 
|  | 81 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 82 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 83 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 84 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 85 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 86 | uint32_t Type, uint64_t BaseAddr, | 
|  | 87 | uint64_t SymVA) const override; | 
| Hal Finkel | be0823d | 2015-10-12 20:58:52 +0000 | [diff] [blame] | 88 | bool isRelRelative(uint32_t Type) const override; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 89 | }; | 
|  | 90 |  | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 91 | class PPCTargetInfo final : public TargetInfo { | 
|  | 92 | public: | 
|  | 93 | PPCTargetInfo(); | 
|  | 94 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 95 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 96 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 97 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 98 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 99 | uint32_t Type, uint64_t BaseAddr, | 
|  | 100 | uint64_t SymVA) const override; | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 101 | }; | 
|  | 102 |  | 
| Davide Italiano | cde9336 | 2015-09-26 00:32:04 +0000 | [diff] [blame] | 103 | class AArch64TargetInfo final : public TargetInfo { | 
|  | 104 | public: | 
|  | 105 | AArch64TargetInfo(); | 
|  | 106 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 107 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 108 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 109 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 110 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 111 | uint32_t Type, uint64_t BaseAddr, | 
|  | 112 | uint64_t SymVA) const override; | 
| Davide Italiano | cde9336 | 2015-09-26 00:32:04 +0000 | [diff] [blame] | 113 | }; | 
|  | 114 |  | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 115 | class MipsTargetInfo final : public TargetInfo { | 
|  | 116 | public: | 
|  | 117 | MipsTargetInfo(); | 
|  | 118 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
| Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame^] | 119 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 120 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 121 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Hal Finkel | 87bbd5f | 2015-10-12 21:19:18 +0000 | [diff] [blame] | 122 | void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP, | 
|  | 123 | uint32_t Type, uint64_t BaseAddr, | 
|  | 124 | uint64_t SymVA) const override; | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 125 | }; | 
|  | 126 |  | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 127 | extern std::unique_ptr<TargetInfo> Target; | 
| Rui Ueyama | 9100439 | 2015-10-13 16:08:15 +0000 | [diff] [blame] | 128 | TargetInfo *createTarget(); | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 129 | } | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | #endif |