c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2

trauscher@loytec.com trauscher@loytec.com
Tue May 22 06:26:00 GMT 2001


>Number:         2898
>Category:       c
>Synopsis:       Illegal function return in ARM code when compiling with -mthumb-interwork -O2
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue May 22 06:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Thomas Rauscher
>Release:        3.0 20010514 (prerelease)
>Organization:
LoyTec electronics
>Environment:
System: Linux lexx 2.2.17 #1 Thu Oct 12 11:50:54 CEST 2000 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: arm-rtems-elf
configured with: ./configure --prefix=/prj/rtems/test --target=arm-rtems-elf --enable-languages=c --with-newlib
>Description:
When compiling for an ARM target with -mthumb-interwork and -02 or higher 
optimization,
the compiler does not correctly return with the BX instruction but loads
the PC directly. Thus, the function cannot be called from THUMB code
safely. 
>How-To-Repeat:

Following testcase shows the problem

char * f(char *a, char *b)
{
  char *c = a;
  char *d;

  if(*a)
  {
    c = d;
  }
  *c = *b;

  return a;
}

Assembly output
===============

gcc -O2 -mthumb-interwork -c testfunc.c

   0:   e52de004        str     lr, [sp, -#4]!
   4:   e1a03000        mov     r3, r0
   8:   e5d32000        ldrb    r2, [r3]
   c:   e5d1c000        ldrb    ip, [r1]
  10:   e3520000        cmp     r2, #0  ; 0x0
  14:   11a0300e        movne   r3, lr
  18:   e5c3c000        strb    ip, [r3]
  1c:   e49df004        ldr     pc, [sp], #4          <--- NO BX

gcc -O -mthumb-interwork -c testfunc.c

   0:   e1a03000        mov     r3, r0
   4:   e5d32000        ldrb    r2, [r3]
   8:   e3520000        cmp     r2, #0  ; 0x0
   c:   11a0300c        movne   r3, ip
  10:   e5d12000        ldrb    r2, [r1]
  14:   e5c32000        strb    r2, [r3]
  18:   e12fff1e        bx      lr                    <--- BX
>Fix:
  unknown
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list