2015Q4 newlib nano for ARMv5TE uses Thumb-2 instructions

Asked by Doug Brunner

After upgrading to 5.2 2015Q4 from 4.9 2015Q3, I encountered an undefined instruction exception on my ARM968E-S (NXP LPC2929). I investigated and found that the default newlib nano (arm-none-eabi/lib/libc_nano.a) contains a Thumb-2 instruction in strlen, specifically ldrb.w. Thumb-2 is not supported on architectures before ARMv6T2, so this crashes. Using objdump -d on the library:

<other object files>

lib_a-strlen.o: file format elf32-littlearm

Disassembly of section .text:

00000000 <strlen>:
   0: 4603 mov r3, r0
   2: f813 2b01 ldrb.w r2, [r3], #1
   6: 2a00 cmp r2, #0
   8: d1fb bne.n 2 <strlen+0x2>
   a: 1a18 subs r0, r3, r0
   c: 3801 subs r0, #1
   e: 4770 bx lr

<other object files>

This makes it into my final executable, and the CPU never gets past <strlen+2>. It appears from a quick regex search of the objdump output that there are no other functions using Thumb instructions, so perhaps this was a hand-coded assembly function?

I'm using the prebuilt Win32 toolchain from Launchpad, host OS Windows 10 Pro. My final link command is:
arm-none-eabi-g++ -g -Og -mcpu=arm968e-s -march=armv5te --specs=nano.specs -nostartfiles -Wl,--gc-sections -Tboard/cs2.ld -Wl,-Map=main/default.elf.map main/Application.o main/PowertrainApplication.o main/default.o libScreens.a libTextDisplay.a libTransmission.a libVariation.a libOption.a libSensor.a libShiftSelector.a libControl.a libNet.a libCAN.a libDiag.a libParam.a libHardware.a libCore.a libBoard.a -o main/default.elf
I would expect this to produce a binary with only ARM and Thumb (not Thumb-2) instructions. Using the 2015Q3 release, for example, strlen is all in ARM mode.

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Doug,

I can indeed reproduce the problem and identified the root cause. A changed occured in strlen between our Q3 and Q4 release. It affects all newlib-nano multilib targeting ARM instructions on an architecture without Thumb-2. We will let you know once this issue is fixed. Hopefully this can be fixed in next release.

Best regards.

Can you help with this problem?

Provide an answer of your own, or ask Doug Brunner for more information if necessary.

To post a message you must log in.