From b0d5b8df1dd45bb7c1c22d097501b0f2daa89354 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 4 Dec 2023 16:40:54 +0800 Subject: [PATCH] Fix issues of build/run with llvm-17 (#2853) - Fix compilation error of using PGOOptions - Fix LLVM JIT run error due to `llvm_orc_registerEHFrameSectionWrapper` symbol not found --- build-scripts/config_common.cmake | 5 +++++ core/iwasm/compilation/aot_llvm_extra.cpp | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 210f2d788..e73ebc85f 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -122,6 +122,11 @@ if (WAMR_BUILD_JIT EQUAL 1) if (CXX_SUPPORTS_REDUNDANT_MOVE_FLAG) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move") endif () + # Enable exporting symbols after llvm-17, or LLVM JIT may run failed + # with `llvm_orc_registerEHFrameSectionWrapper` symbol not found error + if (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "17.0.0") + set (CMAKE_ENABLE_EXPORTS 1) + endif () endif () else () unset (LLVM_AVAILABLE_LIBS) diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index 72e163fa2..ed0205c3c 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -36,6 +36,7 @@ #include #if LLVM_VERSION_MAJOR >= 17 #include +#include #endif #include #include @@ -203,19 +204,27 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) Optional PGO = llvm::None; #endif -// TODO -#if LLVM_VERSION_MAJOR < 17 if (comp_ctx->enable_llvm_pgo) { /* Disable static counter allocation for value profiler, it will be allocated by runtime */ const char *argv[] = { "", "-vp-static-alloc=false" }; cl::ParseCommandLineOptions(2, argv); +#if LLVM_VERSION_MAJOR < 17 PGO = PGOOptions("", "", "", PGOOptions::IRInstr); +#else + auto FS = vfs::getRealFileSystem(); + PGO = PGOOptions("", "", "", "", FS, PGOOptions::IRInstr); +#endif } else if (comp_ctx->use_prof_file) { +#if LLVM_VERSION_MAJOR < 17 PGO = PGOOptions(comp_ctx->use_prof_file, "", "", PGOOptions::IRUse); - } +#else + auto FS = vfs::getRealFileSystem(); + PGO = PGOOptions(comp_ctx->use_prof_file, "", "", "", FS, + PGOOptions::IRUse); #endif + } #ifdef DEBUG_PASS PassInstrumentationCallbacks PIC; @@ -343,7 +352,13 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes)); } - if (OptimizationLevel::O0 == OL) { + if ( +#if LLVM_VERSION_MAJOR <= 13 + PassBuilder::OptimizationLevel::O0 == OL +#else + OptimizationLevel::O0 == OL +#endif + ) { MPM.addPass(PB.buildO0DefaultPipeline(OL)); } else {