Jump to page: 1 2 3
Thread overview
[Issue 16098] align(N) not respected for stack variables if N > platform stack alignment
[Issue 16098] align(32) not respected for stack variables
May 30, 2016
Ketmar Dark
Nov 21, 2016
Walter Bright
Jan 30, 2019
Vladimir Panteleev
Jan 30, 2019
Vladimir Panteleev
Apr 30, 2021
Imperatorn
Aug 07, 2021
kinke
Jun 20, 2022
kinke
Jun 20, 2022
kinke
Jun 20, 2022
kinke
Dec 23, 2022
Walter Bright
Dec 23, 2022
Dennis
Dec 23, 2022
Walter Bright
Dec 26, 2022
Dlang Bot
Dec 26, 2022
Walter Bright
Dec 26, 2022
Dennis
Dec 30, 2022
Walter Bright
Dec 30, 2022
Vladimir Panteleev
Dec 31, 2022
Dlang Bot
Dec 31, 2022
Dlang Bot
Jan 02, 2023
Walter Bright
Feb 25, 2023
Dlang Bot
May 30, 2016
https://issues.dlang.org/show_bug.cgi?id=16098

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--- Comment #1 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
afair, *any* `align` is simply ignored for stack vars in DMD.

--
November 21, 2016
https://issues.dlang.org/show_bug.cgi?id=16098

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to Ketmar Dark from comment #1)
> afair, *any* `align` is simply ignored for stack vars in DMD.

No, this is not true, if the align <= the stack alignment.

--
January 30, 2019
https://issues.dlang.org/show_bug.cgi?id=16098

--- Comment #3 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
Well, this is annoying.

Broken code:

    align(16) uint[128] state;
    asm { fxsave state; }

"Fixed" code:

    uint[128 + 4] buf;
    auto state = cast(uint*)((cast(size_t)buf.ptr + 0xF) & ~size_t(0xF));
    version (X86_64)
        asm { mov RAX, state; fxsave 0[RAX]; }
    else
        asm { mov EAX, state; fxsave 0[EAX]; }

--
January 30, 2019
https://issues.dlang.org/show_bug.cgi?id=16098

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang-bugzilla@thecybershad
                   |                            |ow.net

--
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=16098

Imperatorn <johan_forsberg_86@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johan_forsberg_86@hotmail.c
                   |                            |om

--- Comment #4 from Imperatorn <johan_forsberg_86@hotmail.com> ---
Can we fix this?

--
August 07, 2021
https://issues.dlang.org/show_bug.cgi?id=16098

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|C++                         |backend
                 CC|                            |kinke@gmx.net

--
June 20, 2022
https://issues.dlang.org/show_bug.cgi?id=16098

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|align(32) not respected for |align(N) not respected for
                   |stack variables             |stack variables if N >
                   |                            |platform stack alignment

--
June 20, 2022
https://issues.dlang.org/show_bug.cgi?id=16098

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
                 OS|Linux                       |All
           Severity|normal                      |blocker

--
June 20, 2022
https://issues.dlang.org/show_bug.cgi?id=16098

--- Comment #5 from kinke <kinke@gmx.net> ---
This issue blocks https://github.com/dlang/phobos/pull/8460. On Win32 with its 4-bytes stack alignment, the following assertion fails most of the time:

void main() {
    byte a;
    align(8) byte b;
    assert((cast(size_t) &b) % 8 == 0);
}

--
December 23, 2022
https://issues.dlang.org/show_bug.cgi?id=16098

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---
One way to fix this is to:

1. gather all the locals with larger alignment and put them as fields in a struct variable

2. the first field in the struct is enough alignment padding to cover the worst case alignment bytes needed. For example, if the stack is aligned at 4, and the alignment of the fields is 16, then this field needs to be 12 bytes in size.

3. create a special pointer variable P that points to the aligned start of the struct fields, computed at function entry:

    P = (&struct + 15) & ~0xF;  // for 16 byte alignment

4. rewrite all references to the variables in the struct as P->field

5. be careful that it works with closures allocated with the gc

This should be doable all in the glue code, no need to modify the backend.

Of course, this can be done explicitly for the moment, to unblock code.

--
« First   ‹ Prev
1 2 3