Skip to content

Ensure correct size_t mangling on Emscripten#1257

Closed
kleisauke wants to merge 1 commit intomicrosoft:dev3from
kleisauke:dev3-size_t-mangling-emscripten
Closed

Ensure correct size_t mangling on Emscripten#1257
kleisauke wants to merge 1 commit intomicrosoft:dev3from
kleisauke:dev3-size_t-mangling-emscripten

Conversation

@kleisauke
Copy link
Copy Markdown
Contributor

Emscripten defines size_t as unsigned long for both wasm32 and wasm64, mangling must therefore use m (Itanium ABI), independent of the pointer size.

Details
$ llvm-nm -pU --quiet $EMSDK/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++.a | grep -e _Zn
00000001 W _Znwm
0000004a W _ZnwmRKSt9nothrow_t
00000110 W _Znam
0000011b W _ZnamRKSt9nothrow_t
00000210 W _ZnwmSt11align_val_t
0000028c W _ZnwmSt11align_val_tRKSt9nothrow_t
0000033f W _ZnamSt11align_val_t
0000034c W _ZnamSt11align_val_tRKSt9nothrow_t
$ llvm-nm -pU --quiet $EMSDK/upstream/emscripten/cache/sysroot/lib/wasm64-emscripten/libc++.a | grep -e _Zn
00000001 W _Znwm
0000004d W _ZnwmRKSt9nothrow_t
0000013b W _Znam
00000146 W _ZnamRKSt9nothrow_t
00000263 W _ZnwmSt11align_val_t
000002e2 W _ZnwmSt11align_val_tRKSt9nothrow_t
000003bd W _ZnamSt11align_val_t
000003ca W _ZnamSt11align_val_tRKSt9nothrow_t
$ emcc -dM -E - < /dev/null | grep -e __SIZEOF_SIZE_T__ -e __SIZE_TYPE__
#define __SIZEOF_SIZE_T__ 4
#define __SIZE_TYPE__ long unsigned int
$ emcc -sMEMORY64 -dM -E - < /dev/null | grep -e __SIZEOF_SIZE_T__ -e __SIZE_TYPE__
#define __SIZEOF_SIZE_T__ 8
#define __SIZE_TYPE__ long unsigned int

See also: emscripten-core/emscripten#5916.

Emscripten defines `size_t` as `unsigned long` for both wasm32 and
wasm64, mangling must therefore use `m` (Itanium ABI), independent
of the pointer size.
daanx added a commit that referenced this pull request Apr 12, 2026
@daanx
Copy link
Copy Markdown
Collaborator

daanx commented Apr 12, 2026

Hallo, bedankt voor de PR :-) However, I think we can just add the condition (MI_INTPTR_SIZE==4 && defined(__EMSCRIPTEN__)) instead of doing the pre-processor magic? I pushed a potential fix -- let me know if it works for you. Thank you.

daanx added a commit that referenced this pull request Apr 12, 2026
@kleisauke
Copy link
Copy Markdown
Contributor Author

kleisauke commented Apr 13, 2026

Great, that works for me! 👍

I initially thought consolidating these pre-processor branches would would simplify things, especially since some toolchains (like llvm-mingw) require size_t to be mangled as y, but the pre-processor magic actually ends up making things more complex.

@kleisauke kleisauke closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants