This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ARM] Wrong BLX destination

On 2016-03-09 10:48, Christophe Lyon wrote:
On 9 March 2016 at 16:35, Simon Marchi <> wrote:
On 2016-03-09 03:07, Christophe Lyon wrote:


I haven't looked at this for a while, but:
- which relocations are encoded by gas? (objdump -r). I suspect you
have the ARM version of call (as opposed to the thumb one)


  00000000 R_ARM_CALL        hello1

- I think you have to use the .thumb_func assembly directive right
before helloX definition, and probably give it a function type too

The linker will take care of making the call point to the right
address, provided it has the right relocations.

When adding .thumb_func before the helloX definitions, the branches are now

    8220:       eb00013c        bl      8718 <__hello1_from_arm>
    8224:       eb000135        bl      8700 <__hello2_from_arm>
    8228:       eb000137        bl      870c <__hello3_from_arm>

and this additional code was added somewhere:

  00008700 <__hello2_from_arm>:
      8700:       e59fc000        ldr     ip, [pc]        ; 8708
      8704:       e12fff1c        bx      ip
      8708:       0000827f        .word   0x0000827f

  0000870c <__hello3_from_arm>:
      870c:       e59fc000        ldr     ip, [pc]        ; 8714
      8710:       e12fff1c        bx      ip
      8714:       00008281        .word   0x00008281

  00008718 <__hello1_from_arm>:
      8718:       e59fc000        ldr     ip, [pc]        ; 8720
      871c:       e12fff1c        bx      ip
      8720:       0000827d        .word   0x0000827d

So while it doesn't simply use BLX with the H bit set, it seems that it
would now work properly with this indirection.

Did you supply a --cpu flag or a .cpu directive in your asm source?
If no, then the tools default to some old version (I don't remember
which) of the arm architecture which did not support the blx

Hence the linker insert stubs to provide the desired behaviour
(switching between arm and thumb modes).

Add .cpu cortex-a9 in your source, and the linker should not insert stubs.

Right! Adding .cpu cortex-a9 to either assembly source file works. The result is now:

    8220:       fa000015        blx     827c <hello1>
    8224:       fb000014        blx     827e <hello2>
    8228:       fa000014        blx     8280 <hello3>

Adding -mcpu=cortex-a9 to the command line works as well, obviously.

Thanks for your help, I would never have guessed it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]