| 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: | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 23 | llvm::StringRef getDefaultEntry() const { return DefaultEntry; } | 
| 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; } | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 29 | virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 30 | uint64_t PltEntryAddr) const = 0; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 31 | virtual bool isRelRelative(uint32_t Type) const; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 32 | virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0; | 
| Rafael Espindola | 6d7fcdb | 2015-09-29 13:36:32 +0000 | [diff] [blame] | 33 | virtual bool relocPointsToGot(uint32_t Type) const; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 34 | virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 35 | virtual void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 36 | uint64_t BaseAddr, uint64_t SymVA) const = 0; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 37 |  | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 38 | virtual ~TargetInfo(); | 
|  | 39 |  | 
|  | 40 | protected: | 
| Hal Finkel | 4729064 | 2015-10-08 21:25:04 +0000 | [diff] [blame^] | 41 | uint64_t VAStart; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 42 | unsigned PCRelReloc; | 
| Rafael Espindola | 8acb95c | 2015-09-29 14:42:37 +0000 | [diff] [blame] | 43 | unsigned GotRefReloc; | 
| Rafael Espindola | 7f07442 | 2015-09-22 21:35:51 +0000 | [diff] [blame] | 44 | unsigned GotReloc; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 45 | unsigned RelativeReloc; | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 46 | llvm::StringRef DefaultEntry = "_start"; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 47 | }; | 
|  | 48 |  | 
|  | 49 | class X86TargetInfo final : public TargetInfo { | 
|  | 50 | public: | 
|  | 51 | X86TargetInfo(); | 
|  | 52 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 53 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 54 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | 6d7fcdb | 2015-09-29 13:36:32 +0000 | [diff] [blame] | 55 | bool relocPointsToGot(uint32_t Type) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 56 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 57 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 58 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 59 | }; | 
|  | 60 |  | 
|  | 61 | class X86_64TargetInfo final : public TargetInfo { | 
|  | 62 | public: | 
|  | 63 | X86_64TargetInfo(); | 
|  | 64 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 65 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 66 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 67 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 68 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 69 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 70 | bool isRelRelative(uint32_t Type) const override; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 71 | }; | 
|  | 72 |  | 
|  | 73 | class PPC64TargetInfo final : public TargetInfo { | 
|  | 74 | public: | 
|  | 75 | PPC64TargetInfo(); | 
|  | 76 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 77 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 78 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 79 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | c401088 | 2015-09-22 20:54:08 +0000 | [diff] [blame] | 80 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 81 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 82 | }; | 
|  | 83 |  | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 84 | class PPCTargetInfo final : public TargetInfo { | 
|  | 85 | public: | 
|  | 86 | PPCTargetInfo(); | 
|  | 87 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 88 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 89 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 90 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 91 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 92 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 93 | }; | 
|  | 94 |  | 
|  | 95 | class ARMTargetInfo final : public TargetInfo { | 
|  | 96 | public: | 
|  | 97 | ARMTargetInfo(); | 
|  | 98 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 99 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 100 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 101 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 102 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 103 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 104 | }; | 
|  | 105 |  | 
| Davide Italiano | cde9336 | 2015-09-26 00:32:04 +0000 | [diff] [blame] | 106 | class AArch64TargetInfo final : public TargetInfo { | 
|  | 107 | public: | 
|  | 108 | AArch64TargetInfo(); | 
|  | 109 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 110 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 111 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 112 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Davide Italiano | cde9336 | 2015-09-26 00:32:04 +0000 | [diff] [blame] | 113 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 114 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Davide Italiano | cde9336 | 2015-09-26 00:32:04 +0000 | [diff] [blame] | 115 | }; | 
|  | 116 |  | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 117 | class MipsTargetInfo final : public TargetInfo { | 
|  | 118 | public: | 
|  | 119 | MipsTargetInfo(); | 
|  | 120 | void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, | 
|  | 121 | uint64_t PltEntryAddr) const override; | 
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 122 | bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; | 
|  | 123 | bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 124 | void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type, | 
| Rui Ueyama | af21d92 | 2015-10-08 20:06:07 +0000 | [diff] [blame] | 125 | uint64_t BaseAddr, uint64_t SymVA) const override; | 
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 126 | }; | 
|  | 127 |  | 
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 128 | extern std::unique_ptr<TargetInfo> Target; | 
|  | 129 | } | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | #endif |