annotate lld/ELF/Thunks.h @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- Thunks.h --------------------------------------------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLD_ELF_THUNKS_H
anatofuz
parents:
diff changeset
10 #define LLD_ELF_THUNKS_H
anatofuz
parents:
diff changeset
11
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 #include "llvm/ADT/SmallVector.h"
150
anatofuz
parents:
diff changeset
13 #include "Relocations.h"
anatofuz
parents:
diff changeset
14
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
15 namespace lld::elf {
150
anatofuz
parents:
diff changeset
16 class Defined;
anatofuz
parents:
diff changeset
17 class InputFile;
anatofuz
parents:
diff changeset
18 class Symbol;
anatofuz
parents:
diff changeset
19 class ThunkSection;
anatofuz
parents:
diff changeset
20 // Class to describe an instance of a Thunk.
anatofuz
parents:
diff changeset
21 // A Thunk is a code-sequence inserted by the linker in between a caller and
anatofuz
parents:
diff changeset
22 // the callee. The relocation to the callee is redirected to the Thunk, which
anatofuz
parents:
diff changeset
23 // after executing transfers control to the callee. Typical uses of Thunks
anatofuz
parents:
diff changeset
24 // include transferring control from non-pi to pi and changing state on
anatofuz
parents:
diff changeset
25 // targets like ARM.
anatofuz
parents:
diff changeset
26 //
anatofuz
parents:
diff changeset
27 // Thunks can be created for Defined, Shared and Undefined Symbols.
anatofuz
parents:
diff changeset
28 // Thunks are assigned to synthetic ThunkSections
anatofuz
parents:
diff changeset
29 class Thunk {
anatofuz
parents:
diff changeset
30 public:
anatofuz
parents:
diff changeset
31 Thunk(Symbol &destination, int64_t addend);
anatofuz
parents:
diff changeset
32 virtual ~Thunk();
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 virtual uint32_t size() = 0;
anatofuz
parents:
diff changeset
35 virtual void writeTo(uint8_t *buf) = 0;
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // All Thunks must define at least one symbol, known as the thunk target
anatofuz
parents:
diff changeset
38 // symbol, so that we can redirect relocations to it. The thunk may define
anatofuz
parents:
diff changeset
39 // additional symbols, but these are never targets for relocations.
anatofuz
parents:
diff changeset
40 virtual void addSymbols(ThunkSection &isec) = 0;
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 void setOffset(uint64_t offset);
anatofuz
parents:
diff changeset
43 Defined *addSymbol(StringRef name, uint8_t type, uint64_t value,
anatofuz
parents:
diff changeset
44 InputSectionBase &section);
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 // Some Thunks must be placed immediately before their Target as they elide
anatofuz
parents:
diff changeset
47 // a branch and fall through to the first Symbol in the Target.
anatofuz
parents:
diff changeset
48 virtual InputSection *getTargetInputSection() const { return nullptr; }
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 // To reuse a Thunk the InputSection and the relocation must be compatible
anatofuz
parents:
diff changeset
51 // with it.
anatofuz
parents:
diff changeset
52 virtual bool isCompatibleWith(const InputSection &,
anatofuz
parents:
diff changeset
53 const Relocation &) const {
anatofuz
parents:
diff changeset
54 return true;
anatofuz
parents:
diff changeset
55 }
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 Defined *getThunkTargetSym() const { return syms[0]; }
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 Symbol &destination;
anatofuz
parents:
diff changeset
60 int64_t addend;
anatofuz
parents:
diff changeset
61 llvm::SmallVector<Defined *, 3> syms;
anatofuz
parents:
diff changeset
62 uint64_t offset = 0;
anatofuz
parents:
diff changeset
63 // The alignment requirement for this Thunk, defaults to the size of the
anatofuz
parents:
diff changeset
64 // typical code section alignment.
anatofuz
parents:
diff changeset
65 uint32_t alignment = 4;
anatofuz
parents:
diff changeset
66 };
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 // For a Relocation to symbol S create a Thunk to be added to a synthetic
anatofuz
parents:
diff changeset
69 // ThunkSection.
anatofuz
parents:
diff changeset
70 Thunk *addThunk(const InputSection &isec, Relocation &rel);
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 void writePPC32PltCallStub(uint8_t *buf, uint64_t gotPltVA,
anatofuz
parents:
diff changeset
73 const InputFile *file, int64_t addend);
anatofuz
parents:
diff changeset
74 void writePPC64LoadAndBranch(uint8_t *buf, int64_t offset);
anatofuz
parents:
diff changeset
75
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
76 } // namespace lld::elf
150
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 #endif