Fix for ExecutionEngine buglet

Kaylor, Andrew andrew.kaylor at
Wed Nov 13 10:17:08 PST 2013

Hi Dale,

I assume from the description that you are using either the interpreter or the old JIT execution engine.  If you are using the old JIT, have you considered migrating to MCJIT?  That's not relevant to the patch, but I think it's a good idea.  We're planning to deprecate the old JIT engine in a future release.

As for the patch itself, it seems like it would be better to have the function return immediately if GA is NULL after the call to getMemoryForGV.  We definitely don't want to increment the number of init bytes or the number of global variables in that case.  It would be nice if we had some way to let the caller know the method failed.  Even better would be to figure out why the allocation is failing and fix it.  I'm assuming based on the fact that total program failure is avoidable that we aren't really out of memory.  That said, I wouldn't object to a patch that simply avoids catastrophic failure at this point if that's all you have time for and it is sufficient for your current needs.


-----Original Message-----
From: llvm-commits-bounces at [mailto:llvm-commits-bounces at] On Behalf Of Dale E. Martin
Sent: Tuesday, November 12, 2013 11:21 AM
To: llvm-commits at
Subject: Fix for ExecutionEngine buglet

I have discovered a small bug in the ExecutionEngine.  A proposed fix is attached.

There is a place in the ExecutionEngine where it is not resilient to a failed allocation.  I believe the circumstances are:
* It is near the end of the buffer that has been allocated for code/data
* It is trying to allocate space for a large global, which is not found in the globalAddressMap
* It tries to allocate it via "getMemoryForGV", but that fails after looking at CurBufferPtr, so it returns NULL
* It does not check for a NULL return, and then it calls InitializeMemory with a NULL destination which gets passed into memcpy
* It segvs before looking at CurBufferPtr to see if memory is exhausted and retrying with more memory allocated

I don't know of a good way to unit test this but I have a repeatable failure in some code I'm working on and this patch fixes it.

Let me know if you have more questions, comments, etc.

Dale E. Martin - dale at

More information about the llvm-commits mailing list