llvm-pass-skeleton icon indicating copy to clipboard operation
llvm-pass-skeleton copied to clipboard

Error while running the program

Open schwarzschild-radius opened this issue 7 years ago • 7 comments
trafficstars

I tried to run the following code

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;

namespace {
  struct SkeletonPass : public FunctionPass {
    static char ID;
    SkeletonPass() : FunctionPass(ID) {}

    virtual bool runOnFunction(Function &F) {
      errs() << "In a function called " << F.getName() << "!\n";

      errs() << "Function body:\n";
      F.dump();

      for (auto &B : F) {
        errs() << "Basic block:\n";
        B.dump();

        for (auto &I : B) {
          errs() << "Instruction: ";
          I.dump();
        }
      }

      return false;
    }
  };
}

char SkeletonPass::ID = 0;

// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
static void registerSkeletonPass(const PassManagerBuilder &,
                         legacy::PassManagerBase &PM) {
  PM.add(new SkeletonPass());
}
static RegisterStandardPasses
  RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
                 registerSkeletonPass);

and I received the following error

In a function called __cxx_global_var_init!
Function body:
~/Softwares/LLVM7/bin/clang-7.0: symbol lookup error: ./libSkeletonPass.so: undefined symbol: _ZNK4llvm5Value4dumpEv
clang-7.0: error: unable to execute command: No such file or directory
clang-7.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 7.0.0 (https://llvm.org/git/clang.git e77fed96933e0fa11bd4cd8dc8a198a34649c6ea) (https://llvm.org/git/llvm.git 96102045c0f3090e8ce16bb1fc20cc0a50c236ca)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/pradeep/Softwares/LLVM7/bin
clang-7.0: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-7.0: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-7.0: note: diagnostic msg: /tmp/test-e972d6.cpp
clang-7.0: note: diagnostic msg: /tmp/test-e972d6.sh
clang-7.0: note: diagnostic msg: 

********************

clang version 7.0 llvm version 7.0 Operating System Ubuntu 16.04.3 LTS

Should I need to install a different version of clang?

schwarzschild-radius avatar Mar 05 '18 18:03 schwarzschild-radius

Hello! As the README says, this was written for LLVM 3.8. (Any help with the port would be appreciated.)

sampsyo avatar Mar 06 '18 01:03 sampsyo

Hello, Adrian. Instead of using dump(), you can directly use the variable to print out the contents.

schwarzschild-radius avatar Mar 07 '18 13:03 schwarzschild-radius

OK! I’d accept a pull request if you can offer one. :+1:

sampsyo avatar Mar 07 '18 13:03 sampsyo

Hello, Adrian. Your code in the repository is working perfect, except your code shown in your blog. That second example that prints out the instruction inside blocks inside functions. I don't think this issue needs a pull request. You can update your blog post

schwarzschild-radius avatar Mar 09 '18 13:03 schwarzschild-radius

Aha, got it! In fact, the post is on GitHub too. :smiley: So if you have a moment, please do consider sending a PR there.

sampsyo avatar Mar 09 '18 13:03 sampsyo

Another possibility that 'dump' cannot be found is the clang you use is a 'release build', so it does not include 'dump' function. Trying to build a 'debug' mode clang may solve the problem.

lingda-li avatar Feb 28 '19 20:02 lingda-li

Rebuilt LLVM in Debug mode, compiled the skeleton pass with it and it worked!

LLVM/Clang version used 4.0.1

N.B.! Remember to cmake with paths to the built compilers and not the system ones!

gessha avatar Nov 01 '19 16:11 gessha