blob: 258f37f747d937e6c5e034e2d9198b34504d2606 [file] [log] [blame]
Peter Smithfb05cd92016-07-08 16:10:27 +00001//===- 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
15namespace lld {
16namespace elf {
17class SymbolBody;
18class InputFile;
19template <class ELFT> class InputSection;
20template <class ELFT> class InputSectionBase;
21
22// Class to describe an instance of a Thunk.
23// A Thunk is a code-sequence inserted by the linker in between a caller and
24// the callee. The relocation to the callee is redirected to the Thunk, which
25// after executing transfers control to the callee. Typical uses of Thunks
26// include transferring control from non-pi to pi and changing state on
27// targets like ARM.
28//
29// Thunks can be created for DefinedRegular and Shared Symbols. The Thunk
30// is stored in a field of the Symbol Destination.
31// Thunks to be written to an InputSection are recorded by the InputSection.
32template <class ELFT> class Thunk {
Rui Ueyama3d2bbb12016-07-09 22:52:30 +000033 typedef typename ELFT::uint uintX_t;
34
Peter Smithfb05cd92016-07-08 16:10:27 +000035public:
Peter Smithfb05cd92016-07-08 16:10:27 +000036 Thunk(const SymbolBody &Destination, const InputSection<ELFT> &Owner);
37 virtual ~Thunk();
38
Rui Ueyama3d2bbb12016-07-09 22:52:30 +000039 virtual uint32_t size() const = 0;
40 virtual void writeTo(uint8_t *Buf) const = 0;
41 uintX_t getVA() const;
42
Peter Smithfb05cd92016-07-08 16:10:27 +000043protected:
44 const SymbolBody &Destination;
45 const InputSection<ELFT> &Owner;
46 uint64_t Offset;
47};
48
49// For a Relocation to symbol S from InputSection Src, create a Thunk and
50// update the fields of S and the InputSection that the Thunk body will be
51// written to. At present there are implementations for ARM and Mips Thunks.
52template <class ELFT>
53void addThunk(uint32_t RelocType, SymbolBody &S, InputSection<ELFT> &Src);
54
55} // namespace elf
56} // namespace lld
57
58#endif