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: ld emitting blx immdetiate for Cortex M3

On Fri, Mar 16, 2012 at 08:34:46AM +0000, Benjamin Hase wrote:
> Hi all,
> the following simple program causes the linker to emit 'blx immediate':
> #include <stdlib.h>
> int main(int argc, char **argv)
> {
> 	int x = atoi("123");
> 	return x;
> }
> compilation with
> % arm-none-eabi-gcc -o toolchain-test.elf -Wall -nostartfiles -msoft-float -mlittle-endian -Wl,-t -mthumb -mcpu=cortex-m3 -Wl,--entry=main main.c
> /Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/bin/ld: mode armelf
> /var/folders/6r/jwq4v3_56p19hr18dyx7wcjh0000gn/T//ccANJypP.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-atoi.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-strtol.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-ctype_.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-impure.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/thumb/libgcc.a)_udivsi3.o
> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/thumb/libgcc.a)_dvmd_tls.o
> arm-none-eabi-objdump -d shows in strtol_r (which is internally called from newlib) blx instructions:
>     80a2:       1c30            adds    r0, r6, #0
>     80a4:       4651            mov     r1, sl
>     80a6:       f000 e910       blx     82c8 <__aeabi_uidivmod>
>     80aa:       1c30            adds    r0, r6, #0
>     80ac:       4689            mov     r9, r1
>     80ae:       4651            mov     r1, sl
>     80b0:       f000 e88c       blx     81cc <__aeabi_uidiv>
>     80b4:       2603            movs    r6, #3

Take a look at __aeabi_uidivmod and __aeabi_uidiv - I think you will find
that they are in ARM state, and so the BLX is valid.

This is because you have not set up your multilibs correctly for Cortex-M3
and so (at a guess) you have linked v7-M code against v4-T code containing
ARM state code.  The linker will not complain about this as it views the two
as being compatible - the linker has no idea about which core you are
targeting your image at.

Configuring and building a suitable toolchain for this is non-trivial.

The following website gives a pre-built GCC 4.6 based toolchain with Cortex-M
libraries.  It also gives instructions for how to build such a toolchain
from scratch if the options provided are not suitable for you.



Matthew Gretton-Dann
Principal Engineer, PD Software, ARM Ltd.

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