1//===- bolt/RuntimeLibs/RuntimeLibrary.h - Runtime Library ------*- 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// This file contains the declaration of the RuntimeLibrary class, which
10// provides all the necessary utilities to link runtime libraries during binary
11// rewriting, such as the instrumentation runtime library.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef BOLT_RUNTIMELIBS_RUNTIME_LIBRARY_H
16#define BOLT_RUNTIMELIBS_RUNTIME_LIBRARY_H
17
18#include "bolt/Core/Linker.h"
19#include "llvm/ADT/StringRef.h"
20#include <vector>
21
22namespace llvm {
23
24class MCStreamer;
25
26namespace bolt {
27
28class BinaryContext;
29
30class RuntimeLibrary {
31 // vtable anchor.
32 virtual void anchor();
33
34public:
35 virtual ~RuntimeLibrary() = default;
36
37 uint64_t getRuntimeFiniAddress() const { return RuntimeFiniAddress; }
38
39 uint64_t getRuntimeStartAddress() const { return RuntimeStartAddress; }
40
41 /// Add custom sections added by the runtime libraries.
42 virtual void
43 addRuntimeLibSections(std::vector<std::string> &SecNames) const = 0;
44
45 /// Validity check and modify if necessary all the command line options
46 /// for this runtime library.
47 virtual void adjustCommandLineOptions(const BinaryContext &BC) const = 0;
48
49 /// Emit data structures that will be necessary during runtime.
50 virtual void emitBinary(BinaryContext &BC, MCStreamer &Streamer) = 0;
51
52 /// Link with the library code.
53 virtual void link(BinaryContext &BC, StringRef ToolPath, BOLTLinker &Linker,
54 BOLTLinker::SectionsMapper MapSections) = 0;
55
56protected:
57 /// The fini and init address set by the runtime library.
58 uint64_t RuntimeFiniAddress{0};
59 uint64_t RuntimeStartAddress{0};
60
61 /// Get the full path to a runtime library specified by \p LibFileName.
62 static std::string getLibPath(StringRef ToolPath, StringRef LibFileName);
63
64 /// Load a static runtime library specified by \p LibPath.
65 static void loadLibrary(StringRef LibPath, BOLTLinker &Linker,
66 BOLTLinker::SectionsMapper MapSections);
67};
68
69} // namespace bolt
70} // namespace llvm
71
72#endif // BOLT_RUNTIMELIBS_RUNTIME_LIBRARY_H
73

source code of bolt/include/bolt/RuntimeLibs/RuntimeLibrary.h