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"
32 orc::ExecutionSession ES
;
33 orc::JITDylib
*MainJD
= nullptr;
34 orc::JITDylib
*ProcessSymsJD
= nullptr;
35 orc::JITDylib
*PlatformJD
= 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
<SmallVector
<MemoryRegionInfo
, 1>> StubInfos
;
53 StringMap
<MemoryRegionInfo
> GOTEntryInfos
;
55 using Symbol
= jitlink::Symbol
;
56 using LinkGraph
= jitlink::LinkGraph
;
57 using GetSymbolTargetFunction
=
58 unique_function
<Expected
<Symbol
&>(LinkGraph
&G
, jitlink::Block
&)>;
60 Error
registerGOTEntry(LinkGraph
&G
, Symbol
&Sym
,
61 GetSymbolTargetFunction GetSymbolTarget
);
62 Error
registerStubEntry(LinkGraph
&G
, Symbol
&Sym
,
63 GetSymbolTargetFunction GetSymbolTarget
);
64 Error
registerMultiStubEntry(LinkGraph
&G
, Symbol
&Sym
,
65 GetSymbolTargetFunction GetSymbolTarget
);
68 using DynLibJDMap
= std::map
<std::string
, orc::JITDylib
*>;
69 using SymbolInfoMap
= StringMap
<MemoryRegionInfo
>;
70 using FileInfoMap
= StringMap
<FileInfo
>;
72 Expected
<orc::JITDylib
*> getOrLoadDynamicLibrary(StringRef LibPath
);
73 Error
loadAndLinkDynamicLibrary(orc::JITDylib
&JD
, StringRef LibPath
);
75 Expected
<FileInfo
&> findFileInfo(StringRef FileName
);
76 Expected
<MemoryRegionInfo
&> findSectionInfo(StringRef FileName
,
77 StringRef SectionName
);
78 Expected
<MemoryRegionInfo
&> findStubInfo(StringRef FileName
,
80 StringRef KindNameFilter
);
81 Expected
<MemoryRegionInfo
&> findGOTEntryInfo(StringRef FileName
,
82 StringRef TargetName
);
84 bool isSymbolRegistered(StringRef Name
);
85 Expected
<MemoryRegionInfo
&> findSymbolInfo(StringRef SymbolName
,
88 DynLibJDMap DynLibJDs
;
90 SymbolInfoMap SymbolInfos
;
91 FileInfoMap FileInfos
;
93 StringSet
<> HarnessFiles
;
94 StringSet
<> HarnessExternals
;
95 StringSet
<> HarnessDefinitions
;
96 DenseMap
<StringRef
, StringRef
> CanonicalWeakDefs
;
98 std::optional
<Regex
> ShowGraphsRegex
;
101 Session(std::unique_ptr
<orc::ExecutorProcessControl
> EPC
, Error
&Err
);
104 /// Record symbols, GOT entries, stubs, and sections for ELF file.
105 Error
registerELFGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
107 /// Record symbols, GOT entries, stubs, and sections for MachO file.
108 Error
registerMachOGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
110 /// Record symbols, GOT entries, stubs, and sections for COFF file.
111 Error
registerCOFFGraphInfo(Session
&S
, jitlink::LinkGraph
&G
);
113 /// Adds a statistics gathering plugin if any stats options are used.
114 void enableStatistics(Session
&S
, bool UsingOrcRuntime
);
116 } // end namespace llvm
118 #endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H