Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] increase stack and malloc alignment to 16 bytes

13 views
Skip to first unread message

J.W. Jagersma (jwjagersma@gmail.com) [via djgpp@delorie.com]

unread,
Nov 25, 2021, 10:25:39 AM11/25/21
to dj...@delorie.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 /* Top of stack */
subl ___djgpp_stack_limit, %eax
--
2.33.0

J.W. Jagersma (jwjagersma@gmail.com) [via djgpp@delorie.com]

unread,
Jan 25, 2023, 4:48:56 PM1/25/23
to dj...@delorie.com
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.
0 new messages