MC JIT on ARM can't generate valid code for external functions call

Hello.

We found the following problem with MC JIT, on ARM it can't generate
valid code for instruction "bl <external_function>" like:

bl printf

Because the ELF file in memory generated by MC JIT does not have the
.plt section, but we need to have the following code to be emitted in it:

.plt:00008290 STR LR, [SP,#-4]!
.plt:00008294 LDR LR, =_GLOBAL_OFFSET_TABLE_
; PIC mode
.plt:00008298 NOP
.plt:0000829C LDR PC, [LR,#8]!

Also GOT section doesn't exists.

To fix this we need to generate the valid entries in GOT and PLT sections

We propose adding these sections and generating a thunk, same as in the
usual compilation pipeline.

What is the best way to fix these issues?

Why do you need it to emit PIC? You know the offsets of all functions it
is calling.

Joerg

Instruction BL in the ARM mode can jump by offset +/- 32 MB only.

If using absolute offset, we need generate a few additional instructions same as:

load offset into register and jump to address from register, or save LR, and load into PC offset.

But in both cases change size of code in the function will lead to possibility invalidate offsets

computed in the “ARM constant island placement and branch shortening pass” and we still need

in the thunk.

There is a patch in progress (http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120220/137666.html -- I think it's still just in progress) which refactors the MCJIT dynamic loading and adds some new features. I believe that support for external functions on ARM is one of the features that was added.

-Andy