I'd like to record some dynamic behaviors into some global variables. So I wrote a pass to instrument the code and insert some instructions to update the global variable. I tried to use the GlobalVariable constructor to define a global variable, but there are two problems. First, how can I DEFINE the global variables in the module containing main function? Second, how can I DECLARE those global variables in other modules? It's like "extern double someThing;".
The target programs are written in C.
There is a tool which can answer this and many other questions about LLVM API:
llc -march=cpp
. You can generate a bitcode file using Clang or llvm-gcc, and then build a C++ code which should reconstruct the same module using thecpp
backend.A sample output, showing how to define a global
int *
variable: