<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 7, 2016 at 7:55 PM, Peter Smith via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Simon,<br>
<br>
Yes it is okay to write ARM thunks before an InputSection. There is a<br>
similar "inline state change" thunk in ARM that does BX PC, NOP to<br>
change state and fall through.</blockquote><div><br></div><div>Forgot to mention: BX PC won't do anything in ARM mode. Standard way is ADD Rn,PC,#1;BX Rn (typically LR).</div><div><br></div><div>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. </div><div><br></div><div>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):</div><div><br></div><div> 00010054 <_start>:</div><div> 10054:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>e24ff003 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sub<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>pc, pc, #3</div><div> 10058:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>2001 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>movs<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r0, #1</div><div> 1005a:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>a105 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>add<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r1, pc, #20<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>; (adr r1, 10070 <hello>)</div><div> 1005c:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>220b <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>movs<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r2, #11</div><div> 1005e:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>4778 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>bx<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>pc</div><div> 10060:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>e3b07004 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>movs<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r7, #4</div><div> 10064:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ef000000 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>svc<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x00000000</div><div> 10068:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>e3b07001 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>movs<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r7, #1</div><div> 1006c:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ef000000 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>svc<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x00000000</div><div><br></div><div>00010070 <hello>:</div><div> 10070:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>6c6c6548 <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>.word<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x6c6c6548</div><div> 10074:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>7361206f <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>.word<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x7361206f</div><div> 10078:<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>000a216d <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>.word<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x000a216d</div><div><br></div></div></div></div>