Runtime exception in DominatorTree.getRootNode()

Hi all,

I am trying to traverse a dominator tree and have encountered a weird runtime exception:

Here’s my simple code:

virtual bool runOnFunction(Function &F) {
DominatorTree& DT = getAnalysis();

DomTreeNode* rootNode = DT.getRootNode();
return false.
}

Here’s the documentation page:
http://llvm.org/docs/doxygen/html/classllvm_1_1DominatorTree.html

And here’s my runtime exception:

dyld: lazy symbol binding failed: Symbol not found: __ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
Referenced from: /Users/weibohe/Projects/llvm/llvm/Debug+Asserts/lib/LLVMSLVN.dylib
Expected in: flat namespace

dyld: Symbol not found: __ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
Referenced from: /Users/weibohe/Projects/llvm/llvm/Debug+Asserts/lib/LLVMSLVN.dylib
Expected in: flat namespace

0 opt 0x0000000105f528de llvm::sys::PrintStackTrace(__sFILE*) + 46
1 opt 0x0000000105f52beb _ZL28PrintStackTraceSignalHandlerPv + 27
2 opt 0x0000000105f52ef9 _ZL13SignalHandleri + 297
3 libsystem_c.dylib 0x00007fff90d32cfa _sigtramp + 26
4 libsystem_c.dylib 0xfffffffffffffff8 _sigtramp + 1865208600
5 libsystem_c.dylib 0x00007fff64a41948 sigtramp + 3553684584
6 libdyld.dylib 0x00007fff8afe2716 dyld_stub_binder
+ 13
7 LLVMSLVN.dylib 0x00000001081a8040 void std::__destroy_aux<llvm::PassInfo const**>(llvm::PassInfo const**, llvm::PassInfo const**, std::__true_type) + 19904
8 LLVMSLVN.dylib 0x00000001081998c1 (anonymous namespace)::DVN::runOnFunction(llvm::Function&) + 65
9 opt 0x0000000105eb27b2 llvm::FPPassManager::runOnFunction(llvm::Function&) + 434
10 opt 0x0000000105eb2a98 llvm::FPPassManager::runOnModule(llvm::Module&) + 104
11 opt 0x0000000105eb2e9a llvm::MPPassManager::runOnModule(llvm::Module&) + 634
12 opt 0x0000000105eb36ae llvm::PassManagerImpl::run(llvm::Module&) + 302
13 opt 0x0000000105eb3951 llvm::PassManager::run(llvm::Module&) + 33
14 opt 0x0000000104e4d335 main + 6549
15 opt 0x0000000104e3e434 start + 52
Stack dump:
0. Program arguments: opt -load …/…/…/Debug+Asserts/lib/LLVMSLVN.dylib -dvn

  1. Running pass ‘Function Pass Manager’ on module ‘’.
  2. Running pass ‘My test analysis’ on function ‘@main

Any idea on why this is happening? Any help or suggestion is appreciated! Thanks in advance.

Best,
Weibo

How are you running your pass? Based on the error, it looks like whatever tool you’re using to run your pass doesn’t have the library defining the DominatorTree code linked in. – John T.

Thanks for your reply, John.

I am using opt to run my pass. Should opt by default link in the library? Would you please give me some idea on fixing it? Thanks!

opt -load …/…/…/Debug+Asserts/lib/LLVMHello.dylib -hello < hello.bc > /dev/null

My pass is just:

#include “llvm/IR/Function.h”
#include “llvm/Pass.h”
#include “llvm/Support/raw_ostream.h”
#include “llvm/Analysis/Dominators.h”

using namespace llvm;

namespace {
struct Hello : public FunctionPass {
static char ID;
Hello() : FunctionPass(ID) { }
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired();
}
virtual bool runOnFunction(Function &F) {
DominatorTree& DT = getAnalysis();
BasicBlock* BB = DT.getRoot();
return false;
}
};
}
char Hello::ID = 0;
static RegisterPass Z(“hello”, “My test analysis”, true, true);

Odd. I would think that opt would have that pass linked in statically. I’m not sure why it’s not working. Does anyone else have an idea? – John T.

Hi Weibo,

I thought would be more efficient discussing here (I just saw that every info was replicated on both emails you were sending to me).

I just run your example here on my working machine, and I didn’t have any issues with the namespace. Just tell me one thing: which line (and flags) are you using when configuring and make your build llvm directory?

Oh, and one more thing: what is on your $PATH?

Cheers,

Hi Cristianno,

I have used default options for configure(llvm/configure && make).

Thanks for your advice. After I set the environment var DYLD_LIBRARY_PATH to /usr/local/lib/ , the exception is gone.

Somehow the library is not linked into opt for reasons I don’t know.

Thank you so much for your help!

Best,
Weibo