rust-lang / rust-lang/rust

Function alignment does not work on wasm

Open
#143,368 22 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-align A-LLVM C-bug F-fn_align O-wasm T-compiler T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

For #[align], see the error here and the discussion here. I assume this also affects -Zmin-function-align.

In wasm, functions don't have an "address", it's not a von-Neumann architecture. Instead, there is a dedicated table and one can pick an integer index into the table when doing a dynamic call. So the actual address of a function cannot be observed and "aligning" it has no meaning. However, the fn ptr value can be observed by being cast to an integer, and then one will see the index into that table. One could attempt to align that but it seems not very useful...

Apart from the usefulness, I guess the question is what can we do?

  • Error when the attribute is used on wasm, since relying on fn ptr being divisible by N will just not work
  • Try to convince LLVM to implement this (is there an LLVM issue?)

Contributor guide

Open the contributing guide

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 the error in the linked rust-lang/rust#143313 discussion and the related discussion in rust-lang/rust#143206. Investigate how #[align] and -Zmin-function-align are handled for wasm; done means establishing and implementing a clear wasm-specific behavior, whether rejection or supported alignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers
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.