1 //===- Thunks.h --------------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_THUNKS_H
11 #define LLD_ELF_THUNKS_H
13 #include "Relocations.h"
19 // Class to describe an instance of a Thunk.
20 // A Thunk is a code-sequence inserted by the linker in between a caller and
21 // the callee. The relocation to the callee is redirected to the Thunk, which
22 // after executing transfers control to the callee. Typical uses of Thunks
23 // include transferring control from non-pi to pi and changing state on
26 // Thunks can be created for DefinedRegular, Shared and Undefined Symbols.
27 // Thunks are assigned to synthetic ThunkSections
30 Thunk(const SymbolBody
&Destination
);
33 virtual uint32_t size() const { return 0; }
34 virtual void writeTo(uint8_t *Buf
, ThunkSection
&IS
) const {}
36 // All Thunks must define at least one symbol ThunkSym so that we can
37 // redirect relocations to it.
38 virtual void addSymbols(ThunkSection
&IS
) {}
40 // Some Thunks must be placed immediately before their Target as they elide
41 // a branch and fall through to the first Symbol in the Target.
42 virtual InputSection
*getTargetInputSection() const { return nullptr; }
44 // To reuse a Thunk the caller as identified by the RelocType must be
45 // compatible with it.
46 virtual bool isCompatibleWith(uint32_t RelocType
) const { return true; }
48 // The alignment requirement for this Thunk, defaults to the size of the
49 // typical code section alignment.
50 const SymbolBody
&Destination
;
53 uint32_t Alignment
= 4;
56 // For a Relocation to symbol S create a Thunk to be added to a synthetic
57 // ThunkSection. At present there are implementations for ARM and Mips Thunks.
58 Thunk
*addThunk(uint32_t RelocType
, SymbolBody
&S
);