[LLVMdev] Execution of generated code after multiple compiles fails
Chuck Rose III
cfr at adobe.com
Tue Apr 17 14:00:43 PDT 2007
I'm having a tricky time diagnosing something that is going on in my
program and am hoping some of you might have used LLVM in a similar way
before. All of this is using LLVM 1.9 on Mac OSX. Here is our usage
1. Read in a program in a language we are designing
2. Transform it into LLVM IR using the llvm class hierarchy
3. Link this module to a set of support functions written offline
in C and compiled using the llvm compiler into LLVM IR bytecode
4. Construct a JIT execution environment for X86
5. Run the function
6. Destroy the execution environment, module, linker, etc. Note
this doesn't destroy all LLVM state as there are some things static to
classes such as the machine code emitters.
Under the hood, the JIT callbacks are occurring and are doing the native
compilation on the necessary support functions from the read-in
bytecode. The first few times this process is done, everything works
fine. Repeating this process for the same program and support-function
combination resulted in crashing on the second iteration. Stepping
through the program got me as far as having it
1. Run through the whole process as described above with correct
2. In iteration #32, compile the primary function I want to run
3. Compiling the stub function to turn my primary function into a
4. Getting to the X86 JIT callback
5. Compiling the first support function via JITter
6. Entry into the first support function
7. Crashing somewhere before getting back to the next callback.
Specifically we get a "Program received signal: 'EXC_BAD_ACCESS'"
message and then loose all stack info. It won't break on the offending
instruction, only after the game is already lost.
Unfortunately, XCode is fairly uninformative when you step into code
you've just created, so you have to go on memory dumps, watching the
registers, and doing the disassembly in your head. Once it calls back
into the callbacks its brain resets and gives you a real debugging
I realize this description isn't effective as a repro-case, but I'm
dealing with a fairly large system and before I go about hacking things
apart to try and construct one I was hoping that some of you may have
had experience with this kind of thing. What tools do you all use to
deal with crashes like these? Is there a more robust alternative than
XCode for dealing with low level debugging with on-the-fly generated
code? Have many changes occurred between 1.9 in this area that I should
just abandon 1.9 in favor of the CVS sources?
Any help is greatly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev