JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
826 stars 141 forks source link

Compilation error when building llvm-cbe with LLVM-9 #119

Closed hc825b closed 3 years ago

hc825b commented 3 years ago

Hi llvm-cbe-dev,

I encountered the following error message when running make to build llvm-cbe with LLVM-9

$HOME/comp_ws/llvm-cbe/tools/llvm-cbe/llvm-cbe.cpp:408:3: error: expected unqualified-id before ‘if’
  408 |   if (Target.addPassesToEmitFile(PM, Out->os(),
...

After a quick look, I think the preprocessor macros from line 394-405 linked below is convoluted and causes a missing if condition or an extra right brace } when compiling with LLVM-9 or below.

https://github.com/JuliaComputingOSS/llvm-cbe/blob/caaf6123192e3a5a35e5a4d761f1dc9afe545454/tools/llvm-cbe/llvm-cbe.cpp#L394-L405

I expand and rewrite the macros manually and this fix worked for my setup. I did not test this against LLVM-10 or LLVM-11.

#if LLVM_VERSION_MAJOR > 10
  if (mc::getExplicitRelaxAll()) {
    if (codegen::getFileType() != CodeGenFileType::CGFT_ObjectFile)
      errs() << argv[0]
             << ": warning: ignoring -mc-relax-all because filetype != obj\n";
  }
#elif LLVM_VERSION_MAJOR == 10
  if (RelaxAll) {
    if (FileType != CodeGenFileType::CGFT_ObjectFile)
      errs() << argv[0]
             << ": warning: ignoring -mc-relax-all because filetype != obj\n";
  }
#else
  if (RelaxAll) {
    if (FileType != TargetMachine::CGFT_ObjectFile)
      errs() << argv[0]
             << ": warning: ignoring -mc-relax-all because filetype != obj\n";
  }
#endif
vtjnash commented 3 years ago

LLVM 9 is old, and therefore unsupported here (https://github.com/JuliaComputingOSS/llvm-cbe/issues/60)

hc825b commented 3 years ago

I see. That is unfortunate. Thanks for the quick response!

hikari-no-yume commented 3 years ago

By the way, LLVM supports importing bitcode from previous LLVM versions, so if another tool you are using produces LLVM 9 output, it should be no problem to use it with an llvm-cbe built with LLVM 10.