public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/55940] New: Incorrect code for accessing parameters with 32-bit Intel hosts
@ 2013-01-11 11:17 fm3 at os dot inf.tu-dresden.de
  2013-01-11 11:23 ` [Bug target/55940] " rguenth at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: fm3 at os dot inf.tu-dresden.de @ 2013-01-11 11:17 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55940
           Summary: Incorrect code for accessing parameters with 32-bit
                    Intel hosts
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fm3@os.inf.tu-dresden.de


There are some reports about incorrect compiled Linux kernel modules for
VirtualBox. I've debugged one report (see here:
https://www.virtualbox.org/ticket/11035) and saw that the compiler generated
invalid code for accessing parameters inside a function. When it should read
the parameter from the stack it reads the parameter from a register.

I don't know exactly under which circumstance this happens but this seems to be
related to 32-bit x86 targets. The function VBoxHost_RTR0MemObjGetPagePhysAddr
is marked as __attribute__((cdelc, regparm(0))). The pre-processed
memobj-r0drv.i file is attached to that ticket. The generated code is part of
the vboxdrv.ko file which is also attached to the ticket.

The following code is generated to access the first function parameter (keep
cdecl in mind!):

VBoxHost_RTR0MemObjGetPagePhysAddr():
/usr/src/virtualbox-bin-4.2.4_81684/vboxhost/vboxdrv/r0drv/memobj-r0drv.c:268
    955e:       8b 0f                   mov    (%edi),%ecx
    9560:       8b 47 04                mov    0x4(%edi),%eax
/usr/src/virtualbox-bin-4.2.4_81684/vboxhost/vboxdrv/r0drv/memobj-r0drv.c:272
    9563:       8d 91 00 10 00 00       lea    0x1000(%ecx),%edx

So the function is using the EDI register to access the parameter while it
should read the parameter from the stack.

The C code of this function looks (see memobj-r0drv.i) is:

RTHCPHYS __attribute__((cdecl,regparm(0)))
VBoxHost_RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage)
{

    PRTR0MEMOBJINTERNAL pMem;
    size_t cPages;
    do { if (__builtin_expect(!!(!(( (uintptr_t)(MemObj) + 0x1000U >= 0x2000U
))), 0)) return ((~(RTHCPHYS)0)); } while (0);
    ...

(Explanation of the code: This is actually a sanity check if the pointer is
valid; the value must be either less than 0xFFFFF000U or greater than
0x00000FFFU).

Unfortunately I cannot reproduce this problem myself (gcc 4.7.2 on my Linux
distribution creates correct code). The gcc compiler the user is using is

gcc version 4.7.2 (Exherbo gcc-4.7.2-r2)

(see comment 18 in the above ticket).


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

end of thread, other threads:[~2013-02-01 14:31 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-11 11:17 [Bug target/55940] New: Incorrect code for accessing parameters with 32-bit Intel hosts fm3 at os dot inf.tu-dresden.de
2013-01-11 11:23 ` [Bug target/55940] " rguenth at gcc dot gnu.org
2013-01-11 11:27 ` rguenth at gcc dot gnu.org
2013-01-11 11:36 ` rguenth at gcc dot gnu.org
2013-01-15 13:53 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 15:04 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 15:22 ` jakub at gcc dot gnu.org
2013-01-15 15:38 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 16:55 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 16:56 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 16:58 ` fm3 at os dot inf.tu-dresden.de
2013-01-15 17:46 ` [Bug target/55940] [4.7/4.8 Regression] " jakub at gcc dot gnu.org
2013-01-15 18:29 ` jakub at gcc dot gnu.org
2013-01-15 22:59 ` jakub at gcc dot gnu.org
2013-01-16  8:00 ` [Bug target/55940] [4.7 " jakub at gcc dot gnu.org
2013-01-16  9:01 ` fm3 at os dot inf.tu-dresden.de
2013-01-16  9:16 ` jakub at gcc dot gnu.org
2013-02-01 14:10 ` jakub at gcc dot gnu.org
2013-02-01 14:31 ` jakub at gcc dot gnu.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).