This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcc/60464] New: [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures
- From: "jeremygccb at baymoo dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 08 Mar 2014 01:43:27 +0000
- Subject: [Bug libgcc/60464] New: [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures
- Auto-submitted: auto-generated
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 % 100000;
}
-----
3. Notice that the resultant 'test.s' generates a call to __aeabi_uldivmod:
-----
.global test1
.thumb
.thumb_func
.type test1, %function
test1:
...
movw r2, #34464
movt r2, 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:
00000000 <__aeabi_uldivmod>:
0: e3530000 cmp r3, #0
4: 03520000 cmpeq r2, #0
8: 1a000004 bne 20 <__aeabi_uldivmod+0x20>
c: e3510000 cmp r1, #0
10: 03500000 cmpeq r0, #0
14: 13e01000 mvnne r1, #0
18: 13e00000 mvnne r0, #0
1c: eafffffe b 0 <__aeabi_ldiv0>
20: e24dd008 sub sp, sp, #8
24: e92d6000 push {sp, lr}
28: ebfffffe bl 0 <__gnu_uldivmod_helper>
2c: e59de004 ldr lr, [sp, #4]
30: e28dd008 add sp, sp, #8
34: e8bd000c pop {r2, r3}
38: e12fff1e bx 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
-----