DomTreeNode

Hi Guys,
I am using the Postdom pass and I would like to get the root of the tree. However,
everytime I try to get the root, I get a segfault. I don’t know why the environment can’t
find DominatorTreeBase.

Below is the code that generates the Segfault. In my .h file I include Dominators.h

PDT.getRootNode(); //PDT is a reference to a PostDominatorTree

dyld: lazy symbol binding failed: Symbol not found: __ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
Referenced from: /Users/georgebaah/Software/llvm3.1/build/Debug+Asserts/bin/…/lib/LLVMNshira.dylib
Expected in: flat namespace

dyld: Symbol not found: __ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
Referenced from: /Users/georgebaah/Software/llvm3.1/build/Debug+Asserts/bin/…/lib/LLVMNshira.dylib
Expected in: flat namespace

George

Oh, one more thing, I am running llvm in debug mode – Debug+Asserts. Thanks for your help.

Hi George,

...

dyld: lazy symbol binding failed: Symbol not found:
__ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
   Referenced from:
/Users/georgebaah/Software/llvm3.1/build/Debug+Asserts/bin/../lib/LLVMNshira.dylib
   Expected in: flat namespace

dyld: Symbol not found:
__ZN4llvm17DominatorTreeBaseINS_10BasicBlockEE11getRootNodeEv
   Referenced from:
/Users/georgebaah/Software/llvm3.1/build/Debug+Asserts/bin/../lib/LLVMNshira.dylib
   Expected in: flat namespace

looks like you forgot to link with the library defining this symbol.

Ciao, Duncan.

That is what I don’t understand. This symbol is defined in Dominators.h, which I include
in my file. I don’t understand why I am getting this error. Here is my opt command,

“opt -load LLVMMyDomPass.dylib -mdp < test.bc > test.d.bc”

George

Hi George,

That is what I don't understand. This symbol is defined in Dominators.h, which I
include
in my file. I don't understand why I am getting this error. Here is my opt command,

"opt -load LLVMMyDomPass.dylib -mdp < test.bc > test.d.bc"

did you compile your pass with the same optimization level, debug flags etc as
opt was compiled with?

Ciao, Duncan.

It may also be that the relevant code is dead code eliminated, as it is not used within LLVM. I would try to compile LLVM with --enable-shared (autoconf) or BUILD_SHARED_LIBS (cmake). If this works, the dead code elimination is probably the problem.

Tobi

When I compile llvm in release mode, the problem goes away! I don’t understand?

George

Interesting. I have no idea what is going on, but it would be interesting to investigate that.

Tobi

I think It has to do with the option --disable-optimized. Without that option
llvm builds in release mode and everything works fine.
Is there something being omitted in the makefiles when building in debug
mode? I am running on Mac OSX Lion.

George

Some flags may be different, but for details you need to check the buildfiles yourself. I would have expected it to work with debug or enable-shared, but to have the release build optimize away some uses, which would allow it to eliminate certain functions and which could cause such problems. Apparently, in this case it is the other way around. So I have no clue. Maybe someone else has some ideas.

Tobi

Hi George,

When I compile llvm in release mode, the problem goes away! I don't understand?

probably the function defined in the header is inlined into every function that
calls it when optimization is turned on, but not when optimization is turned
off.

Ciao, Duncan.

Yes, the function is an inline function in PostDominators.h. In fact almost all the functions in the header are inlined.

[00045](http://llvm.org/doxygen/structllvm_1_1PostDominatorTree.html#a94e7209d35e2a344f6b3632330fe8502)   inline [DomTreeNode](http://llvm.org/doxygen/classllvm_1_1DomTreeNodeBase.html) *[getRootNode](http://llvm.org/doxygen/structllvm_1_1PostDominatorTree.html#a94e7209d35e2a344f6b3632330fe8502)() const {
00046     return [DT](http://llvm.org/doxygen/structllvm_1_1PostDominatorTree.html#a0c34ac83dc77fc716cf0d104cb0ffe6a)->[getRootNode](http://llvm.org/doxygen/classllvm_1_1DominatorTreeBase.html#a18bbbda9c8de124d37f05034f8307aa0)();
00047   }

I wonder how to go about making sure it is visible in debug mode.

George

You can try to add it into include/llvm/LinkAllPasses.h. There are already a couple of other functions that have been put here to not be eliminated.

BTW, is there no better way to mark a function as used externally?

Tobi

All the functions in LinkAllPasses.h are passes. I am not sure whether it takes inline functions. I added createPostDomTree() to LinkAllPasses.h but I get the same error. I wonder whether it was even worth it making the functions inline for PostDominators.h.

George

Not all of them are passes. At the very end some non pass functions are added e.g. viewCFG().

Tobi