Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running the program #17

Open
schwarzschild-radius opened this issue Mar 5, 2018 · 7 comments
Open

Error while running the program #17

schwarzschild-radius opened this issue Mar 5, 2018 · 7 comments

Comments

@schwarzschild-radius
Copy link

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?

@sampsyo
Copy link
Owner

sampsyo commented Mar 6, 2018

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

@schwarzschild-radius
Copy link
Author

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

@sampsyo
Copy link
Owner

sampsyo commented Mar 7, 2018

OK! I’d accept a pull request if you can offer one. 👍

@schwarzschild-radius
Copy link
Author

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

@sampsyo
Copy link
Owner

sampsyo commented Mar 9, 2018

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

@lingda-li
Copy link

lingda-li commented Feb 28, 2019

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.

@gessha
Copy link

gessha commented Nov 1, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants