xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 //===-- RuntimeDyldCheckerImpl.h -- RuntimeDyld test framework --*- 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 LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
10 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
11 
12 #include "RuntimeDyldImpl.h"
13 
14 namespace llvm {
15 
16 class RuntimeDyldCheckerImpl {
17   friend class RuntimeDyldChecker;
18   friend class RuntimeDyldCheckerExprEval;
19 
20   using IsSymbolValidFunction =
21     RuntimeDyldChecker::IsSymbolValidFunction;
22   using GetSymbolInfoFunction = RuntimeDyldChecker::GetSymbolInfoFunction;
23   using GetSectionInfoFunction = RuntimeDyldChecker::GetSectionInfoFunction;
24   using GetStubInfoFunction = RuntimeDyldChecker::GetStubInfoFunction;
25   using GetGOTInfoFunction = RuntimeDyldChecker::GetGOTInfoFunction;
26 
27 public:
28   RuntimeDyldCheckerImpl(
29       IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo,
30       GetSectionInfoFunction GetSectionInfo, GetStubInfoFunction GetStubInfo,
31       GetGOTInfoFunction GetGOTInfo, support::endianness Endianness,
32       MCDisassembler *Disassembler, MCInstPrinter *InstPrinter,
33       llvm::raw_ostream &ErrStream);
34 
35   bool check(StringRef CheckExpr) const;
36   bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
37 
38 private:
39 
40   // StubMap typedefs.
41 
42   Expected<JITSymbolResolver::LookupResult>
43   lookup(const JITSymbolResolver::LookupSet &Symbols) const;
44 
45   bool isSymbolValid(StringRef Symbol) const;
46   uint64_t getSymbolLocalAddr(StringRef Symbol) const;
47   uint64_t getSymbolRemoteAddr(StringRef Symbol) const;
48   uint64_t readMemoryAtAddr(uint64_t Addr, unsigned Size) const;
49 
50   StringRef getSymbolContent(StringRef Symbol) const;
51 
52   std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
53                                                   StringRef SectionName,
54                                                   bool IsInsideLoad) const;
55 
56   std::pair<uint64_t, std::string>
57   getStubOrGOTAddrFor(StringRef StubContainerName, StringRef Symbol,
58                       bool IsInsideLoad, bool IsStubAddr) const;
59 
60   std::optional<uint64_t> getSectionLoadAddress(void *LocalAddr) const;
61 
62   IsSymbolValidFunction IsSymbolValid;
63   GetSymbolInfoFunction GetSymbolInfo;
64   GetSectionInfoFunction GetSectionInfo;
65   GetStubInfoFunction GetStubInfo;
66   GetGOTInfoFunction GetGOTInfo;
67   support::endianness Endianness;
68   MCDisassembler *Disassembler;
69   MCInstPrinter *InstPrinter;
70   llvm::raw_ostream &ErrStream;
71 };
72 }
73 
74 #endif
75