This is the mail archive of the
mailing list for the binutils project.
Re: [ARM] Wrong BLX destination
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Christophe Lyon <christophe dot lyon at linaro dot org>
- Cc: binutils at sourceware dot org
- Date: Wed, 09 Mar 2016 10:58:16 -0500
- Subject: Re: [ARM] Wrong BLX destination
- Authentication-results: sourceware.org; auth=none
- References: <CAKdteOZgr1AmECQO7yoA9=bos9Ea93WO7Do=WkHJq9Xt+xDpsw at mail dot gmail dot com> <2fb53383fd85fd969aba8d8f06f85430 at simark dot ca> <CAKdteOZmkrJL6uYzaREEL1bgBxXgQEOk0c4DH2ZOZfW6PZp6vw at mail dot gmail dot com>
On 2016-03-09 10:48, Christophe Lyon wrote:
On 9 March 2016 at 16:35, Simon Marchi <email@example.com> 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
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:
8700: e59fc000 ldr ip, [pc] ; 8708
8704: e12fff1c bx ip
8708: 0000827f .word 0x0000827f
870c: e59fc000 ldr ip, [pc] ; 8714
8710: e12fff1c bx ip
8714: 00008281 .word 0x00008281
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
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
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.