| 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" |
| Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 14 | #include "llvm/Object/ELF.h" |
| Simon Atanasyan | 49829a1 | 2015-09-29 05:34:03 +0000 | [diff] [blame] | 15 | |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
| 18 | namespace lld { |
| 19 | namespace elf2 { |
| 20 | class SymbolBody; |
| 21 | |
| 22 | class TargetInfo { |
| 23 | public: |
| Hal Finkel | e3c2626 | 2015-10-08 22:23:54 +0000 | [diff] [blame] | 24 | unsigned getPageSize() const { return PageSize; } |
| Igor Kudrin | f6f4547 | 2015-11-10 08:39:27 +0000 | [diff] [blame] | 25 | uint64_t getVAStart() const; |
| George Rimar | bc590fe | 2015-10-28 16:48:58 +0000 | [diff] [blame] | 26 | unsigned getCopyReloc() const { return CopyReloc; } |
| Rafael Espindola | 7f07442 | 2015-09-22 21:35:51 +0000 | [diff] [blame] | 27 | unsigned getGotReloc() const { return GotReloc; } |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 28 | unsigned getPltReloc() const { return PltReloc; } |
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 29 | unsigned getRelativeReloc() const { return RelativeReloc; } |
| Michael J. Spencer | ecd7f37 | 2015-11-13 00:32:58 +0000 | [diff] [blame] | 30 | bool isTlsLocalDynamicReloc(unsigned Type) const { |
| 31 | return Type == TlsLocalDynamicReloc; |
| 32 | } |
| 33 | bool isTlsGlobalDynamicReloc(unsigned Type) const { |
| 34 | return Type == TlsGlobalDynamicReloc; |
| 35 | } |
| Michael J. Spencer | 1e22561 | 2015-11-11 01:00:24 +0000 | [diff] [blame] | 36 | unsigned getTlsModuleIndexReloc() const { return TlsModuleIndexReloc; } |
| Michael J. Spencer | 627ae70 | 2015-11-13 00:28:34 +0000 | [diff] [blame] | 37 | unsigned getTlsOffsetReloc() const { return TlsOffsetReloc; } |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 38 | unsigned getPltZeroEntrySize() const { return PltZeroEntrySize; } |
| Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 39 | unsigned getPltEntrySize() const { return PltEntrySize; } |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 40 | bool supportsLazyRelocations() const { return LazyRelocations; } |
| Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 41 | unsigned getGotHeaderEntriesNum() const { return GotHeaderEntriesNum; } |
| Igor Kudrin | 351b41d | 2015-11-16 17:44:08 +0000 | [diff] [blame] | 42 | unsigned getGotPltHeaderEntriesNum() const { return GotPltHeaderEntriesNum; } |
| George Rimar | d23970f | 2015-11-25 20:41:53 +0000 | [diff] [blame] | 43 | virtual unsigned getDynReloc(unsigned Type) const { return Type; } |
| George Rimar | 6f17e09 | 2015-12-17 09:32:21 +0000 | [diff] [blame] | 44 | virtual bool isTlsDynReloc(unsigned Type, const SymbolBody &S) const { |
| 45 | return false; |
| 46 | } |
| Igor Kudrin | e7ad093 | 2015-11-17 17:47:53 +0000 | [diff] [blame] | 47 | virtual unsigned getPltRefReloc(unsigned Type) const; |
| George Rimar | 6f17e09 | 2015-12-17 09:32:21 +0000 | [diff] [blame] | 48 | virtual unsigned getTlsGotReloc(unsigned Type = -1) const { |
| 49 | return TlsGotReloc; |
| 50 | } |
| Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 51 | virtual void writeGotHeaderEntries(uint8_t *Buf) const; |
| Igor Kudrin | 351b41d | 2015-11-16 17:44:08 +0000 | [diff] [blame] | 52 | virtual void writeGotPltHeaderEntries(uint8_t *Buf) const; |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 53 | virtual void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const = 0; |
| 54 | virtual void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr, |
| 55 | uint64_t PltEntryAddr) const = 0; |
| George Rimar | 77b7779 | 2015-11-25 22:15:01 +0000 | [diff] [blame] | 56 | virtual void writePltEntry(uint8_t *Buf, uint64_t GotAddr, |
| 57 | uint64_t GotEntryAddr, uint64_t PltEntryAddr, |
| 58 | int32_t Index, unsigned RelOff) const = 0; |
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 59 | virtual bool isRelRelative(uint32_t Type) const; |
| George Rimar | 4865148 | 2015-12-11 08:59:37 +0000 | [diff] [blame] | 60 | virtual bool isSizeDynReloc(uint32_t Type, const SymbolBody &S) const; |
| George Rimar | 6f17e09 | 2015-12-17 09:32:21 +0000 | [diff] [blame] | 61 | virtual bool relocNeedsDynRelative(unsigned Type) const { return false; } |
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 62 | virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0; |
| Rafael Espindola | 3ef3a4c | 2015-09-29 23:22:16 +0000 | [diff] [blame] | 63 | virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0; |
| Rui Ueyama | 96f0e0b | 2015-10-23 02:40:46 +0000 | [diff] [blame] | 64 | virtual void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, |
| George Rimar | 4865148 | 2015-12-11 08:59:37 +0000 | [diff] [blame] | 65 | uint64_t P, uint64_t SA, uint64_t ZA = 0, |
| Simon Atanasyan | 09b3e36 | 2015-12-01 21:24:45 +0000 | [diff] [blame] | 66 | uint8_t *PairedLoc = nullptr) const = 0; |
| George Rimar | bfb7bf7 | 2015-12-21 10:00:12 +0000 | [diff] [blame^] | 67 | virtual bool isGotRelative(uint32_t Type) const; |
| George Rimar | 6713cf8 | 2015-11-25 21:46:05 +0000 | [diff] [blame] | 68 | virtual bool isTlsOptimized(unsigned Type, const SymbolBody *S) const; |
| Rui Ueyama | 02dfd49 | 2015-12-17 01:18:40 +0000 | [diff] [blame] | 69 | virtual bool needsCopyRel(uint32_t Type, const SymbolBody &S) const; |
| George Rimar | 6713cf8 | 2015-11-25 21:46:05 +0000 | [diff] [blame] | 70 | virtual unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, |
| George Rimar | 25411f25 | 2015-12-04 11:20:13 +0000 | [diff] [blame] | 71 | uint32_t Type, uint64_t P, uint64_t SA, |
| 72 | const SymbolBody &S) const; |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 73 | virtual ~TargetInfo(); |
| 74 | |
| 75 | protected: |
| Hal Finkel | e3c2626 | 2015-10-08 22:23:54 +0000 | [diff] [blame] | 76 | unsigned PageSize = 4096; |
| Hal Finkel | 736c741 | 2015-10-15 07:49:07 +0000 | [diff] [blame] | 77 | |
| 78 | // On freebsd x86_64 the first page cannot be mmaped. |
| 79 | // On linux that is controled by vm.mmap_min_addr. At least on some x86_64 |
| 80 | // installs that is 65536, so the first 15 pages cannot be used. |
| 81 | // Given that, the smallest value that can be used in here is 0x10000. |
| 82 | // If using 2MB pages, the smallest page aligned address that works is |
| 83 | // 0x200000, but it looks like every OS uses 4k pages for executables. |
| 84 | uint64_t VAStart = 0x10000; |
| 85 | |
| George Rimar | bc590fe | 2015-10-28 16:48:58 +0000 | [diff] [blame] | 86 | unsigned CopyReloc; |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 87 | unsigned PCRelReloc; |
| Rafael Espindola | 7f07442 | 2015-09-22 21:35:51 +0000 | [diff] [blame] | 88 | unsigned GotReloc; |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 89 | unsigned PltReloc; |
| Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 90 | unsigned RelativeReloc; |
| George Rimar | 687138c | 2015-11-13 16:28:53 +0000 | [diff] [blame] | 91 | unsigned TlsGotReloc = 0; |
| Michael J. Spencer | 1e22561 | 2015-11-11 01:00:24 +0000 | [diff] [blame] | 92 | unsigned TlsLocalDynamicReloc = 0; |
| Michael J. Spencer | 627ae70 | 2015-11-13 00:28:34 +0000 | [diff] [blame] | 93 | unsigned TlsGlobalDynamicReloc = 0; |
| Michael J. Spencer | 1e22561 | 2015-11-11 01:00:24 +0000 | [diff] [blame] | 94 | unsigned TlsModuleIndexReloc; |
| Michael J. Spencer | 627ae70 | 2015-11-13 00:28:34 +0000 | [diff] [blame] | 95 | unsigned TlsOffsetReloc; |
| Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 96 | unsigned PltEntrySize = 8; |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 97 | unsigned PltZeroEntrySize = 0; |
| Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 98 | unsigned GotHeaderEntriesNum = 0; |
| Igor Kudrin | 351b41d | 2015-11-16 17:44:08 +0000 | [diff] [blame] | 99 | unsigned GotPltHeaderEntriesNum = 3; |
| George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 100 | bool LazyRelocations = false; |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame] | 103 | uint64_t getPPC64TocBase(); |
| 104 | |
| Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 105 | template <class ELFT> |
| 106 | typename llvm::object::ELFFile<ELFT>::uintX_t getMipsGpAddr(); |
| 107 | |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 108 | extern std::unique_ptr<TargetInfo> Target; |
| Rui Ueyama | 9100439 | 2015-10-13 16:08:15 +0000 | [diff] [blame] | 109 | TargetInfo *createTarget(); |
| Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | #endif |