[LLVMdev] How to define a global variable?

Renato Golin rengolin at systemcall.org
Wed Jan 12 16:33:25 PST 2011


On 12 January 2011 23:38, Rob Nikander <rob.nikander at gmail.com> wrote:
> I have to pass something from the LinkageTypes enum to the
> constructor.  I tried others, like GlobalVariable::InternalLinkage,
> which dumps as "internal global" but the error was the same.

To be honest, your IR is a bit odd. I'm not a JIT expert, but here are
a few things that will help you find your way through LLVM...

Is this the result of the compilation of a source file (by any
front-end), or is this code generated dynamically via the API?

Opaque types are not valid, you need to resolve it to a real (LLVM)
type before running/compiling. The inttoptr will not resolve it to a
pointer, so that IR is probably invalid anyway.

The internal global probably works in your case and unless you have
another extern variable, I don't know how you can get the "exact" same
error message with an internal global. (Again, I'm not a JIT expert,
that could happen somehow).

This could be perfectly legal in your case, but if I got it right,
you're setting a static address to a supposed pointer (i64
4316154480). That's generally wrong in all but the most simple cases
(deeply embedded systems with no memory management).

I don't know about the Python integration, but if your @x variable is
a Python variable, then extern global is probably what you're looking
for. However, due to the (possible) difference in memory layouts, I
don't think that's the best way to pass information up to the Python
layer. At least when using JNI to interface Java with C, that was a
clear dead end.

Maybe if you tell us a bit more about your project, expectations and
steps, we might be able to help you more than just guessing... ;)

cheers,
--renato




More information about the llvm-dev mailing list