blob: c888baec9adf4909d54313801fc0d8dcd76c62de [file] [log] [blame]
Lang Hames11c8dfa52019-04-20 17:10:34 +00001//===---- llvm-jitlink.h - Session and format-specific decls ----*- 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// Utilities for remote-JITing with LLI.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
14#define LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
15
16#include "llvm/ADT/Triple.h"
17#include "llvm/ExecutionEngine/Orc/Core.h"
18#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
19#include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/raw_ostream.h"
22
23#include <vector>
24
25namespace llvm {
26
27struct Session {
28 orc::ExecutionSession ES;
Lang Hames85fb9972019-12-16 02:50:40 -080029 orc::JITDylib *MainJD;
Lang Hames11c8dfa52019-04-20 17:10:34 +000030 orc::ObjectLinkingLayer ObjLayer;
31 std::vector<orc::JITDylib *> JDSearchOrder;
32 Triple TT;
33
34 Session(Triple TT);
Lang Hames85fb9972019-12-16 02:50:40 -080035 static Expected<std::unique_ptr<Session>> Create(Triple TT);
Lang Hames11c8dfa52019-04-20 17:10:34 +000036 void dumpSessionInfo(raw_ostream &OS);
37 void modifyPassConfig(const Triple &FTT,
38 jitlink::PassConfiguration &PassConfig);
39
40 using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
41
42 struct FileInfo {
43 StringMap<MemoryRegionInfo> SectionInfos;
44 StringMap<MemoryRegionInfo> StubInfos;
45 StringMap<MemoryRegionInfo> GOTEntryInfos;
46 };
47
48 using SymbolInfoMap = StringMap<MemoryRegionInfo>;
49 using FileInfoMap = StringMap<FileInfo>;
50
51 Expected<FileInfo &> findFileInfo(StringRef FileName);
52 Expected<MemoryRegionInfo &> findSectionInfo(StringRef FileName,
53 StringRef SectionName);
54 Expected<MemoryRegionInfo &> findStubInfo(StringRef FileName,
55 StringRef TargetName);
56 Expected<MemoryRegionInfo &> findGOTEntryInfo(StringRef FileName,
57 StringRef TargetName);
58
59 bool isSymbolRegistered(StringRef Name);
60 Expected<MemoryRegionInfo &> findSymbolInfo(StringRef SymbolName,
61 Twine ErrorMsgStem);
62
63 SymbolInfoMap SymbolInfos;
64 FileInfoMap FileInfos;
65 uint64_t SizeBeforePruning = 0;
66 uint64_t SizeAfterFixups = 0;
Lang Hames85fb9972019-12-16 02:50:40 -080067
68private:
69 Session(Triple TT, Error &Err);
Lang Hames11c8dfa52019-04-20 17:10:34 +000070};
71
Lang Hames4e920e52019-10-04 03:55:26 +000072Error registerMachOStubsAndGOT(Session &S, jitlink::LinkGraph &G);
Lang Hames11c8dfa52019-04-20 17:10:34 +000073
74} // end namespace llvm
75
76#endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H