[LLVMdev] Android JIT patch

James Lyon jameslyon0 at gmail.com
Mon Nov 11 11:12:41 PST 2013


On 11/11/13 17:42, Kaylor, Andrew wrote:
> I've got a number of problems with this patch.
>
> First, we have plans to pry apart the remaining strands connecting JIT with MCJIT, so I don't want to do anything that reconnects them.  That is, I'm against moving things from RTDyldMemoryManager into ExecutionEngine.
The direction of LLVM is not something I'm in a position to comment on. 
The problem of locating these functions is common to the JIT and MCJIT 
though (and even the interpreter for Linux/x86).
>
> Second, unless I'm reading it wrong, this relies on static constructors.  That causes headaches and is against the LLVM coding standards.
My bad, I just ripped off the existing implementation. I guess the 
JITMemoryManager part is destined to go away along with the JIT.
>
> Third, I don't think sys::DynamicLibrary::AddSymbol() is the right way to go here.  I know I have recently suggested using that function, but I was wrong.  That function exposes symbols to the entire host program as if they were present in a locally loaded shared library.  For some programs that may be acceptable behavior, but it cannot be the default behavior for LLVM.  In particular, MCJIT may not even be generating code for local execution.
Well, that's a bit trickier. Somewhere there needs to be a hook to find 
these functions (and make the linker include them). For remote execution 
I suppose that the user would have to load a shared object supporting 
this functionality into the target address space and then query it for 
the address of such functions. I'm assuming that the user isn't expected 
to solve this problem if they're not using remote execution.
>
> The default RTDyldMemoryManager implementation selectively exposes symbols to execution engines for which it is used, and MCJIT/RuntimeDyld clients performing remote execution can (and should) override this behavior.  We probably also need to fix the addGlobalMapping support for MCJIT.
The situation right now is actually more complicated than this: since 
llvm-config --libs MCJIT includes the LLVMJIT library the 
JITMemoryManager hack is always there (subject to being dropped by ld?) 
so these symbols are actually exposed globally.

As I said, I basically just borrowed from the existing code and added 
the functions which won't work without glibc on ARM. 
sys::DynamicLibrary::SearchForAddressOfSymbol only seems to be used by 
stuff under lib/ExecutionEngine, so making that find functions which are 
expected to be in libc during normal linking doesn't seem unreasonable.

James
>
> -Andy
>
> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of James Lyon
> Sent: Sunday, November 10, 2013 5:45 PM
> To: LLVM Dev
> Subject: [LLVMdev] Android JIT patch
>
> I've attached a patch which has got JIT compilation working (for me at
> least!) on Android. It turns out that the problem was a bunch of intrinsic __aeabi* functions which reside in libgcc.a rather than libc.so so are not available unless explicitly linked in, so it's rather similar to the StatSymbols hack.
>
> I moved the StatSymbols code into ExecutionEngine.cpp rather than JITMemoryManager.cpp since it's required for both the JIT and MCJIT, and deleted the code in RTDyldMemoryManager.cpp which did the same thing for fewer functions. They should now be picked up through the sys::DynamicLibrary::AddSymbol mechanism in both cases. The symbols required for ARM/Android are then added by an identical hack just below.
>
> There's one other minor change since setLastModificationAndAccessTime can't be supported on Android; all relevant system calls are missing from the C library. I've therefore changed the code to fail at runtime rather than compile-time here.
>
> James




More information about the llvm-dev mailing list