Hey all,<div><br></div><div>I need to use C bindings in a pass that I am authoring (specifically, I want to use the OCaml bindings that are tied to the C bindings to author the pass).  However, this requires that I link in LLVMCore to provide said bindings to my library.  From what I've read, there is a known issue with linking LLVMCore into a module that is fed to opt.  Namely, you get the following assertion:</div>

<div><br></div><div>[posera ~]$ opt -load "downloads/llvm2.6/Debug/lib/Sample2.so" --sample2 test.bc</div><div>opt: Pass.cpp:152: void<unnamed>::PassRegistrar::RegisterPass(const llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple times!"' failed.</div>

<div>Aborted</div><div><br></div><div>Typically people ran into this problem by following the Pass authoring tutorial which prescribed adding LLVMCore to your Makefile.  The workaround that everyone suggests is to simply remove LLVMCore from the Makefile.</div>

<div><br></div><div>However, in my case, I need to link LLVMCore to use the C bindings.  Not including LLVMCore in the Makefile gives the following error instead:</div><div><br></div><div>[posera ~]$ opt -load "downloads/llvm2.6/Debug/lib/Sample2.so" --sample2 test.bc</div>

<div>WARNING: You're attempting to print out a bitcode file.</div><div>This is inadvisable as it may cause display problems.  If</div><div>you REALLY want to taste LLVM bitcode first-hand, you</div><div>can force output with the `-f' option.</div>

<div><br></div><div>opt: symbol lookup error: downloads/llvm2-6/Debug/lib/Sample2.so: undefined symbol: LLVMDeleteBasicBlock</div><div><br></div><div>Hooking up the sample to a driver outside of opt (linking in LLVMCore) works as expected.</div>

<div><br></div><div>I was hoping if someone knew this was a known issue that would be fixed in the future or if anyone could think of a workaround/fix for the problem.  Here is my repro Makefile and cpp for reference:</div>

<div><br></div><div>Makefile</div><div>===</div><div>LEVEL = ../../..</div><div>LIBRARYNAME = Sample2</div><div>LOADABLE_MODULE = 1</div><div># Keeping this line gives you the assert; removing the line gives the symbol lookup error</div>

<div>LLVMLIBS = LLVMCore.a</div><div><br></div><div>include ${LEVEL}/Makefile.common</div><div><br></div><div>Sample2.cpp</div><div>===</div><div>#include "llvm/Pass.h"</div><div>#include "llvm/Support/Streams.h"</div>

<div>#include "llvm-c/Core.h"</div><div><br></div><div>using namespace llvm;</div><div><br></div><div>namespace {</div><div>    struct Sample2 : public BasicBlockPass {</div><div>        static char ID;</div><div>

        Sample2() : BasicBlockPass(&ID) { }</div><div>        virtual bool runOnBasicBlock(BasicBlock &BB) {</div><div>            LLVMDeleteBasicBlock(wrap(&BB));</div><div>            return false;</div><div>

        }</div><div>    }; <br>}</div><div><br></div><div>char Sample2::ID = 0;</div><div>static RegisterPass<Sample2> X("sample2", "Another sample pass");</div><div>===</div><div><br></div><div>

Thanks!<br><br></div><div>pm</div>