This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [ARM] Wrong BLX destination
- From: Christophe Lyon <christophe dot lyon at linaro dot org>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>
- Cc: binutils at sourceware dot org
- Date: Wed, 9 Mar 2016 16:48:59 +0100
- 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>
On 9 March 2016 at 16:35, Simon Marchi <simon.marchi@polymtl.ca> wrote:
> On 2016-03-09 03:07, Christophe Lyon wrote:
>>
>> Hi,
>>
>> 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)
>
>
> Indeed:
>
> 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
> <__hello2_from_arm+0x8>
> 8704: e12fff1c bx ip
> 8708: 0000827f .word 0x0000827f
>
> 0000870c <__hello3_from_arm>:
> 870c: e59fc000 ldr ip, [pc] ; 8714
> <__hello3_from_arm+0x8>
> 8710: e12fff1c bx ip
> 8714: 00008281 .word 0x00008281
>
> 00008718 <__hello1_from_arm>:
> 8718: e59fc000 ldr ip, [pc] ; 8720
> <__hello1_from_arm+0x8>
> 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
instruction.
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.
> Thanks for the tip!
>
> Simon