linker emits blx instruction for arm7tdmi mcu in some condition
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
if call to sscanf() exist somewhere in source code, even if function with this call removed by linker --gc-sections, linker emits unsupported by arm7tdmi core blx instruction to call arm mode functions from thumb code.
Here is simple test code to reproduce bug (file attached):
#include <string.h>
int _start() // _start() instead of main() just to remove all startup code from disassembly
{
return memcmp((void *)0, (void *) 100, 15); // call to any arm-mode function
}
#include <stdio.h>
void dummy ()
{
char Buffer[2];
// sscanf(Buffer, " "); <- uncomment this line to trigger bug
}
commands to compile:
arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb-interwork -mthumb -Os -ffunction-sections -c test.c -o test.o
arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb-interwork --specs=nano.specs -nostartfiles -Wl,--gc-sections test.o -o test.elf
arm-none-
if line with sscanf() call commented out, linker emits correct call to __memcmp_
00008000 <main>:
8000: b510 push {r4, lr}
8002: 220f movs r2, #15
8004: 2164 movs r1, #100 ; 0x64
8006: 2000 movs r0, #0
8008: f000 f822 bl 8050 <__memcmp_
if line with sscanf() call uncommented, linker emits blx instruction, which is not supported by arm7tdmi core:
00008000 <main>:
8000: b510 push {r4, lr}
8002: 220f movs r2, #15
8004: 2164 movs r1, #100 ; 0x64
8006: 2000 movs r0, #0
8008: f000 e80a blx 8020 <memcmp>
bug exist since gcc-arm-
Host OS - Linux Mint 17.3, tested on gcc-arm-
Changed in gcc-arm-embedded: | |
status: | Fix Committed → Fix Released |
Hi Sergey,
Thanks for your bug report.
This seems to be related to newlib-nano in some way. When linking with straight newlib I get the expected bl. Only when linking with newlib-nano did I get the bug. We'll keep you updated of the progress on this bug.
By the way, I noticed you use --specs but the documented syntax is -specs. It seems it works as well for now but you might want to use the documented symtax.
Best regards.