From dd95d8eb038dd01bb84dde68ad3668b4c2c319ef Mon Sep 17 00:00:00 2001 From: Officeyutong Date: Sat, 10 Aug 2024 17:32:33 +0800 Subject: [PATCH] llvm-jit: patch lddw helpers at compile time (#323) * update * update * update * update --- vm/llvm-jit/src/compat/compat_llvm.cpp | 2 + vm/llvm-jit/src/llvm/compiler.cpp | 236 ++++++++++++---------- vm/llvm-jit/src/llvm/llvm_jit_context.cpp | 204 ++++++++++--------- vm/llvm-jit/src/llvm/llvm_jit_context.hpp | 5 +- 4 files changed, 238 insertions(+), 209 deletions(-) diff --git a/vm/llvm-jit/src/compat/compat_llvm.cpp b/vm/llvm-jit/src/compat/compat_llvm.cpp index bbb7108e..6ca96d19 100644 --- a/vm/llvm-jit/src/compat/compat_llvm.cpp +++ b/vm/llvm-jit/src/compat/compat_llvm.cpp @@ -1,10 +1,12 @@ #include "spdlog/spdlog.h" #include #include +#include #include #include #include "compat_llvm.hpp" #include "../llvm/llvm_jit_context.hpp" + namespace bpftime::vm::compat { diff --git a/vm/llvm-jit/src/llvm/compiler.cpp b/vm/llvm-jit/src/llvm/compiler.cpp index 138caeff..0cc910cd 100644 --- a/vm/llvm-jit/src/llvm/compiler.cpp +++ b/vm/llvm-jit/src/llvm/compiler.cpp @@ -86,8 +86,11 @@ const size_t MAX_LOCAL_FUNC_DEPTH = 32; */ Expected llvm_bpf_jit_context::generateModule( const std::vector &extFuncNames, - const std::vector &lddwHelpers) + const std::vector &lddwHelpers, + bool patch_map_val_at_compile_time) { + SPDLOG_DEBUG("Generating module: patch_map_val_at_compile_time={}", + patch_map_val_at_compile_time); auto context = std::make_unique(); auto jitModule = std::make_unique("bpf-jit", *context); const auto &insts = vm->instructions; @@ -155,17 +158,15 @@ Expected llvm_bpf_jit_context::generateModule( // The main function Function *bpf_func = Function::Create( FunctionType::get(Type::getInt64Ty(*context), - { llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(*context)), + { llvm::PointerType::getUnqual( + llvm::Type::getInt8Ty(*context)), Type::getInt64Ty(*context) }, false), Function::ExternalLinkage, "bpf_main", jitModule.get()); - - // Get args of uint64_t bpf_main(uint64_t, uint64_t) - llvm::Argument* mem = bpf_func->getArg(0); - llvm::Argument* mem_len = bpf_func->getArg(1); - - + // Get args of uint64_t bpf_main(uint64_t, uint64_t) + llvm::Argument *mem = bpf_func->getArg(0); + llvm::Argument *mem_len = bpf_func->getArg(1); std::vector regs; std::vector allBlocks; @@ -631,7 +632,7 @@ Expected llvm_bpf_jit_context::generateModule( (((uint64_t)((uint32_t)nextInst.imm)) << 32); pc++; - SPDLOG_TRACE("Load LDDW val= {} part1={:x} part2={:x}", + SPDLOG_DEBUG("Load LDDW val= {} part1={:x} part2={:x}", val, (uint64_t)inst.imm, (uint64_t)nextInst.imm); if (inst.src_reg == 0) { @@ -639,43 +640,63 @@ Expected llvm_bpf_jit_context::generateModule( builder.CreateStore(builder.getInt64(val), regs[inst.dst_reg]); } else if (inst.src_reg == 1) { - if (auto itr = lddwHelper.find( - LDDW_HELPER_MAP_BY_FD); - itr != lddwHelper.end()) - - { - SPDLOG_DEBUG( - "Emit lddw helper 1 (map_by_fd) at pc {}, imm={}", - pc, inst.imm); + SPDLOG_DEBUG( + "Emit lddw helper 1 (map_by_fd) at pc {}, imm={}, patched at compile time", + pc, inst.imm); + if (vm->map_by_fd) { builder.CreateStore( - builder.CreateCall( - lddwHelperWithUint32, - itr->second, - { builder.getInt32( - inst.imm) }), + builder.getInt64(vm->map_by_fd( + inst.imm)), regs[inst.dst_reg]); } else { - return llvm::make_error< - llvm::StringError>( - "Using lddw helper 1, which requires map_by_fd", - llvm::inconvertibleErrorCode()); + SPDLOG_INFO( + "map_by_fd is called in eBPF code, but is not provided, will use the default behavior"); + // Default: input value + builder.CreateStore( + builder.getInt64( + (int64_t)inst.imm), + regs[inst.dst_reg]); } + } else if (inst.src_reg == 2) { - if (auto itrMapByFd = lddwHelper.find( - LDDW_HELPER_MAP_BY_FD); - itrMapByFd != lddwHelper.end()) { + SPDLOG_DEBUG( + "Emit lddw helper 2 (map_by_fd + map_val) at pc {}, imm1={}, imm2={}", + pc, inst.imm, nextInst.imm); + uint64_t mapPtr; + if (vm->map_by_fd) { + mapPtr = vm->map_by_fd(inst.imm); + } else { + SPDLOG_INFO( + "map_by_fd is called in eBPF code, but is not provided, will use the default behavior"); + // Default: returns the input value + mapPtr = (uint64_t)inst.imm; + } + if (patch_map_val_at_compile_time) { + SPDLOG_DEBUG( + "map_val is required to be evaluated at compile time"); + if (!vm->map_val) { + return llvm::make_error< + llvm::StringError>( + "map_val is not provided, unable to compile", + llvm::inconvertibleErrorCode()); + } + builder.CreateStore( + builder.getInt64( + vm->map_val(mapPtr) + + nextInst.imm), + regs[inst.dst_reg]); + } else { + SPDLOG_DEBUG( + "map_val is required to be evaluated at runtime, emitting calling instructions"); + if (auto itrMapVal = lddwHelper.find( LDDW_HELPER_MAP_VAL); itrMapVal != lddwHelper.end()) { - auto retMapByFd = builder.CreateCall( - lddwHelperWithUint32, - itrMapByFd->second, - { builder.getInt32( - inst.imm) }); auto retMapVal = builder.CreateCall( lddwHelperWithUint64, itrMapVal->second, - { retMapByFd }); + { builder.getInt64( + mapPtr) }); auto finalRet = builder.CreateAdd( retMapVal, builder.getInt64( @@ -683,99 +704,104 @@ Expected llvm_bpf_jit_context::generateModule( builder.CreateStore( finalRet, regs[inst.dst_reg]); - SPDLOG_DEBUG( - "Emit lddw helper 2 (map_by_fd + map_val) at pc {}, imm1={}, imm2={}", - pc, inst.imm, - nextInst.imm); + } else { return llvm::make_error< llvm::StringError>( - "Using lddw helper 2, which requires map_val", + "Using lddw helper 2, which requires map_val to be defined.", llvm::inconvertibleErrorCode()); } - - } else { - return llvm::make_error< - llvm::StringError>( - "Using lddw helper 2, which requires map_by_fd", - llvm::inconvertibleErrorCode()); } + } else if (inst.src_reg == 3) { - if (auto itr = lddwHelper.find( - LDDW_HELPER_VAR_ADDR); - itr != lddwHelper.end()) { - builder.CreateStore( - builder.CreateCall( - lddwHelperWithUint32, - itr->second, - { builder.getInt32( - inst.imm) }), - regs[inst.dst_reg]); - SPDLOG_DEBUG( - "Emit lddw helper 3 (var_addr) at pc {}, imm1={}", - pc, inst.imm); - } else { + SPDLOG_DEBUG( + "Emit lddw helper 3 (var_addr) at pc {}, imm1={}", + pc, inst.imm); + if (!vm->var_addr) { return llvm::make_error< llvm::StringError>( - "Using lddw helper 3, which requires var_addr", + "var_addr is not provided, unable to compile", llvm::inconvertibleErrorCode()); } + builder.CreateStore( + builder.getInt64( + vm->var_addr(inst.imm)), + regs[inst.dst_reg]); } else if (inst.src_reg == 4) { - if (auto itr = lddwHelper.find( - LDDW_HELPER_CODE_ADDR); - itr != lddwHelper.end()) { - builder.CreateStore( - builder.CreateCall( - lddwHelperWithUint32, - itr->second, - { builder.getInt32( - inst.imm) }), - regs[inst.dst_reg]); - SPDLOG_DEBUG( - "Emit lddw helper 4 (code_addr) at pc {}, imm1={}", - pc, inst.imm); - } else { + SPDLOG_DEBUG( + "Emit lddw helper 4 (code_addr) at pc {}, imm1={}", + pc, inst.imm); + if (!vm->code_addr) { return llvm::make_error< llvm::StringError>( - "Using lddw helper 4, which requires code_addr", + "code_addr is not provided, unable to compile", llvm::inconvertibleErrorCode()); } + builder.CreateStore( + builder.getInt64( + vm->code_addr(inst.imm)), + regs[inst.dst_reg]); } else if (inst.src_reg == 5) { - if (auto itr = lddwHelper.find( - LDDW_HELPER_MAP_BY_IDX); - itr != lddwHelper.end()) { + SPDLOG_DEBUG( + "Emit lddw helper 4 (map_by_idx) at pc {}, imm1={}", + pc, inst.imm); + if (vm->map_by_idx) { builder.CreateStore( - builder.CreateCall( - lddwHelperWithUint32, - itr->second, - { builder.getInt32( - inst.imm) }), + builder.getInt64(vm->map_by_idx( + inst.imm)), regs[inst.dst_reg]); - SPDLOG_DEBUG( - "Emit lddw helper 4 (map_by_idx) at pc {}, imm1={}", - pc, inst.imm); } else { - return llvm::make_error< - llvm::StringError>( - "Using lddw helper 5, which requires map_by_idx", - llvm::inconvertibleErrorCode()); + SPDLOG_INFO( + "map_by_idx is called in eBPF code, but it's not provided, will use the default behavior"); + // Default: returns the input value + builder.CreateStore( + builder.getInt64( + (int64_t)inst.imm), + regs[inst.dst_reg]); } + } else if (inst.src_reg == 6) { - if (auto itrMapByIdx = lddwHelper.find( - LDDW_HELPER_MAP_BY_IDX); - itrMapByIdx != lddwHelper.end()) { + SPDLOG_DEBUG( + "Emit lddw helper 6 (map_by_idx + map_val) at pc {}, imm1={}, imm2={}", + pc, inst.imm, nextInst.imm); + + uint64_t mapPtr; + if (vm->map_by_idx) { + mapPtr = vm->map_by_idx(inst.imm); + } else { + SPDLOG_DEBUG( + "map_by_idx is called in eBPF code, but it's not provided, will use the default behavior"); + // Default: returns the input value + mapPtr = (int64_t)inst.imm; + } + if (patch_map_val_at_compile_time) { + SPDLOG_DEBUG( + "Required to evaluate map_val at compile time"); + if (vm->map_val) { + builder.CreateStore( + builder.getInt64( + vm->map_val( + mapPtr) + + nextInst.imm), + regs[inst.dst_reg]); + } else { + return llvm::make_error< + llvm::StringError>( + "map_val is not provided, unable to compile", + llvm::inconvertibleErrorCode()); + } + + } else { + SPDLOG_DEBUG( + "Required to evaluate map_val at runtime time"); if (auto itrMapVal = lddwHelper.find( LDDW_HELPER_MAP_VAL); itrMapVal != lddwHelper.end()) { - auto retMapByIdx = builder.CreateCall( - lddwHelperWithUint32, - itrMapByIdx->second, - { builder.getInt32( - inst.imm) }); auto retMapVal = builder.CreateCall( lddwHelperWithUint64, itrMapVal->second, - { retMapByIdx }); + { builder.getInt64( + mapPtr) }); auto finalRet = builder.CreateAdd( retMapVal, builder.getInt64( @@ -783,21 +809,13 @@ Expected llvm_bpf_jit_context::generateModule( builder.CreateStore( finalRet, regs[inst.dst_reg]); - SPDLOG_DEBUG( - "Emit lddw helper 6 (map_by_idx + map_val) at pc {}, imm1={}, imm2={}", - pc, inst.imm, - nextInst.imm); + } else { return llvm::make_error< llvm::StringError>( "Using lddw helper 6, which requires map_val", llvm::inconvertibleErrorCode()); } - } else { - return llvm::make_error< - llvm::StringError>( - "Using lddw helper 6, which requires map_by_idx", - llvm::inconvertibleErrorCode()); } } break; diff --git a/vm/llvm-jit/src/llvm/llvm_jit_context.cpp b/vm/llvm-jit/src/llvm/llvm_jit_context.cpp index 7534acd3..9d1fc75f 100644 --- a/vm/llvm-jit/src/llvm/llvm_jit_context.cpp +++ b/vm/llvm-jit/src/llvm/llvm_jit_context.cpp @@ -13,7 +13,6 @@ #include #include - #include #include #include @@ -142,9 +141,6 @@ #include "bpftime_vm_compat.hpp" #include "compiler_utils.hpp" #include "spdlog/spdlog.h" -#include -#include -#include #include #include "llvm/IR/Module.h" @@ -160,12 +156,9 @@ #include #include #include -#include #include #include -#include #include -#include #include #include #include @@ -177,10 +170,6 @@ using namespace llvm::orc; using namespace bpftime; using namespace std; - - - - struct spin_lock_guard { pthread_spinlock_t *spin; spin_lock_guard(pthread_spinlock_t *spin) : spin(spin) @@ -197,46 +186,48 @@ static ExitOnError ExitOnErr; static void optimizeModule(llvm::Module &M) { - // std::cout << "LLVM_VERSION_MAJOR: " << LLVM_VERSION_MAJOR << std::endl; - #if LLVM_VERSION_MAJOR >= 17 - // ===================== - // Create the analysis managers. - // These must be declared in this order so that they are destroyed in the - // correct order due to inter-analysis-manager references. - LoopAnalysisManager LAM; - FunctionAnalysisManager FAM; - CGSCCAnalysisManager CGAM; - ModuleAnalysisManager MAM; - - // Create the new pass manager builder. - // Take a look at the PassBuilder constructor parameters for more - // customization, e.g. specifying a TargetMachine or various debugging - // options. - PassBuilder PB; - - // Register all the basic analyses with the managers. - PB.registerModuleAnalyses(MAM); - PB.registerCGSCCAnalyses(CGAM); - PB.registerFunctionAnalyses(FAM); - PB.registerLoopAnalyses(LAM); - PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); - - // Create the pass manager. - // This one corresponds to a typical -O2 optimization pipeline. - ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OptimizationLevel::O3); - - // Optimize the IR! - MPM.run(M, MAM); - // ===================================== - #else - llvm::legacy::PassManager PM; - - llvm::PassManagerBuilder PMB; - PMB.OptLevel = 3; - PMB.populateModulePassManager(PM); - - PM.run(M); - #endif + // std::cout << "LLVM_VERSION_MAJOR: " << LLVM_VERSION_MAJOR << + // std::endl; +#if LLVM_VERSION_MAJOR >= 17 + // ===================== + // Create the analysis managers. + // These must be declared in this order so that they are destroyed in + // the correct order due to inter-analysis-manager references. + LoopAnalysisManager LAM; + FunctionAnalysisManager FAM; + CGSCCAnalysisManager CGAM; + ModuleAnalysisManager MAM; + + // Create the new pass manager builder. + // Take a look at the PassBuilder constructor parameters for more + // customization, e.g. specifying a TargetMachine or various debugging + // options. + PassBuilder PB; + + // Register all the basic analyses with the managers. + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + + // Create the pass manager. + // This one corresponds to a typical -O2 optimization pipeline. + ModulePassManager MPM = + PB.buildPerModuleDefaultPipeline(OptimizationLevel::O3); + + // Optimize the IR! + MPM.run(M, MAM); + // ===================================== +#else + llvm::legacy::PassManager PM; + + llvm::PassManagerBuilder PMB; + PMB.OptLevel = 3; + PMB.populateModulePassManager(PM); + + PM.run(M); +#endif } #if defined(__arm__) || defined(_M_ARM) @@ -264,8 +255,8 @@ void llvm_bpf_jit_context::do_jit_compile() { auto [jit, extFuncNames, definedLddwHelpers] = create_and_initialize_lljit_instance(); - auto bpfModule = - ExitOnErr(generateModule(extFuncNames, definedLddwHelpers)); + auto bpfModule = ExitOnErr( + generateModule(extFuncNames, definedLddwHelpers, true)); bpfModule.withModuleDo([](auto &M) { optimizeModule(M); }); ExitOnErr(jit->addIRModule(std::move(bpfModule))); this->jit = std::move(jit); @@ -293,7 +284,8 @@ std::vector llvm_bpf_jit_context::do_aot_compile( const std::vector &lddwHelpers, bool print_ir) { SPDLOG_DEBUG("AOT: start"); - if (auto module = generateModule(extFuncNames, lddwHelpers); module) { + if (auto module = generateModule(extFuncNames, lddwHelpers, false); + module) { auto defaultTargetTriple = llvm::sys::getDefaultTargetTriple(); SPDLOG_DEBUG("AOT: target triple: {}", defaultTargetTriple); return module->withModuleDo([&](auto &module) @@ -327,20 +319,29 @@ std::vector llvm_bpf_jit_context::do_aot_compile( std::make_unique( objStream); -legacy::PassManager pass; + legacy::PassManager pass; // auto FileType = CGFT_ObjectFile; #if LLVM_VERSION_MAJOR >= 18 -if (targetMachine->addPassesToEmitFile(pass, *BOS, nullptr, CodeGenFileType::ObjectFile)) { + if (targetMachine->addPassesToEmitFile( + pass, *BOS, nullptr, + CodeGenFileType::ObjectFile)) { #elif LLVM_VERSION_MAJOR >= 10 -if (targetMachine->addPassesToEmitFile(pass, *BOS, nullptr, CGFT_ObjectFile)) { + if (targetMachine->addPassesToEmitFile( + pass, *BOS, nullptr, CGFT_ObjectFile)) { #elif LLVM_VERSION_MAJOR >= 8 -if (targetMachine->addPassesToEmitFile(pass, *BOS, nullptr, TargetMachine::CGFT_ObjectFile)) { + if (targetMachine->addPassesToEmitFile( + pass, *BOS, nullptr, + TargetMachine::CGFT_ObjectFile)) { #else -if (targetMachine->addPassesToEmitFile(pass, *BOS, TargetMachine::CGFT_ObjectFile, true)) { + if (targetMachine->addPassesToEmitFile( + pass, *BOS, TargetMachine::CGFT_ObjectFile, + true)) { #endif - SPDLOG_ERROR("Unable to emit module for target machine"); - throw std::runtime_error("Unable to emit module for target machine"); -} + SPDLOG_ERROR( + "Unable to emit module for target machine"); + throw std::runtime_error( + "Unable to emit module for target machine"); + } pass.run(module); SPDLOG_INFO("AOT: done, received {} bytes", @@ -364,28 +365,30 @@ std::vector llvm_bpf_jit_context::do_aot_compile(bool print_ir) std::vector extNames, lddwNames; for (uint32_t i = 0; i < std::size(vm->ext_funcs); i++) { if (vm->ext_funcs[i].has_value()) { - #if LLVM_VERSION_MAJOR >= 16 - extNames.emplace_back(ext_func_sym(i)); - #else - extNames.push_back(ext_func_sym(i)); - #endif +#if LLVM_VERSION_MAJOR >= 16 + extNames.emplace_back(ext_func_sym(i)); +#else + extNames.push_back(ext_func_sym(i)); +#endif } } const auto tryDefineLddwHelper = [&](const char *name, void *func) { if (func) { - #if LLVM_VERSION_MAJOR >= 16 - lddwNames.emplace_back(name); - #else - lddwNames.push_back(name); - #endif +#if LLVM_VERSION_MAJOR >= 16 + lddwNames.emplace_back(name); +#else + lddwNames.push_back(name); +#endif } }; - tryDefineLddwHelper(LDDW_HELPER_MAP_BY_FD, (void *)vm->map_by_fd); - tryDefineLddwHelper(LDDW_HELPER_MAP_BY_IDX, (void *)vm->map_by_idx); + // Only map_val will have a chance to be called at runtime tryDefineLddwHelper(LDDW_HELPER_MAP_VAL, (void *)vm->map_val); - tryDefineLddwHelper(LDDW_HELPER_CODE_ADDR, (void *)vm->code_addr); - tryDefineLddwHelper(LDDW_HELPER_VAR_ADDR, (void *)vm->var_addr); + // These symbols won't be used at runtime + // tryDefineLddwHelper(LDDW_HELPER_MAP_BY_FD, (void *)vm->map_by_fd); + // tryDefineLddwHelper(LDDW_HELPER_MAP_BY_IDX, (void *)vm->map_by_idx); + // tryDefineLddwHelper(LDDW_HELPER_CODE_ADDR, (void *)vm->code_addr); + // tryDefineLddwHelper(LDDW_HELPER_VAR_ADDR, (void *)vm->var_addr); return this->do_aot_compile(extNames, lddwNames, print_ir); } @@ -433,17 +436,17 @@ llvm_bpf_jit_context::create_and_initialize_lljit_instance() ext_func_sym(i)); sym.setFlags(JITSymbolFlags::Callable | JITSymbolFlags::Exported); - - #if LLVM_VERSION_MAJOR < 17 +#if LLVM_VERSION_MAJOR < 17 extSymbols.try_emplace(symName, sym); extFuncNames.push_back(ext_func_sym(i)); - #else - auto symbol = ::llvm::orc::ExecutorSymbolDef (::llvm::orc::ExecutorAddr (sym.getAddress()), sym.getFlags()); +#else + auto symbol = ::llvm::orc::ExecutorSymbolDef( + ::llvm::orc::ExecutorAddr(sym.getAddress()), + sym.getFlags()); extSymbols.try_emplace(symName, symbol); extFuncNames.emplace_back(ext_func_sym(i)); - #endif - +#endif } } #if defined(__arm__) || defined(_M_ARM) @@ -464,31 +467,36 @@ llvm_bpf_jit_context::create_and_initialize_lljit_instance() // printf("The type of sym %s\n", typeid(sym).name()); sym.setFlags(JITSymbolFlags::Callable | JITSymbolFlags::Exported); - - - #if LLVM_VERSION_MAJOR < 17 - lddwSyms.try_emplace(jit->getExecutionSession().intern(name), sym); +#if LLVM_VERSION_MAJOR < 17 + lddwSyms.try_emplace( + jit->getExecutionSession().intern(name), sym); definedLddwHelpers.push_back(name); - #else - auto symbol = ::llvm::orc::ExecutorSymbolDef (::llvm::orc::ExecutorAddr (sym.getAddress()), sym.getFlags()); - lddwSyms.try_emplace(jit->getExecutionSession().intern(name), symbol); +#else + auto symbol = ::llvm::orc::ExecutorSymbolDef( + ::llvm::orc::ExecutorAddr(sym.getAddress()), + sym.getFlags()); + lddwSyms.try_emplace( + jit->getExecutionSession().intern(name), + symbol); definedLddwHelpers.emplace_back(name); - #endif - - +#endif } }; - tryDefineLddwHelper(LDDW_HELPER_MAP_BY_FD, (void *)vm->map_by_fd); - tryDefineLddwHelper(LDDW_HELPER_MAP_BY_IDX, (void *)vm->map_by_idx); + // Only map_val will have a chance to be called at runtime, so it's the + // only symbol to be defined tryDefineLddwHelper(LDDW_HELPER_MAP_VAL, (void *)vm->map_val); - tryDefineLddwHelper(LDDW_HELPER_CODE_ADDR, (void *)vm->code_addr); - tryDefineLddwHelper(LDDW_HELPER_VAR_ADDR, (void *)vm->var_addr); + // These symbols won't be used at runtime + // tryDefineLddwHelper(LDDW_HELPER_MAP_BY_FD, (void *)vm->map_by_fd); + // tryDefineLddwHelper(LDDW_HELPER_MAP_BY_IDX, (void *)vm->map_by_idx); + // tryDefineLddwHelper(LDDW_HELPER_CODE_ADDR, (void *)vm->code_addr); + // tryDefineLddwHelper(LDDW_HELPER_VAR_ADDR, (void *)vm->var_addr); ExitOnErr(mainDylib.define(absoluteSymbols(lddwSyms))); return { std::move(jit), extFuncNames, definedLddwHelpers }; } -bpftime::vm::compat::precompiled_ebpf_function llvm_bpf_jit_context::get_entry_address() +bpftime::vm::compat::precompiled_ebpf_function +llvm_bpf_jit_context::get_entry_address() { if (!this->jit.has_value()) { SPDLOG_CRITICAL( @@ -506,4 +514,4 @@ bpftime::vm::compat::precompiled_ebpf_function llvm_bpf_jit_context::get_entry_a SPDLOG_DEBUG("LLVM-JIT: Entry func is {:x}", (uintptr_t)addr); return addr; } -} \ No newline at end of file +} diff --git a/vm/llvm-jit/src/llvm/llvm_jit_context.hpp b/vm/llvm-jit/src/llvm/llvm_jit_context.hpp index fc188738..61452fa8 100644 --- a/vm/llvm-jit/src/llvm/llvm_jit_context.hpp +++ b/vm/llvm-jit/src/llvm/llvm_jit_context.hpp @@ -33,12 +33,13 @@ class llvm_bpf_jit_context { std::unique_ptr compiling; llvm::Expected generateModule(const std::vector &extFuncNames, - const std::vector &lddwHelpers); + const std::vector &lddwHelpers, + bool patch_map_val_at_compile_time); std::vector do_aot_compile(const std::vector &extFuncNames, const std::vector &lddwHelpers, bool print_ir); - // (JIT, extFuncs, lddwHelpers) + // (JIT, extFuncs, definedLddwSymbols) std::tuple, std::vector, std::vector > create_and_initialize_lljit_instance();