hc
2023-12-02 57e32c52610e6a560beda60bf33c48f9f42306d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
From 3bb232ef9eeea769985d550799f6a9d2accaf32a Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 4 Sep 2021 17:28:17 -0700
Subject: [PATCH 2/2] orc: Fix build with clang >= 13
 
Fixes errors like
src/ast/bpforc/bpforcv2.cpp:3:9: error: constructor for 'bpftrace::BpfOrc' must explicitly initialize the member 'ES' which does not have a default constructor
BpfOrc::BpfOrc(TargetMachine *TM, DataLayout DL)
        ^
 
Fixes https://github.com/iovisor/bpftrace/issues/1963
 
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/ast/bpforc/bpforc.h     | 18 ++++++++++++++++--
 src/ast/bpforc/bpforcv2.cpp | 23 ++++++++++++-----------
 2 files changed, 28 insertions(+), 13 deletions(-)
 
diff --git a/src/ast/bpforc/bpforc.h b/src/ast/bpforc/bpforc.h
index 1b929dfd..76913279 100644
--- a/src/ast/bpforc/bpforc.h
+++ b/src/ast/bpforc/bpforc.h
@@ -72,8 +72,12 @@ private:
   std::unique_ptr<TargetMachine> TM;
   DataLayout DL;
 #if LLVM_VERSION_MAJOR >= 7
+#ifdef LLVM_ORC_V2
+  std::unique_ptr<ExecutionSession> ES;
+#else // LLVM_ORC_V1
   ExecutionSession ES;
 #endif
+#endif
 #if LLVM_VERSION_MAJOR >= 7 && LLVM_VERSION_MAJOR < 12
   std::shared_ptr<SymbolResolver> Resolver;
 #endif
@@ -98,7 +102,17 @@ private:
 #endif
 
 public:
-  BpfOrc(TargetMachine *TM, DataLayout DL);
+#if LLVM_VERSION_MAJOR >= 13
+  ~BpfOrc()
+  {
+    if (auto Err = ES->endSession())
+      ES->reportError(std::move(Err));
+  }
+#endif
+  BpfOrc(TargetMachine *TM,
+         DataLayout DL,
+         std::unique_ptr<ExecutionSession> ES);
+
   void compile(std::unique_ptr<Module> M);
 
   /* Helper for creating a orc object, responsible for creating internal objects
@@ -134,7 +148,7 @@ public:
 #ifdef LLVM_ORC_V2
   Expected<JITEvaluatedSymbol> lookup(StringRef Name)
   {
-    return ES.lookup({ &MainJD }, Mangle(Name.str()));
+    return ES->lookup({ &MainJD }, Mangle(Name.str()));
   }
 #endif
 };
diff --git a/src/ast/bpforc/bpforcv2.cpp b/src/ast/bpforc/bpforcv2.cpp
index 9876625b..ca8d214e 100644
--- a/src/ast/bpforc/bpforcv2.cpp
+++ b/src/ast/bpforc/bpforcv2.cpp
@@ -1,21 +1,21 @@
 // Included by bpforc.cpp
 
-BpfOrc::BpfOrc(TargetMachine *TM, DataLayout DL)
+BpfOrc::BpfOrc(TargetMachine *TM,
+               DataLayout DL,
+               std::unique_ptr<ExecutionSession> ES)
     : TM(std::move(TM)),
       DL(std::move(DL)),
-      ObjectLayer(ES,
-                  [this]() {
-                    return std::make_unique<MemoryManager>(sections_);
-                  }),
-      CompileLayer(ES,
+      ES(std::move(ES)),
+      ObjectLayer(*this->ES,
+                  []() { return std::make_unique<SectionMemoryManager>(); }),
+      CompileLayer(*this->ES,
                    ObjectLayer,
                    std::make_unique<SimpleCompiler>(*this->TM)),
-      Mangle(ES, this->DL),
+      Mangle(*this->ES, this->DL),
       CTX(std::make_unique<LLVMContext>()),
-      MainJD(cantFail(ES.createJITDylib("<main>")))
+      MainJD(cantFail(this->ES->createJITDylib("<main>")))
 {
 }
-
 LLVMContext &BpfOrc::getContext()
 {
   return *CTX.getContext();
@@ -34,8 +34,9 @@ std::unique_ptr<BpfOrc> BpfOrc::Create()
   // return unique_ptrs
   auto DL = cantFail(JTMB.getDefaultDataLayoutForTarget());
   auto TM = cantFail(JTMB.createTargetMachine());
-
-  return std::make_unique<BpfOrc>(TM.release(), std::move(DL));
+  auto EPC = SelfExecutorProcessControl::Create();
+  auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
+  return std::make_unique<BpfOrc>(TM.release(), std::move(DL), std::move(ES));
 }
 
 void BpfOrc::compile(std::unique_ptr<Module> M)
-- 
2.33.0