How to link LLVMCore.a into a custom pass that is fed to opt

Hey all,

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:

[posera ~]$ opt -load “downloads/llvm2.6/Debug/lib/” --sample2 test.bc
opt: Pass.cpp:152: void::PassRegistrar::RegisterPass(const llvm::PassInfo&): Assertion `Inserted && “Pass registered multiple times!”’ failed.

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.

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:

[posera ~]$ opt -load “downloads/llvm2.6/Debug/lib/” --sample2 test.bc
WARNING: You’re attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f’ option.

opt: symbol lookup error: downloads/llvm2-6/Debug/lib/ undefined symbol: LLVMDeleteBasicBlock

Hooking up the sample to a driver outside of opt (linking in LLVMCore) works as expected.

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: