xref: /llvm-project/bolt/include/bolt/Passes/ValidateMemRefs.h (revision a5f3d1a803020167bd9d494a8a3921e7dcc1550a)
1 //===- bolt/Passes/ValidateMemRefs.h ----------------------------*- 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 #ifndef BOLT_PASSES_VALIDATEMEMREFS_H
10 #define BOLT_PASSES_VALIDATEMEMREFS_H
11 
12 #include "bolt/Passes/BinaryPasses.h"
13 
14 namespace llvm::bolt {
15 
16 /// Post processing to check for memory references that cause a symbol
17 /// in data section to be ambiguous, requiring us to avoid moving that
18 /// object or disambiguating such references. This is currently
19 /// limited to fixing false references to the location of jump tables.
20 ///
21 class ValidateMemRefs : public BinaryFunctionPass {
22 public:
ValidateMemRefs(const cl::opt<bool> & PrintPass)23   explicit ValidateMemRefs(const cl::opt<bool> &PrintPass)
24       : BinaryFunctionPass(PrintPass) {}
25 
getName()26   const char *getName() const override { return "validate-mem-refs"; }
27 
28   Error runOnFunctions(BinaryContext &BC) override;
29 
30 private:
31   bool checkAndFixJTReference(BinaryFunction &BF, MCInst &Inst,
32                               uint32_t OperandNum, const MCSymbol *Sym,
33                               uint64_t Offset);
34   void runOnFunction(BinaryFunction &BF);
35 
36   static std::atomic<std::uint64_t> ReplacedReferences;
37 };
38 
39 } // namespace llvm::bolt
40 
41 #endif
42