• [PATCH] increase stack and malloc alignment to 16 bytes

    From [via djgpp@delorie.com]" @21:1/5 to All on Thu Nov 25 16:13:24 2021
    Copy: jwjagersma@gmail.com (J.W. Jagersma)

    The section alignment patch I posted here earlier has been accepted in binutils,
    so that will be available in the next release.

    Now in libc only these two lines need to be adjusted, and then all code, data, stack and heap will be aligned to 16 byte boundaries.

    Should be good for SSE, hopefully it will help resolve the gcc 11 Ada issue too.

    ---
    src/libc/ansi/stdlib/nmalcdef.h | 2 +-
    src/libc/crt0/crt0.S | 2 +-
    2 files changed, 2 insertions(+), 2 deletions(-)

    diff --git a/src/libc/ansi/stdlib/nmalcdef.h b/src/libc/ansi/stdlib/nmalcdef.h index cb41f619..495c63a6 100644
    --- a/src/libc/ansi/stdlib/nmalcdef.h
    +++ b/src/libc/ansi/stdlib/nmalcdef.h
    @@ -188,7 +188,7 @@ typedef struct memblock {
    /* conversion and access macros */
    #define MEMBLKp(p) (memblockp)((byte*)(p) - DATAOFFSET)
    #define PTR(m) (void*)((byte*)(m) + DATAOFFSET)
    -#define ALIGN 8
    +#define ALIGN 16

    #define ALIGNMASK (ALIGN-1)

    diff --git a/src/libc/crt0/crt0.S b/src/libc/crt0/crt0.S
    index 446a989b..226f0cb9 100644
    --- a/src/libc/crt0/crt0.S
    +++ b/src/libc/crt0/crt0.S
    @@ -315,7 +315,7 @@ use_stubinfo_stack_size:
    addl __stklen, %eax
    movw %ds, %dx /* set stack */
    movw %dx, %ss
    - andb $0xf8, %al /* align to 8-byte boundary */
    + andb $0xf0, %al /* align to 16-byte boundary */
    movl %eax, %esp
    movl %eax, ___djgpp_stack_top /* To
  • From [via djgpp@delorie.com]" @21:1/5 to J.W. Jagersma on Wed Jan 25 22:45:24 2023
    Pinging another patch that I think is important, particularly for -msse users.

    Note that gcc / libstdc++ also expect 16-byte alignment, as evidenced by alignof(std::max_align_t) == 16, the macro __STDCPP_DEFAULT_NEW_ALIGNMENT__ (defined to 16), and the fact that it always bumps the stack pointer by multiples of 16.


    On 2021-11-25 16:13, J.W. Jagersma wrote:
    The section alignment patch I posted here earlier has been accepted in binutils,
    so that will be available in the next release.

    Now in libc only these two lines need to be adjusted, and then all code, data,
    stack and heap will be aligned to 16 byte boundaries.

    Should be good for SSE, hopefully it will help resolve the gcc 11 Ada issue too.

    ---
    src/libc/ansi/stdlib/nmalcdef.h | 2 +-
    src/libc/crt0/crt0.S | 2 +-
    2 files changed, 2 insertions(+), 2 deletions(-)

    diff --git a/src/libc/ansi/stdlib/nmalcdef.h b/src/libc/ansi/stdlib/nmalcdef.h
    index cb41f619..495c63a6 100644
    --- a/src/libc/ansi/stdlib/nmalcdef.h
    +++ b/src/libc/ansi/stdlib/nmalcdef.h
    @@ -188,7 +188,7 @@ typedef struct memblock {
    /* conversion and access macros */
    #define MEMBLKp(p) (memblockp)((byte*)(p) - DATAOFFSET)
    #define PTR(m) (void*)((byte*)(m) + DATAOFFSET)
    -#define ALIGN 8
    +#define ALIGN 16

    #define ALIGNMASK (ALIGN-1)

    diff --git a/src/libc/crt0/crt0.S b/src/libc/crt0/crt0.S
    index 446a989b..226f0cb9 100644
    --- a/src/libc/crt0/crt0.S
    +++ b/src/libc/crt0/crt0.S
    @@ -315,7 +315,7 @@ use_stubinfo_stack_size:
    addl __stklen, %eax
    movw %ds, %dx /* set stack */
    movw %dx, %ss
    - andb $0xf8, %al /* align to 8-byte boundary */
    + andb $0xf0, %al /* align to 16-byte boundary */
    movl %eax, %esp
    movl %eax, ___djgpp_stack_top /* Top of stack */
    subl ___djgpp_stack_limit, %eax

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)