| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 1 | //===- Thunks.h --------------------------------------------------------===// |
| 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_THUNKS_H |
| 11 | #define LLD_ELF_THUNKS_H |
| 12 | |
| 13 | #include "Relocations.h" |
| 14 | |
| 15 | namespace lld { |
| 16 | namespace elf { |
| 17 | class SymbolBody; |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 18 | template <class ELFT> class InputSection; |
| 19 | |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 20 | // Class to describe an instance of a Thunk. |
| 21 | // A Thunk is a code-sequence inserted by the linker in between a caller and |
| 22 | // the callee. The relocation to the callee is redirected to the Thunk, which |
| 23 | // after executing transfers control to the callee. Typical uses of Thunks |
| 24 | // include transferring control from non-pi to pi and changing state on |
| 25 | // targets like ARM. |
| 26 | // |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 27 | // Thunks can be created for DefinedRegular and Shared Symbols. The Thunk |
| 28 | // is stored in a field of the Symbol Destination. |
| 29 | // Thunks to be written to an InputSection are recorded by the InputSection. |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 30 | template <class ELFT> class Thunk { |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 31 | typedef typename ELFT::uint uintX_t; |
| 32 | |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 33 | public: |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 34 | Thunk(const SymbolBody &Destination, const InputSection<ELFT> &Owner); |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 35 | virtual ~Thunk(); |
| 36 | |
| Rui Ueyama | 0d410c26 | 2016-07-09 23:02:37 +0000 | [diff] [blame] | 37 | virtual uint32_t size() const { return 0; } |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 38 | virtual void writeTo(uint8_t *Buf) const {} |
| 39 | uintX_t getVA() const; |
| Rui Ueyama | 3d2bbb1 | 2016-07-09 22:52:30 +0000 | [diff] [blame] | 40 | |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 41 | protected: |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 42 | const SymbolBody &Destination; |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 43 | const InputSection<ELFT> &Owner; |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 44 | uint64_t Offset; |
| 45 | }; |
| 46 | |
| Rui Ueyama | f20ee9f | 2017-01-28 00:48:06 +0000 | [diff] [blame^] | 47 | // For a Relocation to symbol S from InputSection Src, create a Thunk and |
| 48 | // update the fields of S and the InputSection that the Thunk body will be |
| 49 | // written to. At present there are implementations for ARM and Mips Thunks. |
| 50 | template <class ELFT> |
| 51 | void addThunk(uint32_t RelocType, SymbolBody &S, InputSection<ELFT> &Src); |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 52 | |
| 53 | } // namespace elf |
| 54 | } // namespace lld |
| 55 | |
| 56 | #endif |