Bug 15628 - Cortex M4 incorrect blx instruction generated
Summary: Cortex M4 incorrect blx instruction generated
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-14 13:09 UTC by Matias henttunen
Modified: 2013-06-17 07:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matias henttunen 2013-06-14 13:09:17 UTC
It seems incorrect code is generated when I compile the following example

-------mylib.c-----------
int test()
{
        return 1;
}
arm-none-eabi-gcc -fPIC -mcpu=cortex-m4 -mthumb -O2 -ggdb  mylib.c -o mylib.so
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O2 -ggdb  -lmylib main.c -o test

----main.c---------
int main()
{
        test();
        return 1;
}



The machine generated code for main looks as follows (objdump -D):
0000015c <main>:
 15c:   b508            push    {r3, lr}
 15e:   f000 e888       blx     270 <__libc_fini_array+0xfc>
 162:   2001            movs    r0, #1
 164:   bd08            pop     {r3, pc}
 166:   bf00            nop

instruction at  15e:   seems incorrect to me, since M4 only branches using 
a register   blx{cond} Rm, (M3 seems to be ok with label aswell.)

Ive tried to use -mlong-calls, and it produces:
00000164 <main>:
 164:   b508            push    {r3, lr}
 166:   f240 237c       movw    r3, #636        ; 0x27c
 16a:   f2c0 0300       movt    r3, #0
 16e:   4798            blx     r3
 170:   2001            movs    r0, #1
 172:   bd08            pop     {r3, pc}

This looks OK except for the address in R3 not being rellative, since it's 
absolute it's not correct either (or am I missing something)

is a workaround for this, or am I doing something wrong here ?

/Matias