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

Peter-Michael Osera posera at cis.upenn.edu
Thu Mar 18 11:25:42 PDT 2010


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.so" --sample2
test.bc
opt: Pass.cpp:152: void<unnamed>::PassRegistrar::RegisterPass(const
llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple times!"'
failed.
Aborted

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.so" --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/Sample2.so: 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:

Makefile
===
LEVEL = ../../..
LIBRARYNAME = Sample2
LOADABLE_MODULE = 1
# Keeping this line gives you the assert; removing the line gives the symbol
lookup error
LLVMLIBS = LLVMCore.a

include ${LEVEL}/Makefile.common

Sample2.cpp
===
#include "llvm/Pass.h"
#include "llvm/Support/Streams.h"
#include "llvm-c/Core.h"

using namespace llvm;

namespace {
    struct Sample2 : public BasicBlockPass {
        static char ID;
        Sample2() : BasicBlockPass(&ID) { }
        virtual bool runOnBasicBlock(BasicBlock &BB) {
            LLVMDeleteBasicBlock(wrap(&BB));
            return false;
        }
    };
}

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

Thanks!

pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100318/1a54c554/attachment.html>


More information about the llvm-dev mailing list