1 //===---- llvm-jitlink.h - Session and format-specific decls ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // llvm-jitlink Session class and tool utilities.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
14 #define LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/ExecutionEngine/Orc/Core.h"
18 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
19 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
20 #include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
21 #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/Regex.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/TargetParser/SubtargetFeature.h"
26 #include "llvm/TargetParser/Triple.h"
34 orc::ExecutionSession ES
;
35 orc::JITDylib
*MainJD
= nullptr;
36 orc::ObjectLinkingLayer ObjLayer
;
37 orc::JITDylibSearchOrder JDSearchOrder
;
38 SubtargetFeatures Features
;
42 static Expected
<std::unique_ptr
<Session
>> Create(Triple TT
,
43 SubtargetFeatures Features
);
44 void dumpSessionInfo(raw_ostream
&OS
);
45 void modifyPassConfig(const Triple
&FTT
,
46 jitlink::PassConfiguration
&PassConfig
);
48 using MemoryRegionInfo
= RuntimeDyldChecker::MemoryRegionInfo
;
51 StringMap
<MemoryRegionInfo
> SectionInfos
;
52 StringMap
<MemoryRegionInfo
> StubInfos
;
53 StringMap
<MemoryRegionInfo
> GOTEntryInfos
;
56 using DynLibJDMap
= std::map
<std::string
, orc::JITDylib
*>;
57 using SymbolInfoMap
= StringMap
<MemoryRegionInfo
>;
58 using FileInfoMap
= StringMap
<FileInfo
>;
60 Expected
<orc::JITDylib
*> getOrLoadDynamicLibrary(StringRef LibPath
);
61 Error
loadAndLinkDynamicLibrary(orc::JITDylib
&JD
, StringRef LibPath
);
63 Expected
<FileInfo
&> findFileInfo(StringRef FileName
);
64 Expected
<MemoryRegionInfo
&> findSectionInfo(StringRef FileName
,
65 StringRef SectionName
);
66 Expected
<MemoryRegionInfo
&> findStubInfo(StringRef FileName
,
67 StringRef TargetName
);
68 Expected
<MemoryRegionInfo
&> findGOTEntryInfo(StringRef FileName
,
69 StringRef TargetName
);
71 bool isSymbolRegistered(StringRef Name
);
72 Expected
<MemoryRegionInfo
&> findSymbolInfo(StringRef SymbolName
,
75 DynLibJDMap DynLibJDs
;
77 SymbolInfoMap SymbolInfos
;
78 FileInfoMap FileInfos
;
80 StringSet
<> HarnessFiles
;
81 StringSet
<> HarnessExternals
;
82 StringSet
<> HarnessDefinitions
;
83 DenseMap
<StringRef
, StringRef
> CanonicalWeakDefs
;
85 std::optional
<Regex
> ShowGraphsRegex
;
88 Session(std::unique_ptr
<orc::ExecutorProcessControl
> EPC
, Error
&Err
);
91 /// Record symbols, GOT entries, stubs, and sections for ELF file.
92 Error
registerELFGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
94 /// Record symbols, GOT entries, stubs, and sections for MachO file.
95 Error
registerMachOGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
97 /// Record symbols, GOT entries, stubs, and sections for COFF file.
98 Error
registerCOFFGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
100 /// Adds a statistics gathering plugin if any stats options are used.
101 void enableStatistics(Session
&S
, bool UsingOrcRuntime
);
103 } // end namespace llvm
105 #endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H