www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8658] New: Passing large structs to function b value causes stack corruption

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8658

           Summary: Passing large structs to function b value causes stack
                    corruption
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: r.sagitario gmx.de



PDT ---
If the arguments passed to a function exceed 64kB the stack gets corrupted.
Compiling and running this code without optimizations leads to a crash:

struct S
{
    int[16385] a;
}

void foo(S s)
{
}

void main()
{
    S s;
    for(int i = 0; i < 100; i++)
        foo(s);
}

This is caused by the frame pointer cleanup only popping the lower 16 bit of
the used stack size:

_D4test3fooFS4test1SZv  comdat
        assume  CS:_D4test3fooFS4test1SZv
                ret     4
_D4test3fooFS4test1SZv  ends

[Actually I never meant to do this, it happened because I thought I was passing
a class reference.]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 14 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8658


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---

 If the arguments passed to a function exceed 64kB the stack gets corrupted.
 Compiling and running this code without optimizations leads to a crash:
 
<snip> Couple of comments: 1) This program doesn't crash in x64 linux 2) what exactly is requested: you allocate data on stack which certainly big enough to corrupt it, so? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 14 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8658


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|All                         |x86
         OS/Version|All                         |Windows



PDT ---
Sorry, I didn't specify the platform: Windows 32-bit. I don't know if it
happens elsewhere. 
What happens in the example is that each call pushes 16385 words onto the
stack, but only 1 gets popped. 
For x64, the code might be different and the stack might be larger.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 14 2012