WebAssembly / WebAssembly/wasi-libc

Alignment used by dlmalloc is not correct (AFAICT)

Open
#249 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1k
Forks
251
Avg merge
7h 15m
Merged PRs (30d)
3

Description

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:

  1. Leave everything as is and accept non-conforming malloc.
  2. Increase alignment used by dlmalloc.
  3. Decrease the alignment of long double.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading dlmalloc/src/malloc.c at the cited MALLOC_ALIGNMENT and 8-byte tuning lines. Review the linked Emscripten issue and LLVM review to understand the three proposed choices and their standards implications. The work is done when one approach is selected and the malloc alignment behavior is made conforming.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, wasm
Domain
operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.