[Bug libgcc/60464] New: [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures

2014-03-07 Thread jeremygccb at baymoo dot org
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
  -


[Bug libgcc/60464] [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures

2014-03-07 Thread jeremygccb at baymoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464

--- Comment #1 from Jeremy Cooper  ---
Seeing as this could be an assembler bug, my arm-none-eabi-as is:

$ arm-none-eabi-as -v
GNU assembler version 2.23.2 (arm-none-eabi) using BFD version (GNU Binutils)
2.23.2


[Bug libgcc/60464] [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures

2014-03-07 Thread jeremygccb at baymoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464

Jeremy Cooper  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #3 from Jeremy Cooper  ---
I have done as you suggested and built gcc for the target "armv7m-none-eabi"
and the "thumb" version of libgcc.a still has functions with ARM code. Shall I
re-open this bug or create a new one?


[Bug libgcc/60464] [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures

2014-03-07 Thread jeremygccb at baymoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464

--- Comment #6 from Jeremy Cooper  ---
(In reply to Andrew Pinski from comment #4)
> Can you configure with --with-arch=armv7-m and try again?  You might need to
> edit config/arm/t-arm-elf to enable only the multi-lib that you need.

I am sorry if I appear dense, but which multi-lib would I need? Recall that I'm
trying to target a cortex-m3, so what exactly do I need for the multi-lib
options in t-arm-elf? (And once this is done, how can I effect this change with
a configure option, rather than having to edit GCC source?)

MULTILIB_OPTIONS = ?
MULTILIB_DIRNAMES= ?
MULTILIB_EXCEPTIONS  = ?
MULTILIB_MATCHES = ?


[Bug libgcc/60464] [arm] ARM -mthumb version of libgcc contains ARM (non-thumb) code; not safe for thumb-only architectures

2014-03-08 Thread jeremygccb at baymoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464

--- Comment #7 from Jeremy Cooper  ---
I have managed to resolve the problem by doing two things. However, one of them
is still distasteful (editing the GCC 4.8.2 source).

1. Edited gcc/config/arm/t-arm-elf, uncommenting the following lines:

MULTILIB_OPTIONS  += march=armv7
MULTILIB_DIRNAMES += thumb2
MULTILIB_EXCEPTIONS   += march=armv7* marm/*march=armv7*
MULTILIB_MATCHES  += march?armv7=march?armv7-a
MULTILIB_MATCHES  += march?armv7=march?armv7-r
MULTILIB_MATCHES  += march?armv7=march?armv7-m
MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a8
MULTILIB_MATCHES  += march?armv7=mcpu?cortex-r4
MULTILIB_MATCHES  += march?armv7=mcpu?cortex-m3

2. configure --target=arm-none-eabi --enable-languages=c --disable-libssp
--disable-libstdcxx

Is there a reason these were commented out? Is the armv7 multilib unstable?