Open yosmo78 opened 1 year ago
The problem is likely the standard library (and thus wprintf
, etc) is not compiled with -fshort-wchar
.. which means its still expecting wide wchars.
I think if you want to make -fshort-wchar
work you would also need to rebuild any system libraries that deal with wchar.
Indeed it seems this is true of -fshort-wchar
in general, not specific to emscripten: https://stackoverflow.com/a/15287634/2770641
@sbc100 is there any resources you know of for recompiling the emscripten standard library?
Its not something that is easy to do I'm afraid. Can you explain why you want to go to all the effort?
If you do want to go to all the effort your best bet is probably to modify emcc.py
such that -fshort-wchar
is one of the default compile flags (see get_cflags
in emcc.py
) then run emcc --clear-cache
to remove all the existing libraries.. then just rebuild your program and emscripten should automatically rebuild all the system libraries.
@sbc100 the goal was to be compatible with windows wchar_t (as that is what we are porting lots of stuff from, i.e. a massive amount of code and data (mainly the data is the important bit and the interaction between our wasm system and our native windows code)). So that was the primary motivation for making it unified with our preexisting codebase.
OK, let me know of patching -fshort-wchar
into get_cflags
works for you?
Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.30 (cfe2bdfe2692457cb5f5770672f6e5ccb3ffc2f2) clang version 16.0.0 (https://github.com/llvm/llvm-project 800f0f1546b2352ba42a4777149afb13cb874fcd) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: C:\emsdk\upstream\bin
Failing command line in full:
em++ main.cpp -std=c++20 -fshort-wchar -sWASM=1 -g3 -pthread -s PTHREAD_POOL_SIZE=1 -sALLOW_BLOCKING_ON_MAIN_THREAD -s LLD_REPORT_UNDEFINED -s SAFE_HEAP=1 -o index.js
Here is an extremely minimal version of the code. This contains the error in it:
Basically the error I am running into is that the compiler is placing these 2 byte wchar literals at unaligned memory locations. So you cannot read from them properly without crashing from alignment faults.
For completeness here is a
index.html
A quick and dirty server
server.js
and a command to run the server
node server.js
and then connect tohttp://127.0.0.1:8080/index.html
in the browser