Dong Chen
2012-Dec-05 13:49 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Duncan Sands, i have tried the functions: GlobalValue * getNamedValue (StringRef Name) const GlobalVariable * getGlobalVariable (StringRef Name, bool AllowInternal=false) const GlobalVariable * getNamedGlobal (StringRef Name) const but i think these functions just return the ID or something else (not the Global Variable's main memory address, i am not sure) here is the thing. i want to know the exact main memory address of the Global Varibale's address when ExecutionEngine execut the *.ll code. further more, i want to change the address, is it possible? do you have some good idea? thank you very much -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52295.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Clemens Hammacher
2012-Dec-05 15:40 UTC
[LLVMdev] how to get and modify a global variable inside a module
On 12/5/12 2:49 PM, Dong Chen wrote:> here is the thing. i want to know the exact main memory address of the > Global Varibale's address when ExecutionEngine execut the *.ll code. further > more, i want to change the address, is it possible?I assume you want to adjust the value at that address, right? Then you might want to check the ExecutionEngine::getPointerToGlobal method. You can just cast the void* to the appropriate pointer type, and write to it. If you really want to change the address of the GlobalValue (i.e. the mapping from GlobalValue to main memory address), you can use the addGlobalMapping or updateGlobalMapping methods, but this should only be done before JITting any function which uses the GlobalValue. Otherwise you have to call recompileAndRelinkFunction for each function that uses the GlobalValue. Cheers, Clemens
Dong Chen
2012-Dec-05 16:05 UTC
[LLVMdev] how to get and modify a global variable inside a module
haha~ you are right :) i have tried the function ExecutionEngine::getPointerToGlobal(), it is returned a address, but i am not sure the address is the pointer to the main memory. are you sure about that? the 2nd suggestion seems working, but i am not at the lab now, so please allow me to try it tomorrow. but i believe your suggestion will help me. it's really late here -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52305.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Dong Chen
2012-Dec-06 08:38 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Clemens, great news, I solved the problem using updateGlobalMapping and recompileAndRelinkFunction. that really helps. thank you very very much Dong Chen -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52349.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Apparently Analagous Threads
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] how to get and modify a local variable's value through executionEngine?
- [LLVMdev] wrong value with getPointerToGlobal
- [LLVMdev] lli crashes when running cpp programs
- [LLVMdev] Dynamic updates of current executed code