public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/32838]  New: gcc generates incorrect trampoline code in thumb mode
@ 2007-07-20 11:52 leo at marco dot de
  2007-07-20 11:53 ` [Bug target/32838] " leo at marco dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: leo at marco dot de @ 2007-07-20 11:52 UTC (permalink / raw)
  To: gcc-bugs

When using nested functions, the trampoline code will destroy register 9 while
loading the static chain. This is even noted in gcc/config/arm/arm.h:
XXX FIXME: When the trampoline returns, r8 will be clobbered.
(it will be r9 and not r8...).
The attached patch avoids clobbering r9.


-- 
           Summary: gcc generates incorrect trampoline code in thumb mode
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: leo at marco dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
@ 2007-07-20 11:53 ` leo at marco dot de
  2007-07-20 11:55 ` leo at marco dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: leo at marco dot de @ 2007-07-20 11:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from leo at marco dot de  2007-07-20 11:53 -------
Created an attachment (id=13943)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13943&action=view)
fix for the reported bug


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
  2007-07-20 11:53 ` [Bug target/32838] " leo at marco dot de
@ 2007-07-20 11:55 ` leo at marco dot de
  2009-01-02 12:31 ` laurent at guerby dot net
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: leo at marco dot de @ 2007-07-20 11:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from leo at marco dot de  2007-07-20 11:55 -------
(In reply to comment #0)
I forgot to mention that this happens only for thumb mode.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
  2007-07-20 11:53 ` [Bug target/32838] " leo at marco dot de
  2007-07-20 11:55 ` leo at marco dot de
@ 2009-01-02 12:31 ` laurent at guerby dot net
  2009-03-17 16:48 ` leo at marco dot de
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: laurent at guerby dot net @ 2009-01-02 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from laurent at guerby dot net  2009-01-02 12:29 -------
This needs a testcase


-- 

laurent at guerby dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
                   ` (2 preceding siblings ...)
  2009-01-02 12:31 ` laurent at guerby dot net
@ 2009-03-17 16:48 ` leo at marco dot de
  2009-03-19 10:15 ` sam at gcc dot gnu dot org
  2009-03-19 19:08 ` leo at marco dot de
  5 siblings, 0 replies; 7+ messages in thread
From: leo at marco dot de @ 2009-03-17 16:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from leo at marco dot de  2009-03-17 16:47 -------
Subject: Re:  gcc generates incorrect trampoline code in
 thumb mode

laurent at guerby dot net wrote:
> ------- Comment #3 from laurent at guerby dot net  2009-01-02 12:29 -------
> This needs a testcase
> 
>
Testcase:


void
f(int aa, int bb, int cc, int dd, int ee, int ff)
{
         extern int x(int (*)(void));

         int
         q(void)
         {
                 extern int a(int);
                 return(a(ff)*55);
         }

         x(&q);
}

"arm-elf-gcc -mthumb -S -O tst.c" results in:
         .code   16
         .file   "tst.c"
         .section        .rodata
         .align  2
.LTRAMP0:
         .code 32
.Ltrampoline_start:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         ldr     r9, [pc, #8]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         ldr     ip, [pc, #8]
         orr     ip, ip, #1
         bx      ip
         .word   0
         .word   0
         .code 16
         .global __clear_cache
         .text
         .align  2
         .global f
         .code 16
         .thumb_func
         .type   f, %function
f:
         push    {r4, r5, lr}
         sub     sp, sp, #28
         ldr     r0, [sp, #44]
         str     r0, [sp]
         add     r4, sp, #4
         ldr     r3, .L3
         mov     r2, r4
         ldmia   r3!, {r0, r1, r5}
         stmia   r2!, {r0, r1, r5}
         ldmia   r3!, {r0, r1, r5}
         stmia   r2!, {r0, r1, r5}
         mov     r3, sp
         str     r3, [sp, #20]
         ldr     r3, .L3+4
         str     r3, [sp, #24]
         mov     r0, r4
         add     r1, sp, #28
         bl      __clear_cache
         mov     r0, r4
         bl      x
         add     sp, sp, #28
         @ sp needed for prologue
         pop     {r4, r5, pc}
.L4:
         .align  2
.L3:
         .word   .LTRAMP0
         .word   q.1472
         .size   f, .-f
         .align  2
         .code 16
         .thumb_func
         .type   q.1472, %function
q.1472:
         mov     r2, r9
         push    {r2, lr}
         mov     r3, r9
         ldr     r0, [r3]
         bl      a
         mov     r3, r0
         lsl     r0, r0, #3
         sub     r0, r0, r3
         lsl     r0, r0, #3
         sub     r0, r0, r3
         @ sp needed for prologue
         pop     {r2}
         mov     r9, r2
         pop     {pc}
         .size   q.1472, .-q.1472
         .ident  "GCC: (GNU) 4.2.3"


Notice the line marked with "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
r9 is unconditionally destroyed when the trampoline code is called.

Regards, Matthias


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
                   ` (3 preceding siblings ...)
  2009-03-17 16:48 ` leo at marco dot de
@ 2009-03-19 10:15 ` sam at gcc dot gnu dot org
  2009-03-19 19:08 ` leo at marco dot de
  5 siblings, 0 replies; 7+ messages in thread
From: sam at gcc dot gnu dot org @ 2009-03-19 10:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from sam at gcc dot gnu dot org  2009-03-19 10:15 -------
Matthias,

I think Laurent was asking for an executable test case, which fails before your
test and succeeds after, so that it can enter the regression suite.


-- 

sam at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

* [Bug target/32838] gcc generates incorrect trampoline code in thumb mode
  2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
                   ` (4 preceding siblings ...)
  2009-03-19 10:15 ` sam at gcc dot gnu dot org
@ 2009-03-19 19:08 ` leo at marco dot de
  5 siblings, 0 replies; 7+ messages in thread
From: leo at marco dot de @ 2009-03-19 19:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from leo at marco dot de  2009-03-19 19:08 -------
Subject: Re:  gcc generates incorrect trampoline code in
 thumb mode

sam at gcc dot gnu dot org wrote:
> ------- Comment #5 from sam at gcc dot gnu dot org  2009-03-19 10:15 -------
> Matthias,
>
> I think Laurent was asking for an executable test case, which fails before your
> test and succeeds after, so that it can enter the regression suite.
>
>
>   
We are using the compiler strictly for our embedded systems (software
running on the bare hardware). Sorry, I cannot provide you an
exececutable testcase.

Regards, Matthias


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32838


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

end of thread, other threads:[~2009-03-19 19:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-20 11:52 [Bug target/32838] New: gcc generates incorrect trampoline code in thumb mode leo at marco dot de
2007-07-20 11:53 ` [Bug target/32838] " leo at marco dot de
2007-07-20 11:55 ` leo at marco dot de
2009-01-02 12:31 ` laurent at guerby dot net
2009-03-17 16:48 ` leo at marco dot de
2009-03-19 10:15 ` sam at gcc dot gnu dot org
2009-03-19 19:08 ` leo at marco dot de

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).