AMDGPU: Fix warnings introduced by r310336
[llvm-project.git] / lld / ELF / Thunks.h
blob21eba699fe4fbf71278e57b7983f5fbc41bfad48
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 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_THUNKS_H
11 #define LLD_ELF_THUNKS_H
13 #include "Relocations.h"
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.
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();
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;
51 SymbolBody *ThunkSym;
52 uint64_t Offset;
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);
60 } // namespace elf
61 } // namespace lld
63 #endif