1//===- bolt/Rewrite/ExecutableFileMemoryManager.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_REWRITE_EXECUTABLE_FILE_MEMORY_MANAGER_H
10#define BOLT_REWRITE_EXECUTABLE_FILE_MEMORY_MANAGER_H
11
12#include "llvm/ADT/StringRef.h"
13#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
14#include <cstdint>
15#include <string>
16
17namespace llvm {
18
19namespace bolt {
20class BinaryContext;
21
22/// Class responsible for allocating and managing code and data sections.
23class ExecutableFileMemoryManager : public jitlink::JITLinkMemoryManager {
24private:
25 void updateSection(const jitlink::Section &Section, uint8_t *Contents,
26 size_t Size, size_t Alignment);
27
28 BinaryContext &BC;
29
30 // All new sections will be identified by the following prefix.
31 std::string NewSecPrefix;
32
33 // Name prefix used for sections from the input.
34 std::string OrgSecPrefix;
35
36public:
37 // Our linker's main purpose is to handle a single object file, created
38 // by RewriteInstance after reading the input binary and reordering it.
39 // After objects finish loading, we increment this. Therefore, whenever
40 // this is greater than zero, we are dealing with additional objects that
41 // will not be managed by BinaryContext but only exist to support linking
42 // user-supplied objects into the main input executable.
43 uint32_t ObjectsLoaded{0};
44
45 ExecutableFileMemoryManager(BinaryContext &BC) : BC(BC) {}
46
47 void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
48 OnAllocatedFunction OnAllocated) override;
49
50 void deallocate(std::vector<FinalizedAlloc> Allocs,
51 OnDeallocatedFunction OnDeallocated) override;
52 using JITLinkMemoryManager::deallocate;
53
54 /// Section name management.
55 void setNewSecPrefix(StringRef Prefix) { NewSecPrefix = Prefix; }
56 void setOrgSecPrefix(StringRef Prefix) { OrgSecPrefix = Prefix; }
57};
58
59} // namespace bolt
60} // namespace llvm
61
62#endif
63

source code of bolt/include/bolt/Rewrite/ExecutableFileMemoryManager.h