http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464
Bug ID: 60464
Summary: [arm] ARM -mthumb version of libgcc contains ARM
(non-thumb) code; not safe for thumb-only
architectures
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: jeremygccb at baymoo dot org
SUMMARY
Configuring and building gcc 4.8.2 for the target 'arm-none-eabi' results in a
thumb version of libgcc.a that is not entirely suitable for thumb-only
processors. This bug is also present in 4.8.1.
DETAILS
I have built GCC 4.8.2 using the following configuration:
- config.log snippet -
$ /Users/build/Downloads/gcc-4.8.2/configure --target=arm-none-eabi
--enable-languages=c --disable-libssp --disable-libstcdxx
## - ##
## Platform. ##
## - ##
hostname = not-relevant.local
uname -m = x86_64
uname -r = 12.4.0
uname -s = Darwin
uname -v = Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013;
root:xnu-2050.24.15~1/RELEASE_X86_64
---
When using this compiler to compile code targeted for '-mcpu=cortex-m3 -mthumb'
I noticed that some of the routines in the resulting binary still seem to
expect the processor to support ARM (non-thumb) mode. On further inspection I
found that these routines came from '_clzsi2.o' and '_divsi3.o' from libgcc.a.
I double-checked that the correct version of libgcc.a was being used:
-
$ /usr/local/bin/arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb
-print-libgcc-file-name
/usr/local/lib/gcc/arm-none-eabi/4.8.2/thumb/libgcc.a
-
TO REPRODUCE
1. Configure: --target=arm-none-eabi --enable-languages=c --disable-libssp
--disable-libstcdxx
2. Compile a short test program:
$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -S test.c
- test.c
unsigned int
test1(unsigned long long a)
{
return a % 10;
}
-
3. Notice that the resultant 'test.s' generates a call to __aeabi_uldivmod:
-
.global test1
.thumb
.thumb_func
.type test1, %function
test1:
...
movwr2, #34464
movtr2, 1
mov r3, #0
bl __aeabi_uldivmod
mov r3, r2
mov r0, r3
-
4. Notice that __aeabi_uldivmod in
/usr/local/lib/gcc/arm-none-eabi/4.8.2/thumb/libgcc.a is a non-thumb function.
$ arm-none-eabi-objdump -d
/usr/local/lib/gcc/arm-none-eabi/4.8.2/thumb/libgcc.a
-
_aeabi_uldivmod.o: file format elf32-littlearm
Disassembly of section .text:
<__aeabi_uldivmod>:
0: e353cmp r3, #0
4: 0352cmpeq r2, #0
8: 1a04bne 20 <__aeabi_uldivmod+0x20>
c: e351cmp r1, #0
10: 0350cmpeq r0, #0
14: 13e01000mvnne r1, #0
18: 13e0mvnne r0, #0
1c: eafeb 0 <__aeabi_ldiv0>
20: e24dd008sub sp, sp, #8
24: e92d6000push{sp, lr}
28: ebfebl 0 <__gnu_uldivmod_helper>
2c: e59de004ldr lr, [sp, #4]
30: e28dd008add sp, sp, #8
34: e8bd000cpop {r2, r3}
38: e12fff1ebx lr
-
5. Notice that this occurred even though the build process for
thumb/libgcc.a(_aeabi_uldivmod.o) correctly asserted its intent by passing the
'-mthumb' to the compiler driver by inspecting the GCC build log:
-
/Users/build/builds/gcc-4.8.2-arm-none-eabi/./gcc/xgcc
-B/Users/build/builds/gcc-4.8.2-arm-none-eabi/./gcc/
-B/usr/local/arm-none-eabi/bin/ -B/usr/local/arm-none-eabi/lib/ -isystem
/usr/local/arm-none-eabi/include -isystem /usr/local/arm-none-eabi/sys-include
-g -O2 -mthumb -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall
-Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -isystem ./include -fno-inline -g -DIN_LIBGCC2
-fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -fno-inline -I. -I.
-I../../.././gcc -I/Users/build/Downloads/gcc-4.8.2/libgcc
-I/Users/build/Downloads/gcc-4.8.2/libgcc/.
-I/Users/build/Downloads/gcc-4.8.2/libgcc/../gcc
-I/Users/build/Downloads/gcc-4.8.2/libgcc/../include -DHAVE_CC_TLS -o
_aeabi_uldivmod.o -MT _aeabi_uldivmod.o -MD -MP -MF _aeabi_uldivmod.dep
-DL_aeabi_uldivmod -xassembler-with-cpp -c
/Users/build/Downloads/gcc-4.8.2/libgcc/config/arm/lib1funcs.S -include
_aeabi_uldivmod.vis
-