public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/30579]  New: Clobbered hard register is not restored before subsequent use
@ 2007-01-24 21:58 dpm at danger dot com
  2007-01-24 21:59 ` [Bug inline-asm/30579] " dpm at danger dot com
  2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: dpm at danger dot com @ 2007-01-24 21:58 UTC (permalink / raw)
  To: gcc-bugs

Version Information

[dpm@spenseweed ~]$ arm-elf-gcc -v
Using built-in specs.
Target: arm-elf
Configured with: ../gcc-4.1.1/configure
--prefix=/usr/local/armdev-926ej-s-4.1.1 --target=arm-elf --enable-languages=c
--with-float=soft --enable-interwork --enable-multilib --with-cpu=arm926ej-s
--disable-threads --with-dwarf2 --without-headers
Thread model: single
gcc version 4.1.1
[dpm@spenseweed ~]$


Reproduction Steps

[dpm@spenseweed ~]$ arm-elf-gcc -Os -save-temps -c -S sample.c
[dpm@spenseweed ~]$

[ sample.i attached to this bug report ]


Analysis of the bug

The bug appears in the generated assembly of the function gc_lock_held(int).
The function gc_memmove_down(void *, const void *, size_t) is inlined into this
function during compilation. That function includes the following inline
assembly statement:

        asm("0:\t"
            "ldmia %[src]!, { r4 - r11 }\n\t"
            "stmia %[dest]!, { r4 - r11 }\n\t"
            "sub %[count], %[count], #32\n\t"
            "cmp %[count], #32\n\t"
            "bhs 0b\n\t"
            : [src] "+r" (src), [dest] "+r" (dest), [count] "+r" (count)
            :
            : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "cc",
"memory");

The statement lists several clobbered hard registers, as described in this part
of the GCC manual:
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Extended-Asm.html#Extended-Asm. In
particular, "r11" is one of the clobbered hard registers. In the ARM
architecture, "r11" is a synonym for "fp". This inline assembly statement is
exported into the generated .s file on line 215.

The bug appears on line 241, where we see the following instruction:

    str r3, [fp, #0]

A quick hand simulation of the generated assembly code shows that we can reach
this statement without reloading a valid value into fp. Thus, fp is
dereferenced despite having been clobbered by the inline assembly statement.
Because "r11" was listed as a clobbered hard register, gcc should have restored
the value of this register before using it.

Replacing "r11" with "fp" in the clobbered hard register list does not change
the generated code.


-- 
           Summary: Clobbered hard register is not restored before
                    subsequent use
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dpm at danger dot com


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


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

* [Bug inline-asm/30579] Clobbered hard register is not restored before subsequent use
  2007-01-24 21:58 [Bug inline-asm/30579] New: Clobbered hard register is not restored before subsequent use dpm at danger dot com
@ 2007-01-24 21:59 ` dpm at danger dot com
  2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: dpm at danger dot com @ 2007-01-24 21:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from dpm at danger dot com  2007-01-24 21:59 -------
Created an attachment (id=12951)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12951&action=view)
Reproducible test case


-- 


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


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

* [Bug inline-asm/30579] Clobbered hard register is not restored before subsequent use
  2007-01-24 21:58 [Bug inline-asm/30579] New: Clobbered hard register is not restored before subsequent use dpm at danger dot com
  2007-01-24 21:59 ` [Bug inline-asm/30579] " dpm at danger dot com
@ 2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-25  1:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-01-25 01:02 -------
frame pointer should not be in the clobber list.

*** This bug has been marked as a duplicate of 11807 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2007-01-25  1:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-24 21:58 [Bug inline-asm/30579] New: Clobbered hard register is not restored before subsequent use dpm at danger dot com
2007-01-24 21:59 ` [Bug inline-asm/30579] " dpm at danger dot com
2007-01-25  1:02 ` pinskia at gcc dot gnu dot org

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