Version Information

[EMAIL PROTECTED] ~]$ 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
[EMAIL PROTECTED] ~]$


Reproduction Steps

[EMAIL PROTECTED] ~]$ arm-elf-gcc -Os -save-temps -c -S sample.c
[EMAIL PROTECTED] ~]$

[ 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

Reply via email to