Question

I want to run an example plugin for CLANG/LLVM. Specifically llvm\tools\clang\examples\PrintFunctionNames. I managed to build it and i see an PrintFunctionNames.exports but i dont think visual studios supports it. The file is simply _ZN4llvm8Registry*. I have no idea what that is but i suspect its namespace llvm, class Registry which is defined as

template <typename T, typename U = RegistryTraits<T> >
class Registry {

I suspect the key line is at the end of the example file

static FrontendPluginRegistry::Add<PrintFunctionNamesAction> X("print-fns", "print function names");

print-fns is the name while the 2nd param is the desc. When i try loading/running the dll via

clang -cc1 -load printFunctionNames.dll -plugin print-fns a.c

I get an error about not finding print-fns. I suspect its because the static variable is never being initialize thus it never registers the plugin. A wrong dll name would get an error loading module msg.

I created a def file and added it to my project. It compiled but still no luck. Here is my def file

LIBRARY printFunctionNames
EXPORTS
X DATA

How do i register the plugin or get this example working?

Was it helpful?

Solution

Ok, becoming slightly more clear. To summarize: Visual Studio has nothing to do with it, really. This is a plugin for the clang executable. Therefore, there must be a method to communicate between them (the plugin interface). This appears to be an undocumented interface, so it's taking a bit off guesswork.

Troubleshooting DLL issues is done with "Dependency Walker" aka "Depends". It offers a profiling mode, in which all symbol lookups can be profiled. I.e. if you profile clang -cc1 -load printFunctionNames.dll -plugin print-fns a.c, you will see what symbols clang expects from your DLL, and in what order.

OTHER TIPS

It looks like you're trying to mix C++ code built with two different, incompatible compilers. That's not supported, and the error you're seeing is a typical sign of that: C++ compilers usually use a "name mangling scheme", and if two compilers are incompatible then their name mangling schemes don't line up. One compiler may mangle llvm::Registry as _ZN4llvm8Registry* while another refers to it as llvm__Registry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top