I would like to create and then write to a global value and am wondering how to achieve this. Do I need to get a pointer to it and then use the store instruction? If so, how do I get a pointer to it? Is there a different instruction that I need to use? I can create and read from the global value just fine but am totally lost on how to write to it so any help would be greatly appreciated!
If you are using cranelift-module (or one of it's implementors like cranelift-jit or cranelift-object), the global_value
instruction will return a pointer to the global variable. You can then read and write through this pointer.
When I try that and then print out the pointer it prints 0 and attempting to write to it segfaults
Are you using cranelift-jit or cranelift-object? How did you get the GlobalValue
you passed to the global_value
instruction?
I'm using cranelift object and i produced the global value using the declare data method on object module
Is the global variable something you import from another library or do you define it in the same object file?
And which Linkage
did you specify when declaring?
I am trying to define it by writing to it and I declared it as linkage::local
You need to define any global variable you aren't importing from another library using define_data.
alright thanks
ill give that a try in a moment
Last updated: Nov 22 2024 at 16:03 UTC