<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(32,18,77)">Hi Tim,</div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(32,18,77)"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(32,18,77)">Thank you for clarifying what the error actually means! I did read something about the BLX instruction but since I'm compiling strictly for thumb, it didn't make much sense to me. Adding -mdisable-tail-calls as a cc1 command indeed allowed me to link the generated binary. </div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(32,18,77)"><br></div><div class="gmail_default"><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">After looking some more at the ld64 source code, I came across the following comment:</font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif"><br></font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// The tail-call optimization may result in a function ending in a jump (b) </font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// to another functions.  At compile time the compiler does not know </font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// if the target of the jump will be in the same mode (arm vs thumb).</font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// The arm/thumb instruction set has a way to change modes in a bl(x)</font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// instruction, but no instruction to change mode in a jump (b) instruction.</font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// In those rare cases, the linker needs to insert a shim of code to </font></div><div class="gmail_default"><font color="#20124d" face="tahoma, sans-serif">// make the mode switch.</font></div><div class="gmail_default"><br></div><div style="color:rgb(32,18,77);font-family:tahoma,sans-serif">So it seems that a branch island is glue code added by the linker to do the actual mode switch if necessary. But why would we need a mode switch for a jump to a function that is also in thumb mode? And why is the branch island arm code and not thumb? Would you mind helping me understand how these branch islands work? I'd love to comprehend what's actually going on here. </div><div style="color:rgb(32,18,77);font-family:tahoma,sans-serif"><br></div><div style="color:rgb(32,18,77);font-family:tahoma,sans-serif">Thanks again for your help!</div><div style="color:rgb(32,18,77);font-family:tahoma,sans-serif"><br></div><div style="color:rgb(32,18,77);font-family:tahoma,sans-serif">Jonas </div></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:rgb(32,18,77)"><br></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 26, 2017 at 9:25 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</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">Hi Jonas,<br>
<br>
On 26 July 2017 at 10:52, Jonas Devlieghere via llvm-dev<br>
<span><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> I'm working on some custom transformation passes that have the side-effect<br>
> of<br>
> significantly increasing the code size. While testing it on some larger,<br>
> real-world code bases, I run into a linker error for armv7 thumb code. The<br>
> particular error I get from ld64 is that "armv7 has no pc-rel bx thumb<br>
> instruction." I've been able to reproduce the problem by taking a random<br>
> thumbv7 bitcode file and cloning functions until the linker fails.<br>
<br>
</span>Interesting. It looks like you've got a tail call from Thumb code to<br>
ARM code. The linker would normally turn a BL into a BLX to make this<br>
work, but it's (rightly) reporting that there's no "BX some_func"<br>
instruction (you have to load the destination into a register and jump<br>
there).<br>
<br>
If you have control over both functions you probably just want to<br>
compile the destination in Thumb mode (there's hardly ever reason to<br>
use ARM mode these days). But given your circumstances there's a<br>
pretty good chance the ARM code is actually a branch island ld64 is<br>
trying to insert.<br>
<br>
Other than that Clang has a "-fno-optimize-sibling-calls" which should<br>
disable tail calls and make things work. I'd suggest reporting a bug<br>
against ld64 too, it should be able to handle this case really.<br>
<br>
Cheers.<br>
<span class="gmail-m_-2970005759777052605HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div></div>