]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Thunks.h
Merge lld trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / Thunks.h
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;
18 class ThunkSection;
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
24 // targets like ARM.
25 //
26 // Thunks can be created for DefinedRegular, Shared and Undefined Symbols.
27 // Thunks are assigned to synthetic ThunkSections
28 class Thunk {
29 public:
30   Thunk(const SymbolBody &Destination);
31   virtual ~Thunk();
32
33   virtual uint32_t size() const { return 0; }
34   virtual void writeTo(uint8_t *Buf, ThunkSection &IS) const {}
35
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) {}
39
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; }
43
44   // The alignment requirement for this Thunk, defaults to the size of the
45   // typical code section alignment.
46   const SymbolBody &Destination;
47   SymbolBody *ThunkSym;
48   uint64_t Offset;
49   uint32_t alignment = 4;
50 };
51
52 // For a Relocation to symbol S create a Thunk to be added to a synthetic
53 // ThunkSection. At present there are implementations for ARM and Mips Thunks.
54 template <class ELFT> Thunk *addThunk(uint32_t RelocType, SymbolBody &S);
55
56 } // namespace elf
57 } // namespace lld
58
59 #endif