public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2
@ 2001-05-23 10:26 Richard Earnshaw
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Earnshaw @ 2001-05-23 10:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/2898; it has been noted by GNATS.

From: Richard Earnshaw <rearnsha@arm.com>
To: Philip Blundell <philb@gnu.org>
Cc: trauscher@loytec.com, gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org,
        Richard.Earnshaw@arm.com
Subject: Re: c/2898: Illegal function return in ARM code when compiling 
 with -mthumb-interwork -O2
Date: Wed, 23 May 2001 18:19:51 +0100

 > > >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. 
 > > 
 > > Thanks for your bug report.
 > > 
 > > I think the patch below should fix this problem (which, incidentally, is a 
 > > regression from 2.95).
 > > 
 > > p.
 > > 
 > > 2001-05-22  Philip Blundell  <philb@gnu.org>
 > > 
 > > 	* config/arm/arm.c (output_return_instruction): Correctly handle
 > > 	interworking and interrupt functions.
 > 
 > OK (both).
 > 
 > Thanks,
 > R.
 > 
 > 
 
 Doh! Wait a moment, we only want to avoid this sequence if really 
 returning -- popping to lr should be safe with a load even for the cases 
 concerned (though we should never be tail-calling out of an interrupt 
 function...).
 
 R.
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2
@ 2001-05-23 11:36 Philip Blundell
  0 siblings, 0 replies; 5+ messages in thread
From: Philip Blundell @ 2001-05-23 11:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/2898; it has been noted by GNATS.

From: Philip Blundell <philb@gnu.org>
To: Richard.Earnshaw@arm.com
Cc: trauscher@loytec.com, gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2 
Date: Wed, 23 May 2001 19:27:10 +0100

 >Doh! Wait a moment, we only want to avoid this sequence if really 
 >returning -- popping to lr should be safe with a load even for the cases 
 >concerned (though we should never be tail-calling out of an interrupt 
 >function...).
 
 Yeah, I know.  Really, that code wants heavier breathing on so that it spots 
 all the opportunities to use an LDR.  But that's a bit too intrusive a change 
 for me to be completely comfortable putting it on the branch; I'd rather leave 
 it until later.
 
 p.
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2
@ 2001-05-23 10:26 Richard Earnshaw
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Earnshaw @ 2001-05-23 10:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/2898; it has been noted by GNATS.

From: Richard Earnshaw <rearnsha@arm.com>
To: Philip Blundell <philb@gnu.org>
Cc: trauscher@loytec.com, gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org,
        Richard.Earnshaw@arm.com
Subject: Re: c/2898: Illegal function return in ARM code when compiling 
 with -mthumb-interwork -O2
Date: Wed, 23 May 2001 18:17:17 +0100

 > >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. 
 > 
 > Thanks for your bug report.
 > 
 > I think the patch below should fix this problem (which, incidentally, is a 
 > regression from 2.95).
 > 
 > p.
 > 
 > 2001-05-22  Philip Blundell  <philb@gnu.org>
 > 
 > 	* config/arm/arm.c (output_return_instruction): Correctly handle
 > 	interworking and interrupt functions.
 
 OK (both).
 
 Thanks,
 R.
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2
@ 2001-05-22 10:36 Philip Blundell
  0 siblings, 0 replies; 5+ messages in thread
From: Philip Blundell @ 2001-05-22 10:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/2898; it has been noted by GNATS.

From: Philip Blundell <philb@gnu.org>
To: trauscher@loytec.com
Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2 
Date: Tue, 22 May 2001 18:29:43 +0100

 >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. 
 
 Thanks for your bug report.
 
 I think the patch below should fix this problem (which, incidentally, is a 
 regression from 2.95).
 
 p.
 
 2001-05-22  Philip Blundell  <philb@gnu.org>
 
 	* config/arm/arm.c (output_return_instruction): Correctly handle
 	interworking and interrupt functions.
 
 Index: arm.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.c,v
 retrieving revision 1.142.2.1
 diff -u -p -u -r1.142.2.1 arm.c
 --- arm.c	2001/05/12 20:32:40	1.142.2.1
 +++ arm.c	2001/05/22 17:26:11
 @@ -7045,6 +7065,8 @@ output_return_instruction (operand, real
       load a single register.  On other architectures, the cost is the same.
       In 26 bit mode we have to use LDM in order to be able to restore the CPSR.  */
    if ((live_regs_mask  == (1 << LR_REGNUM))
 +      && ! TARGET_INTERWORK
 +      && ! IS_INTERRUPT (func_type)
        && (! really_return || TARGET_APCS_32))
      {
        if (! really_return)
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2
@ 2001-05-22  6:26 trauscher
  0 siblings, 0 replies; 5+ messages in thread
From: trauscher @ 2001-05-22  6:26 UTC (permalink / raw)
  To: gcc-gnats

>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:


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-05-23 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-23 10:26 c/2898: Illegal function return in ARM code when compiling with -mthumb-interwork -O2 Richard Earnshaw
  -- strict thread matches above, loose matches on Subject: below --
2001-05-23 11:36 Philip Blundell
2001-05-23 10:26 Richard Earnshaw
2001-05-22 10:36 Philip Blundell
2001-05-22  6:26 trauscher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).