Просмотр исходного кода

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
Wenyong Huang 2 лет назад
Родитель
Сommit
b0d5b8df1d
2 измененных файлов с 24 добавлено и 4 удалено
  1. 5 0
      build-scripts/config_common.cmake
  2. 19 4
      core/iwasm/compilation/aot_llvm_extra.cpp

+ 5 - 0
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)

+ 19 - 4
core/iwasm/compilation/aot_llvm_extra.cpp

@@ -36,6 +36,7 @@
 #include <llvm/Support/ErrorHandling.h>
 #if LLVM_VERSION_MAJOR >= 17
 #include <llvm/Support/PGOOptions.h>
+#include <llvm/Support/VirtualFileSystem.h>
 #endif
 #include <llvm/Target/CodeGenCWrappers.h>
 #include <llvm/Target/TargetMachine.h>
@@ -203,19 +204,27 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
     Optional<PGOOptions> 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 {