From f562f8fae4bdb8ac51fc815b725bfaada2371b31 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 4 Sep 2021 17:28:17 -0700 Subject: [PATCH 3/6] 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 --- src/bpforc.h | 23 ++++++++++++++++++++++- src/bpforcv2.cpp | 23 +++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/bpforc.h b/src/bpforc.h index c333a651..cc6a1c97 100644 --- a/src/bpforc.h +++ b/src/bpforc.h @@ -20,6 +20,9 @@ #ifdef LLVM_ORC_V2 #include #include +#if LLVM_VERSION_MAJOR >= 13 +#include +#endif #endif #include @@ -71,8 +74,12 @@ class BpfOrc std::unique_ptr TM; DataLayout DL; #if LLVM_VERSION_MAJOR >= 7 +#ifdef LLVM_ORC_V2 + std::unique_ptr ES; +#else // LLVM_ORC_V1 ExecutionSession ES; #endif +#endif #if LLVM_VERSION_MAJOR >= 7 && LLVM_VERSION_MAJOR < 12 std::shared_ptr Resolver; #endif @@ -97,7 +104,21 @@ class BpfOrc #endif public: +#if LLVM_VERSION_MAJOR >= 13 + ~BpfOrc() + { + if (auto Err = ES->endSession()) + ES->reportError(std::move(Err)); + } +#endif +#ifdef LLVM_ORC_V2 + BpfOrc(TargetMachine *TM, + DataLayout DL, + std::unique_ptr ES); +#else BpfOrc(TargetMachine *TM, DataLayout DL); +#endif + void compile(std::unique_ptr M); /* Helper for creating a orc object, responsible for creating internal objects @@ -130,7 +151,7 @@ class BpfOrc #ifdef LLVM_ORC_V2 Expected lookup(StringRef Name) { - return ES.lookup({ &MainJD }, Mangle(Name.str())); + return ES->lookup({ &MainJD }, Mangle(Name.str())); } #endif }; diff --git a/src/bpforcv2.cpp b/src/bpforcv2.cpp index 9876625b..3e6684e4 100644 --- a/src/bpforcv2.cpp +++ b/src/bpforcv2.cpp @@ -1,21 +1,23 @@ // Included by bpforc.cpp -BpfOrc::BpfOrc(TargetMachine *TM, DataLayout DL) +BpfOrc::BpfOrc(TargetMachine *TM, + DataLayout DL, + std::unique_ptr ES) : TM(std::move(TM)), DL(std::move(DL)), - ObjectLayer(ES, + ES(std::move(ES)), + ObjectLayer(*(this->ES), [this]() { return std::make_unique(sections_); }), - CompileLayer(ES, + CompileLayer(*this->ES, ObjectLayer, std::make_unique(*this->TM)), - Mangle(ES, this->DL), + Mangle(*this->ES, this->DL), CTX(std::make_unique()), - MainJD(cantFail(ES.createJITDylib("
"))) + MainJD(cantFail(this->ES->createJITDylib("
"))) { } - LLVMContext &BpfOrc::getContext() { return *CTX.getContext(); @@ -34,8 +36,13 @@ std::unique_ptr BpfOrc::Create() // return unique_ptrs auto DL = cantFail(JTMB.getDefaultDataLayoutForTarget()); auto TM = cantFail(JTMB.createTargetMachine()); - - return std::make_unique(TM.release(), std::move(DL)); +#if LLVM_VERSION_MAJOR >= 13 + auto EPC = SelfExecutorProcessControl::Create(); + auto ES = std::make_unique(std::move(*EPC)); +#else + auto ES = std::make_unique(); +#endif + return std::make_unique(TM.release(), std::move(DL), std::move(ES)); } void BpfOrc::compile(std::unique_ptr M) -- 2.35.3