I have a function address held in an uint64_t. I would like to cast the function address to a function prototype and create a call to the function in LLVM. How could I do this ? Thanks Xin
Using uintptr_t is the way to hold pointer values. However, I seem to recall there being an exception for function addresses. -bw On Jun 18, 2012, at 1:09 PM, Xin Tong wrote:> I have a function address held in an uint64_t. I would like to cast > the function address to a function prototype and create a call to the > function in LLVM. How could I do this ? > > Thanks > > Xin > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
In fact i want to cast a uint64_t to a function address and make LLVM generate IR to call it. i.e. in LLVM IR, i want to generate something like this. the uint64_t function prototype function args call 0xAABBCC (void () (int int)) (1 , 2) Thanks Xin On Mon, Jun 18, 2012 at 10:21 PM, Bill Wendling <wendling at apple.com> wrote:> Using uintptr_t is the way to hold pointer values. However, I seem to recall there being an exception for function addresses. > > -bw > > On Jun 18, 2012, at 1:09 PM, Xin Tong wrote: > >> I have a function address held in an uint64_t. I would like to cast >> the function address to a function prototype and create a call to the >> function in LLVM. How could I do this ? >> >> Thanks >> >> Xin >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Xin Tong > Subject: [LLVMdev] Cast Pointer Address to Functions> I have a function address held in an uint64_t. I would like to cast > the function address to a function prototype and create a call to the > function in LLVM. How could I do this ?This is what works for us: std::vector<Type*> margs; FunctionType* fType; PointerType* pm3_routine; Value* m3func; Value* result; margs.resize(1); margs[0] = I64; fType = FunctionType::get(I32, margs, false); pm3_routine = PointerType::get(fType, 0); m3func = Builder.CreateIntToPtr(I64_Const((uint64_t)pFunc), pm3_routine, "pm3func"); result = Builder.CreateCall(m3func, parameter, "m3func"); - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Interestingly I have something similar. but does not seem to work. This one works. Value *FuncCast = EIR->CreateIntToPtr(FuncAddr, FuncTyPntr, "FuncName"); This one does not work. it gives me an instruction with badref. CastInst *FuncCast = CastInst::Create(Instruction::IntToPtr, FuncAddr, FuncTyPntr); Anyone knows why ? Thanks Xin On Mon, Jun 18, 2012 at 10:38 PM, Caldarale, Charles R <Chuck.Caldarale at unisys.com> wrote:>> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Xin Tong >> Subject: [LLVMdev] Cast Pointer Address to Functions > >> I have a function address held in an uint64_t. I would like to cast >> the function address to a function prototype and create a call to the >> function in LLVM. How could I do this ? > > This is what works for us: > > std::vector<Type*> margs; > FunctionType* fType; > PointerType* pm3_routine; > Value* m3func; > Value* result; > > margs.resize(1); > margs[0] = I64; > fType = FunctionType::get(I32, margs, false); > pm3_routine = PointerType::get(fType, 0); > > m3func = Builder.CreateIntToPtr(I64_Const((uint64_t)pFunc), pm3_routine, "pm3func"); > result = Builder.CreateCall(m3func, parameter, "m3func"); > > - Chuck > > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Possibly Parallel Threads
- [LLVMdev] Cast Pointer Address to Functions
- [LLVMdev] Why would -disable-fp-elim cause SEGV in JIT, when without it code works fine?
- [LLVMdev] Why would -disable-fp-elim cause SEGV in JIT, when without it code works fine?
- [LLVMdev] Why would -disable-fp-elim cause SEGV in JIT, when without it code works fine?
- JIT compiler and calls to existing functions