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