Alec Benzer <alecbenzer at gmail.com> writes:> Ok, so calling lle_X_FUNCTIONNAME instead of FUNCTIONNAME works (is there > any reason the post used the lle_X_ prefix other than convention? was it > once possible to call external functions as I was originally trying, or, why > did the blog post think it was possible?)AFAIK you can name the function as you please (with some reasonable restrictions on the character set, etc)> I'm now running into trouble when trying to access arguments however. > printing args.size() from the function yields 12105250188025543488. The > generated call to it looks like: > > %object_tmp = call %object_structure* @lle_X_create_number_object(double > 5.000000e+00) ; <%object_structure*> [#uses=1]You are calling a function that takes a single argument of type `double'. But on a previous post you showed the function with this signature: llvm::GenericValue lle_X_create_number_object(llvm::FunctionType* ft, const std::vector<llvm::GenericValue>& args) so as the execution enters the function above from your call, the stack can be considered corrupt. Also, the return type of the `call' might not be right (it depends on the ABI of your platform.) It is strange to generate GenericValue's from JITted code. Are you doing some kind of meta-interpreter? I'm afraid that you might be utterly confused about how to use LLVM.
> I'm afraid that you might be utterly confused about how to use LLVM.Er, I don't think so? I think I was mostly just confused about interfacing with external functions, since whoever wrote that blog post ( http://www.gearleaf.com/blog/post/44) didn't seem to know what he was talking about (or he was doing stuff that once worked but now doesn't? I don't know). If you glance at that post I think you'll understand why I was doing what I was doing. anyway, I think I get it now, what I was trying to do seems to be working how I expect it to. On Thu, Aug 19, 2010 at 8:55 PM, Óscar Fuentes <ofv at wanadoo.es> wrote:> The following message is a courtesy copy of an article > that has been posted to gmane.comp.compilers.llvm.devel as well. > > Alec Benzer <alecbenzer at gmail.com> writes: > > > Ok, so calling lle_X_FUNCTIONNAME instead of FUNCTIONNAME works (is there > > any reason the post used the lle_X_ prefix other than convention? was it > > once possible to call external functions as I was originally trying, or, > why > > did the blog post think it was possible?) > > AFAIK you can name the function as you please (with some reasonable > restrictions on the character set, etc) > > > I'm now running into trouble when trying to access arguments however. > > printing args.size() from the function yields 12105250188025543488. The > > generated call to it looks like: > > > > %object_tmp = call %object_structure* @lle_X_create_number_object(double > > 5.000000e+00) ; <%object_structure*> [#uses=1] > > You are calling a function that takes a single argument of type > `double'. But on a previous post you showed the function with this > signature: > > llvm::GenericValue > lle_X_create_number_object(llvm::FunctionType* ft, > const std::vector<llvm::GenericValue>& args) > > so as the execution enters the function above from your call, the stack > can be considered corrupt. Also, the return type of the `call' might not > be right (it depends on the ABI of your platform.) > > It is strange to generate GenericValue's from JITted code. Are you doing > some kind of meta-interpreter? I'm afraid that you might be utterly > confused about how to use LLVM. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100819/228fb43c/attachment.html>
o.j.sivart at gmail.com
2010-Aug-20 02:17 UTC
[LLVMdev] using external functions from llvm
On 20/08/2010, at 11:29 AM, Alec Benzer wrote:> > I'm afraid that you might be utterly confused about how to use LLVM. > > Er, I don't think so? I think I was mostly just confused about interfacing with external functions, since whoever wrote that blog post (http://www.gearleaf.com/blog/post/44) didn't seem to know what he was talking about (or he was doing stuff that once worked but now doesn't? I don't know). If you glance at that post I think you'll understand why I was doing what I was doing.The blog appears to leave out a lot of context and as such is confusing. lle_X appears to be a special prefix which is used by the interpreter and not the JIT from what I can gather from a quick look at https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_27/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp but I didn't bother to look to much into the detail.> anyway, I think I get it now, what I was trying to do seems to be working how I expect it to. > > On Thu, Aug 19, 2010 at 8:55 PM, Óscar Fuentes <ofv at wanadoo.es> wrote: > The following message is a courtesy copy of an article > that has been posted to gmane.comp.compilers.llvm.devel as well. > > Alec Benzer <alecbenzer at gmail.com> writes: > > > Ok, so calling lle_X_FUNCTIONNAME instead of FUNCTIONNAME works (is there > > any reason the post used the lle_X_ prefix other than convention? was it > > once possible to call external functions as I was originally trying, or, why > > did the blog post think it was possible?) > > AFAIK you can name the function as you please (with some reasonable > restrictions on the character set, etc) > > > I'm now running into trouble when trying to access arguments however. > > printing args.size() from the function yields 12105250188025543488. The > > generated call to it looks like: > > > > %object_tmp = call %object_structure* @lle_X_create_number_object(double > > 5.000000e+00) ; <%object_structure*> [#uses=1] > > You are calling a function that takes a single argument of type > `double'. But on a previous post you showed the function with this > signature: > > llvm::GenericValue > lle_X_create_number_object(llvm::FunctionType* ft, > const std::vector<llvm::GenericValue>& args) > > so as the execution enters the function above from your call, the stack > can be considered corrupt. Also, the return type of the `call' might not > be right (it depends on the ABI of your platform.) > > It is strange to generate GenericValue's from JITted code. Are you doing > some kind of meta-interpreter? I'm afraid that you might be utterly > confused about how to use LLVM. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100820/2b7356b4/attachment.html>
Alec Benzer <alecbenzer at gmail.com> writes:>> I'm afraid that you might be utterly confused about how to use LLVM. > > Er, I don't think so? I think I was mostly just confused about interfacing > with external functions, since whoever wrote that blog post ( > http://www.gearleaf.com/blog/post/44) didn't seem to know what he was > talking about (or he was doing stuff that once worked but now doesn't? I > don't know). If you glance at that post I think you'll understand why I was > doing what I was doing. > > anyway, I think I get it now, what I was trying to do seems to be working > how I expect it to.I've just looked at the blog post. That is over-complicated. There is no need for a wrapping function for calling external functions. It seems to me that the example on that blog post is badly broken on several ways. Instead of sys::DynamicLibrary::AddSymbol use Module::getOrInsertFunction and then ExecutionEngine::addGlobalMapping passing to it a pointer to your function. No wrappers needed. Be sure that the FunctionType matches the signature of your function. Try first with the simplest case (a function that takes 0 args and returs void) then with an integer argument, etc. Things become really messy when you reach C structs (let's forget about C++ classes.) Finally, follow the standard requirements for setting up the JIT, like calling InitializaNativeTarget at the beginning of `main'. My advice is to forget about the example on that blog post and use as an skeleton some of the examples that comes with LLVM, like HowToUseJIT or Fibonacci.