linker emits blx instruction for arm7tdmi mcu in some condition

Bug #1578811 reported by Sergey A. Borshch
6
This bug affects 1 person
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-eabi-objdump -h -S test.elf > test.lss

if line with sscanf() call commented out, linker emits correct call to __memcmp_from_thumb:
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_from_thumb>

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-none-eabi-5_2-2015q4-20151219
Host OS - Linux Mint 17.3, tested on gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2, gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2.

Revision history for this message
Sergey A. Borshch (sb-sf) wrote :
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

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.

Changed in gcc-arm-embedded:
status: New → Confirmed
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

Hi Sergey,

it turns out it's a consequence of the bug reported at [1]. It's been fixed in newlib already and the fix will be available in our next release.

[1] https://answers.launchpad.net/gcc-arm-embedded/+question/282991

Best regards.

Changed in gcc-arm-embedded:
status: Confirmed → Fix Committed
Revision history for this message
Sergey A. Borshch (sb-sf) wrote :

Hi Thomas.

Thanks for a response and pointing to --specs mistype. I'll fix it in my makefiles.

Changed in gcc-arm-embedded:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.