Thread overview
[Issue 21097] [REG2.083] Stack exhaustion upon large struct .destroy
May 10, 2021
Dlang Bot
May 10, 2021
Dlang Bot
May 18, 2021
Dlang Bot
May 28, 2021
Dlang Bot
July 30, 2020
https://issues.dlang.org/show_bug.cgi?id=21097

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
July 30, 2020
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #1 from johanengelen@weka.io ---
Note: the 10MB symbol may lead one to believe that this is only a problem in rare cases. It isn't. At Weka, this bug is triggered with a dynamically allocated 300kb struct. Fibers do not have very large stacks.

--
July 31, 2020
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #2 from johanengelen@weka.io ---
Two potential solutions:
```
// Avoid stack allocation, at the cost of virtual call to get the init symbol.
{
    auto arr = cast(ubyte[])typeid(T).initializer();
    if (arr.ptr is null) {
        (cast(ubyte*)val)[0 .. T.sizeof] = ubyte(0);
    } else {
        // Use fill to duplicate 'arr' to work around
https://issues.dlang.org/show_bug.cgi?id=16394
        (cast(ubyte*)val)[0 .. T.sizeof].fillbytes(arr);
    }
}

// Avoid stack allocation, at the cost of duplicating the init symbol (binary
size increase)
{
    import core.stdc.string : memcpy;
    shared static immutable T init = T.init;
    memcpy(&chunk, &init, T.sizeof);
}
```

(one cannot access the init symbol directly)

--
May 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21097

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@JohanEngelen created dlang/druntime pull request #3467 "Fix Issue 21097 - prevent stack allocation when destroying large aggregates" fixing this issue:

- Fix Issue 21097 - Fix destroy and core.internal.lifetime.emplaceInitializer for large aggregates by preventing stack allocation

https://github.com/dlang/druntime/pull/3467

--
May 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@JohanEngelen created dlang/dmd pull request #12509 "Add tests for the druntime fix for destroy on large aggregates (issue 21097)" mentioning this issue:

- Add tests for the druntime fix for destroy on large aggregates (issue 21097)

https://github.com/dlang/dmd/pull/12509

--
May 18, 2021
https://issues.dlang.org/show_bug.cgi?id=21097

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #3467 "Fix Issue 21097 - prevent stack allocation when destroying large aggregates" was merged into stable:

- 5981d49df518185725328538ab7b7b13879520e7 by Johan Engelen:
  Fix Issue 21097 - Fix destroy and core.internal.lifetime.emplaceInitializer
for large aggregates by preventing stack allocation

https://github.com/dlang/druntime/pull/3467

--
May 28, 2021
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #3482 "merge stable" was merged into master:

- 706815547a6d7219dc39ef2f392c6139b6e943db by Johan Engelen:
  Fix Issue 21097 - Fix destroy and core.internal.lifetime.emplaceInitializer
for large aggregates by preventing stack allocation

https://github.com/dlang/druntime/pull/3482

--