Hi everyone,
I am building a binary translator, and try to do block chaining.
LLVM version : 3.1
my machine : x86-32 bit, Linux
Before each *LLVM IR returnInst constantValue*, I insert a call instruction
& a returnInst which looks like
%x = call @G ;
ret %x;
then remove the *LLVM IR returnInst constantValue*
The initializer of @G is a function which has prototype int f(struct MyType*
);
and the content in terms of LLVM IR is
define internal i32 @chaining1057({ i32, [32 x i32] }* %ThreadCtx1) {
"block":
%0 = getelementptr inbounds { i32, [32 x i32] }* %ThreadCtx1, i32 0, i32 1
%1 = getelementptr inbounds [32 x i32]* %0, i32 0, i32 23
store i32 0, i32* %1 ; // the first three instruction just stores
information
ret i32 296696 ; // return the same constantValue of the above said
returnInst
}
I use JIT to compile the above function and also use
JIT->getOrEmitGlobalVariable to get
the address of @G , and store the address in a pointer variable. So later,
I can modify the content
pointed by the pointer then
%x = call @G
the above instruction would call another function.
My environment has multi-thread, which means maybe some threads would try to
modify the address of @G
at the same time, but I think there is no big deal because what all threads
are trying to do is just
modify the address from A to B ( A , B is fixed ).
I modify the address of the globalvariable by
long* addr = (long*)(cur->getGVAddressPtrVector()[ix]); // no vector
insertion or deletion when this is called.
*addr = (long)next->getMachBlock();
% ix is just a vector index