xref: /llvm-project/bolt/include/bolt/Passes/PatchEntries.h (revision a5f3d1a803020167bd9d494a8a3921e7dcc1550a)
1 //===- bolt/Passes/PatchEntries.h - Patch function entries ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Pass for patching original function entry points.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef BOLT_PASSES_PATCH_ENTRIES_H
14 #define BOLT_PASSES_PATCH_ENTRIES_H
15 
16 #include "bolt/Passes/BinaryPasses.h"
17 
18 namespace llvm {
19 namespace bolt {
20 
21 /// Pass for patching original function entry points.
22 class PatchEntries : public BinaryFunctionPass {
23   // If the function size is below the threshold, attempt to skip patching it.
24   static constexpr uint64_t PatchThreshold = 128;
25 
26   struct Patch {
27     const MCSymbol *Symbol;
28     uint64_t Address;
29     uint64_t FileOffset;
30     BinarySection *Section;
31   };
32 
33 public:
PatchEntries()34   explicit PatchEntries() : BinaryFunctionPass(false) {}
35 
getName()36   const char *getName() const override { return "patch-entries"; }
37   Error runOnFunctions(BinaryContext &BC) override;
38 };
39 
40 } // namespace bolt
41 } // namespace llvm
42 
43 #endif
44