Blame SOURCES/bpftrace-0.13.1-orc-Fix-build-with-clang-13.patch

fe99d4
From 44fab4dd2201ee4a470248b4e3f8b2aa51c90a53 Mon Sep 17 00:00:00 2001
055636
From: Khem Raj <raj.khem@gmail.com>
055636
Date: Sat, 4 Sep 2021 17:28:17 -0700
fe99d4
Subject: [PATCH 2/6] orc: Fix build with clang >= 13
055636
055636
Fixes errors like
055636
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
055636
BpfOrc::BpfOrc(TargetMachine *TM, DataLayout DL)
055636
        ^
055636
055636
Fixes https://github.com/iovisor/bpftrace/issues/1963
055636
055636
Signed-off-by: Khem Raj <raj.khem@gmail.com>
055636
---
055636
 src/bpforc.h     | 23 ++++++++++++++++++++++-
055636
 src/bpforcv2.cpp | 23 +++++++++++++++--------
055636
 2 files changed, 37 insertions(+), 9 deletions(-)
055636
055636
diff --git a/src/bpforc.h b/src/bpforc.h
fe99d4
index c333a651..cc6a1c97 100644
055636
--- a/src/bpforc.h
055636
+++ b/src/bpforc.h
055636
@@ -20,6 +20,9 @@
055636
 #ifdef LLVM_ORC_V2
055636
 #include <llvm/ExecutionEngine/Orc/Core.h>
055636
 #include <llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h>
055636
+#if LLVM_VERSION_MAJOR >= 13
055636
+#include <llvm/ExecutionEngine/Orc/ExecutorProcessControl.h>
055636
+#endif
055636
 #endif
055636
 
055636
 #include <optional>
fe99d4
@@ -71,8 +74,12 @@ class BpfOrc
055636
   std::unique_ptr<TargetMachine> TM;
055636
   DataLayout DL;
055636
 #if LLVM_VERSION_MAJOR >= 7
055636
+#ifdef LLVM_ORC_V2
055636
+  std::unique_ptr<ExecutionSession> ES;
055636
+#else // LLVM_ORC_V1
055636
   ExecutionSession ES;
055636
 #endif
055636
+#endif
055636
 #if LLVM_VERSION_MAJOR >= 7 && LLVM_VERSION_MAJOR < 12
055636
   std::shared_ptr<SymbolResolver> Resolver;
055636
 #endif
fe99d4
@@ -97,7 +104,21 @@ class BpfOrc
055636
 #endif
055636
 
055636
 public:
055636
+#if LLVM_VERSION_MAJOR >= 13
055636
+  ~BpfOrc()
055636
+  {
055636
+    if (auto Err = ES->endSession())
055636
+      ES->reportError(std::move(Err));
055636
+  }
055636
+#endif
055636
+#ifdef LLVM_ORC_V2
055636
+  BpfOrc(TargetMachine *TM,
055636
+         DataLayout DL,
055636
+         std::unique_ptr<ExecutionSession> ES);
055636
+#else
055636
   BpfOrc(TargetMachine *TM, DataLayout DL);
055636
+#endif
055636
+
055636
   void compile(std::unique_ptr<Module> M);
055636
 
055636
   /* Helper for creating a orc object, responsible for creating internal objects
fe99d4
@@ -130,7 +151,7 @@ class BpfOrc
055636
 #ifdef LLVM_ORC_V2
055636
   Expected<JITEvaluatedSymbol> lookup(StringRef Name)
055636
   {
055636
-    return ES.lookup({ &MainJD }, Mangle(Name.str()));
055636
+    return ES->lookup({ &MainJD }, Mangle(Name.str()));
055636
   }
055636
 #endif
055636
 };
055636
diff --git a/src/bpforcv2.cpp b/src/bpforcv2.cpp
fe99d4
index 9876625b..3e6684e4 100644
055636
--- a/src/bpforcv2.cpp
055636
+++ b/src/bpforcv2.cpp
fe99d4
@@ -1,21 +1,23 @@
055636
 // Included by bpforc.cpp
055636
 
055636
-BpfOrc::BpfOrc(TargetMachine *TM, DataLayout DL)
055636
+BpfOrc::BpfOrc(TargetMachine *TM,
055636
+               DataLayout DL,
055636
+               std::unique_ptr<ExecutionSession> ES)
055636
     : TM(std::move(TM)),
055636
       DL(std::move(DL)),
055636
-      ObjectLayer(ES,
055636
+      ES(std::move(ES)),
055636
+      ObjectLayer(*(this->ES),
055636
                   [this]() {
055636
                     return std::make_unique<MemoryManager>(sections_);
055636
                   }),
055636
-      CompileLayer(ES,
055636
+      CompileLayer(*this->ES,
055636
                    ObjectLayer,
055636
                    std::make_unique<SimpleCompiler>(*this->TM)),
055636
-      Mangle(ES, this->DL),
055636
+      Mangle(*this->ES, this->DL),
055636
       CTX(std::make_unique<LLVMContext>()),
055636
-      MainJD(cantFail(ES.createJITDylib("<main>")))
055636
+      MainJD(cantFail(this->ES->createJITDylib("<main>")))
055636
 {
055636
 }
055636
-
055636
 LLVMContext &BpfOrc::getContext()
055636
 {
055636
   return *CTX.getContext();
fe99d4
@@ -34,8 +36,13 @@ std::unique_ptr<BpfOrc> BpfOrc::Create()
055636
   // return unique_ptrs
055636
   auto DL = cantFail(JTMB.getDefaultDataLayoutForTarget());
055636
   auto TM = cantFail(JTMB.createTargetMachine());
055636
-
055636
-  return std::make_unique<BpfOrc>(TM.release(), std::move(DL));
055636
+#if LLVM_VERSION_MAJOR >= 13
055636
+  auto EPC = SelfExecutorProcessControl::Create();
055636
+  auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
055636
+#else
055636
+  auto ES = std::make_unique<ExecutionSession>();
055636
+#endif
055636
+  return std::make_unique<BpfOrc>(TM.release(), std::move(DL), std::move(ES));
055636
 }
055636
 
055636
 void BpfOrc::compile(std::unique_ptr<Module> M)
055636
-- 
fe99d4
2.35.3
055636