Linkage error in simple call graph pass?

Evening All,

So I need a call graph pass and having done several other passes, I went to work on a simple pass, inheriting from CallGraphSCCPass.

However, while I was quickly able to build the pass, when I went to run it I got the following:

opt -load ../Passes/HierchalFunctions/Hierchal/hierchal.dylib -hierchal < hello.bc > /dev/null
Error opening '../Passes/HierchalFunctions/Hierchal/hierchal.dylib': dlopen(../Passes/HierchalFunctions/Hierchal/hierchal.dylib, 9): Symbol not found: __ZTIN4llvm16CallGraphSCCPassE
  Referenced from: /Users/jcarlson/Software/LLDB/Passes/HierchalFunctions/Hierchal/hierchal.dylib
  Expected in: flat namespace
in /Users/jcarlson/Software/LLDB/Passes/HierchalFunctions/Hierchal/hierchal.dylib
  -load request ignored.
opt: Unknown command line argument '-hierchal'. Try: 'opt -help'
opt: Did you mean '-verify'?

It was suggested that I might have forgotten to link in the ipa lib so I tried to modify my cmakelists and then even ran by hand:

/usr/local/bin/clang++ -dynamiclib -Wl,-headerpad_max_install_names -Wl,-flat_namespace -Wl,-undefined -Wl,suppress -o hierchal.dylib -install_name /Users/jcarlson/Software/LLDB/Passes/HierchalFunctions/Hierchal/hierchal.dylib CMakeFiles/hierchal.dir/Hierchal.o -L/usr/local/lib -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMMC -lLLVMObject -lLLVMSupport -lpthread

When I run otool -l on the dylib I get:

otool -L hierchal.dylib
hierchal.dylib:
  /Users/jcarlson/Software/LLDB/Passes/HierchalFunctions/Hierchal/hierchal.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
  /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)

I have the feeling I'm just missing something simple but I've been banging my head on this for a bit now… Any suggestions?

Thanks,

- Jared

Jared Carlson <jared.carlson23 <at> gmail.com> writes:

opt -load ../Passes/HierchalFunctions/Hierchal/hierchal.dylib -hierchal
< hello.bc > /dev/null
Error opening '../Passes/HierchalFunctions/Hierchal/hierchal.dylib':
dlopen(../Passes/HierchalFunctions/Hierchal/hierchal.dylib, 9):
Symbol not found:

__ZTIN4llvm16CallGraphSCCPassE

  Referenced from:
  /Users/jcarlson/Software/LLDB/Passes/
         HierchalFunctions/Hierchal/hierchal.dylib
  Expected in: flat namespace
in /Users/jcarlson/Software/LLDB/Passes/
        HierchalFunctions/Hierchal/hierchal.dylib
  -load request ignored.
opt: Unknown command line argument '-hierchal'. Try: 'opt -help'
opt: Did you mean '-verify'?

Alright... so I must have built without something... the symbol isn't
there in the libs, so I'm assuming a flag of some sort wasn't set...
I did a grep in the libs for the exact and related symbols and I've
got the right libs...

$grep -l ZTIN4llvm16CallGraphSCCPassE *

... "nothing"...

$ grep -l llvm16CallGraphSCCPassE *
libLLVMipa.a
libLLVMipo.a
libLTO.dylib

Just going to close the loop here... the issue was that CMake build obscured RTTI
and exceptions being on.. Check out the CXX_FLAGS for opt in the source tree
and everything works out.