emscripten-core / emscripten-core/emscripten

Support for multivalue ABI?

Open
#27,418 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

There are no tests against the multivalue ABI, the sysroot does not build separately etc. Despite this, there seem to be quite few functions in libc and other system libraries whose ABI is different between multivalue and normal. Multivalue ABI can allow substantially simpler JS FFI in certain cases so it would be nice if it were a real thing with real support. Especially because it seems to work in surprisingly many cases in practice.

If it is not intended to work, it might be nice to get an actual link error rather than just doing something completely weird. Surprisingly, I have no example of a program that links and then behaves incorrectly (though I could probably get one from Claude quite easily). The closest is the example I have included below, which prints a warning at link time but actually works correctly at runtime for some reason.

Now that wasm-bindgen has migrated off of it perhaps nobody intends to support the multivalue abi in llvm but it's a bit of a shame because it seems clearly useful.

If Emscripten does want to support it, one problem seems to be that object files do not record what ABI they were linked with. We would either need to fix that or pass `-sMULTIVALUE` to both compiler and linker.

#### Example:

```C
#include "math.h"

int
f(float x) {
if (isfinite(x)) {
return 1;
}
return 0;
}

int main() {
return f(0.0);
}
```

```C
$ emcc a.c -mmultivalue -Xclang -target-abi -Xclang experimental-mv
wasm-ld: warning: function signature mismatch: __extendsftf2
>>> defined as (f32) -> i64 in /tmp/emscripten_temp_3smyz6xa/a.o
>>> defined as (i32, f32) -> void in /home/hood/Documents/programming/pyodide/emsdk/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a(extendsftf2.o)
```

**Version of emscripten/emsdk:**
I checked that it reproduces on Emscripten 3.1.58, 5.0.3, and 6.0.3

####

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided emcc command with -mmultivalue and the experimental-mv target ABI, then inspect the sysroot and libcompiler_rt.a interaction reported by wasm-ld. Determine whether multivalue and normal ABI objects can be distinguished or consistently passed through compilation and linking; done should include coverage for the ABI behavior or a reliable link error when it is unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, wasm
Domain
build-system, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.