[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / tools / llvm-jitlink / llvm-jitlink.h
blob71bdab7862c6e6e934368f0db4442e79ed52cd19
1 //===---- 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 // 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/Optional.h"
17 #include "llvm/ADT/StringSet.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/ExecutionEngine/Orc/Core.h"
20 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
21 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
22 #include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
23 #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
24 #include "llvm/Support/Error.h"
25 #include "llvm/Support/Regex.h"
26 #include "llvm/Support/raw_ostream.h"
28 #include <vector>
30 namespace llvm {
32 struct Session;
34 struct Session {
36 orc::ExecutionSession ES;
37 orc::JITDylib *MainJD = nullptr;
38 orc::ObjectLinkingLayer ObjLayer;
39 orc::JITDylibSearchOrder JDSearchOrder;
41 ~Session();
43 static Expected<std::unique_ptr<Session>> Create(Triple TT);
44 void dumpSessionInfo(raw_ostream &OS);
45 void modifyPassConfig(const Triple &FTT,
46 jitlink::PassConfiguration &PassConfig);
48 using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
50 struct FileInfo {
51 StringMap<MemoryRegionInfo> SectionInfos;
52 StringMap<MemoryRegionInfo> StubInfos;
53 StringMap<MemoryRegionInfo> GOTEntryInfos;
56 using SymbolInfoMap = StringMap<MemoryRegionInfo>;
57 using FileInfoMap = StringMap<FileInfo>;
59 Expected<FileInfo &> findFileInfo(StringRef FileName);
60 Expected<MemoryRegionInfo &> findSectionInfo(StringRef FileName,
61 StringRef SectionName);
62 Expected<MemoryRegionInfo &> findStubInfo(StringRef FileName,
63 StringRef TargetName);
64 Expected<MemoryRegionInfo &> findGOTEntryInfo(StringRef FileName,
65 StringRef TargetName);
67 bool isSymbolRegistered(StringRef Name);
68 Expected<MemoryRegionInfo &> findSymbolInfo(StringRef SymbolName,
69 Twine ErrorMsgStem);
71 SymbolInfoMap SymbolInfos;
72 FileInfoMap FileInfos;
73 uint64_t SizeBeforePruning = 0;
74 uint64_t SizeAfterFixups = 0;
76 StringSet<> HarnessFiles;
77 StringSet<> HarnessExternals;
78 StringSet<> HarnessDefinitions;
79 DenseMap<StringRef, StringRef> CanonicalWeakDefs;
81 private:
82 Session(std::unique_ptr<orc::ExecutorProcessControl> EPC, Error &Err);
85 /// Record symbols, GOT entries, stubs, and sections for ELF file.
86 Error registerELFGraphInfo(Session &S, jitlink::LinkGraph &G);
88 /// Record symbols, GOT entries, stubs, and sections for MachO file.
89 Error registerMachOGraphInfo(Session &S, jitlink::LinkGraph &G);
91 } // end namespace llvm
93 #endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H