1 //===- bolt/Rewrite/JITLinkLinker.h - Linker using JITLink ------*- 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 // BOLTLinker using JITLink. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef BOLT_REWRITE_JITLINK_LINKER_H 14 #define BOLT_REWRITE_JITLINK_LINKER_H 15 16 #include "bolt/Core/Linker.h" 17 #include "bolt/Rewrite/ExecutableFileMemoryManager.h" 18 #include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h" 19 20 #include <memory> 21 #include <vector> 22 23 namespace llvm { 24 namespace bolt { 25 26 class BinaryContext; 27 28 class JITLinkLinker : public BOLTLinker { 29 private: 30 struct Context; 31 friend struct Context; 32 33 BinaryContext &BC; 34 std::unique_ptr<ExecutableFileMemoryManager> MM; 35 jitlink::JITLinkDylib Dylib{"main"}; 36 std::vector<ExecutableFileMemoryManager::FinalizedAlloc> Allocs; 37 StringMap<SymbolInfo> Symtab; 38 39 public: 40 JITLinkLinker(BinaryContext &BC, 41 std::unique_ptr<ExecutableFileMemoryManager> MM); 42 ~JITLinkLinker(); 43 44 void loadObject(MemoryBufferRef Obj, SectionsMapper MapSections) override; 45 std::optional<SymbolInfo> lookupSymbolInfo(StringRef Name) const override; 46 47 static SmallVector<jitlink::Block *, 2> 48 orderedBlocks(const jitlink::Section &Section); 49 static size_t sectionSize(const jitlink::Section &Section); 50 }; 51 52 } // namespace bolt 53 } // namespace llvm 54 55 #endif // BOLT_REWRITE_JITLINK_LINKER_H 56