Luke Evans
2009-Mar-15 22:20 UTC
[LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
I'm a total LLVM n00b, and have just started to work through some of the tutorials with the intention of gathering a clear picture of what LLVM does and doesn't do for a possible project. I'm on the Mac, and would like to have my code dynamically create and load new functions into a process. I believe I can do this, but I'm not sure yet how 'direct' things will be in terms of both the tool chain, and how much I need to emit intermediate files. I think I will have to ultimately dynamically load from a Mach-O dylib file (dopen), but in any case I'm interested in whether I can go straight from my in-memory linked module(s) to a Mach-O file that I can dynamically load, using the LLVM API as it exists at V2.5. Before I even worry about coding this up directly, I've been playing with doing this the available tools to see what the various steps are likely to be. From comments on this list, it looks like going from bitfile to a native Mach-O file ought to be possible, but I've tried "llc -filetype=dynlib" (and indeed -filetype=obj) and get the message "target does not support generation of this file type!". BTW, I compiled the LLVM stuff myself, but assume it does the right thing w.r.t. building in appropriate knowledge of the native platform. I can see how to generate an assembly file, then use the platform tools to compile and link this, but I get the impression this is unnecessary with the current state-of-play. Would anyone be kind enough to provide clue? I couldn't find any samples or docs that directly speak to this - probably because it's a minor part of the overall LLVM system. Cheers Luke
John McCall
2009-Mar-15 23:09 UTC
[LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
On Mar 15, 2009, at 3:20 PM, Luke Evans wrote:> I'm on the Mac, and would like to have my code dynamically create and > load new functions into a process. I believe I can do this, but I'm > not sure yet how 'direct' things will be in terms of both the tool > chain, and how much I need to emit intermediate files.Are you just loading functions into the current process? There's no need to create temporary object files and dynamically link them in; LLVM is perfectly capable of assembling a function in memory. Look up the docs for llvm::ExecutionEngine::create and go from there. John.
Luke Evans
2009-Mar-15 23:23 UTC
[LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
Thanks John. I had passed over ExecutionEngine as it looked like it offered a JIT. Maybe there's more to it than meets the (hasty) eye though. I'm interested in getting a native image. Ultimately, I'd like to do things like emitting Objective-C IMPs and building Objective-C classes around them. However, I'm going one step at a time (there's probably much to learn and maybe gotchas to discover before I get to this). To begin with, I figured I'd try to get a Mach-O file written out, dload'ed and then make a regular C call to a loaded function. So, I'll take a look at ExecutionEngine, but I'm still curious if I'm currently able to emit Mach-O dylibs directly from the LLVM tool chain, or if I have to go a little more round-the-houses (perhaps emitting .s and then using platform tools to get to the dylib). -- lwe On 15-Mar-09, at 6:09 PM, John McCall wrote:> Are you just loading functions into the current process? There's no > need > to create temporary object files and dynamically link them in; LLVM > is > perfectly capable of assembling a function in memory. Look up the > docs for llvm::ExecutionEngine::create and go from there. > > John.-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090315/80165ddd/attachment.html>
Eric Christopher
2009-Mar-16 01:38 UTC
[LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
On Mar 15, 2009, at 4:23 PM, Luke Evans wrote:> I had passed over ExecutionEngine as it looked like it offered a > JIT. Maybe there's more to it than meets the (hasty) eye though. >It does...> I'm interested in getting a native image. Ultimately, I'd like to > do things like emitting Objective-C IMPs and building Objective-C > classes around them. > However, I'm going one step at a time (there's probably much to > learn and maybe gotchas to discover before I get to this). > To begin with, I figured I'd try to get a Mach-O file written out, > dload'ed and then make a regular C call to a loaded function. >Aaah. Wasn't quite sure what you were doing here. I'm not positive what llvm can emit via the writers (there's support for all parts of the file format), but it could be extended to write one out. I'm just not quite sure why :) -eric
Luke Evans
2009-Mar-16 02:54 UTC
[LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
> Aaah. Wasn't quite sure what you were doing here. I'm not positive > what llvm can emit via the writers (there's support for all parts of > the file format), but it could be extended to write one out. I'm just > not quite sure why :) > > -ericWell, ultimately I'm curious about what it would take to port a JVM based language (http://openquark.org) to LLVM. A main motivator though is language/library/platform integration on the Mac (Cocoa, Objective-C, autozone). I'm not too interested in a JIT at this point, but rather native code generation. So far I can see a MachOWriter (with an "AddMachOWriter" in FileWriters.h) and it looks like I get to pass an appropriate TargetMachine to this. I'm wondering if this is expected to be sufficient (added to a pass manager) to be able to output a library on the Mac - whether or not it actually works. I only picked LLVM up yesterday, so I'm still trying to understand how the parts work together. With my current lack of orientation I have very little intuition as to whether I'm on the right track, and if it fails, how close (or otherwise) I might have been to getting something going. So I suppose I've been looking for hints at the vague 'shape' of the code I would expect to connect together to get the output I want, and while there are some nice samples for some parts of LLVM, I haven't found much to help learn how to emit native .o or .dylib (assuming this is possible). In the meantime I'll spend some time trying to bang some of the aforementioned pieces together and see if I can get it to do anything interesting with a minimal module. Thanks. -- lwe -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090315/4b6d0655/attachment.html>
Maybe Matching Threads
- [LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
- [LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
- [LLVMdev] Bit-code file input to ld (was: ...From module/bitcode to Mach-O dylib file directly)
- [LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?
- [LLVMdev] n00b question: From module/bitcode to Mach-O dylib file directly?