wasi-libc
wasi-libc copied to clipboard
Alignment used by dlmalloc is not correct (AFAICT)
Today dlmalloc has hardcoded MALLOC_ALIGNMENT
of 2*pointer size:
https://github.com/WebAssembly/wasi-libc/blob/3c4a3f94d1ce685a672ec9a642f1ae42dae16eb1/dlmalloc/src/malloc.c#L628
Emscripten has had the same issue basically forever, but its not standards compliant and is causing issues for some codebases that assume malloc returns things that are aligned to alignof(max_align_t)
. See https://github.com/emscripten-core/emscripten/issues/10072.
We've discussed several ways to address this, the most obvious being to increase the alignment used by dlmalloc to 16 bytes. However, we are also looking and reducing the alignment of max_align_t instead: https://reviews.llvm.org/D104808 The rational being that increasing malloc alignment does have some size and performance costs associated with it. Also, dlmalloc seems to be tuned for 8 bytes allignment:
https://github.com/WebAssembly/wasi-libc/blob/3c4a3f94d1ce685a672ec9a642f1ae42dae16eb1/dlmalloc/src/malloc.c#L252-L253
So, the choices seem like:
- Leave everything as is and accept non-conforming malloc.
- Increase alignment used by dlmalloc.
- Decrease the alignment of long double.