[llvm-dev] [LLD] Writing thunks before the corresponding section

Bruce Hoult via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 8 04:42:43 PDT 2016


On Wed, Sep 7, 2016 at 7:55 PM, Peter Smith via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello Simon,
>
> Yes it is okay to write ARM thunks before an InputSection. There is a
> similar "inline state change" thunk in ARM that does BX PC, NOP to
> change state and fall through.


Forgot to mention: BX PC won't do anything in ARM mode. Standard way is ADD
Rn,PC,#1;BX Rn (typically LR).

In Thumb mode BX PC will switch to ARM, but the BX instruction should be
4-byte aligned and the next 2 bytes are ignored .. doesn't matter whether
they are NOP or not.

The architecture manual says BX PC from the 2nd Thumb instruction in a 4
byte word is unpredictable. On some implementations it will work, resuming
at the ARM instruction in the very next bytes (address 4 bytes more than
the word the Thumb instruction was in). But it's hit and miss. The
following code works on Odroid XU4 (A15) and Raspberry Pi 2 (A7) but not on
Raspberry Pi 3 (A53 - bus error):

 00010054 <_start>:
   10054: e24ff003 sub pc, pc, #3
   10058: 2001       movs r0, #1
   1005a: a105       add r1, pc, #20 ; (adr r1, 10070 <hello>)
   1005c: 220b       movs r2, #11
   1005e: 4778       bx pc
   10060: e3b07004 movs r7, #4
   10064: ef000000 svc 0x00000000
   10068: e3b07001 movs r7, #1
   1006c: ef000000 svc 0x00000000

00010070 <hello>:
   10070: 6c6c6548 .word 0x6c6c6548
   10074: 7361206f .word 0x7361206f
   10078: 000a216d .word 0x000a216d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160908/b256dbf4/attachment.html>


More information about the llvm-dev mailing list