[llvm-dev] armv7 pc-rel bx thumb instruction

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 26 14:36:55 PDT 2017


Hi Jonas,

On 26 July 2017 at 13:56, Jonas Devlieghere via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 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?

We wouldn't unless shim is in ARM mode; that's what the code actually
has to jump to. But it's just speculation, I haven't read the ld64
code nearly enough to pinpoint the error there.

> And why is the branch island arm code and not thumb?

If that really is the issue, it'll just be an oversight.

> Would you mind helping me understand how these branch islands work?

The basic idea is that if a call destination is too far away for the
instruction to make it there in one step the linker inserts a code
sequence roughly like this:

    ldr ip, Laddr
    bx ip
Laddr:
    .word real_function_dest

that is in range and converts the original call to jump there instead.
This allows the jump to reach anywhere in the 32-bit address since the
pointer at Laddr can be anything it wants.

There are bells and whistles for PIC code, and obviously linker
internal details get involved, but for those you're probably better
off just looking at the code.

Tim.


More information about the llvm-dev mailing list