[LLVMdev] Using llvm command line functions from within a plugin?

Duncan Sands baldrick at free.fr
Tue Jan 3 00:42:34 PST 2012


Hi Talin,

> After a several-month hiatus, I've returned to working on my main LLVM project.
> However, after checking out the latest LLVM head I'm encountering a new problem.
> When I attempt to load my custom plugin pass into opt, I'm getting this error
> message:
>
> dyld: lazy symbol binding failed: Symbol not found:
> __ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv
>    Referenced from: /Users/talin/Projects/tart/build-eclipse/linker/libgc.dylib
>    Expected in: flat namespace

are you sure you built opt and your plugin using the same LLVM build?  You can
get this kind of thing if (eg) opt is from a Release build, but your plugin was
built against a Debug build.

Ciao, Duncan.

> It appears to be due to the fact that I'm using LLVM's command-line functions
> from within my plugin:
>
>     cl::opt<bool> optShowGC("show-gc", cl::desc("Print debugging output from GC
>     strategy"));
>
> (when I remove the option from the source, everything works fine.)
>
> Now, I recognize the 'flat namespace' phrase from my build file, which passes
> "-Wl -flat_namespace -Wl -undefined -Wl suppress" to the linker when building
> the plugin. I remember that someone gave me this magic formula (or perhaps I got
> it off a search result) - I certainly don't understand what it means. I remember
> it had to do with creating the plugin in such a way as to resolve undefined
> symbols against the main program when loaded, instead of giving an error for
> each undefined symbol. (This appears to be specific to OS X, the linker on Linux
> doesn't require these flags.)
>
> A more general question is this - I've never really found a good reference or
> tutorial for building plugin libraries, in particular the kinds used with LLVM.
> I don't expect LLVM's docs to teach me how to compile and link a shared library,
> but it seems like there's a fair amount of non-obvious esoterica involved here,
> and it would be nice to have a pointer to some doc that would make it all less
> mysterious :)
>
> --
> -- Talin
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list