Skip to content

WasmFS: FS.readFile doesn't work with BigInt #17444

@kd935

Description

@kd935

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.17-git (529028e5b243d7fb5ce0cb7ac7fbd67ea27cbb17)
clang version 15.0.0 (https://github.com/llvm/llvm-project 7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: D:\emsdk\upstream\bin

Failing command line in full:

#include <stdio.h>
#include <emscripten/emscripten.h>

int main()
{
  EM_ASM({
    FS.writeFile("/read_file.txt", new Uint8Array([1, 2, 3]));
    console.log(FS.readFile("/read_file.txt")); // expected 123
  });
  return 0;
}

Full link command and output with -v appended:

D:\emscripten>em++ -v D:/build/test.cpp -o D:/build/test.html -s FORCE_FILESYSTEM=1 -s WASM_BIGINT=1 -sWASMFS=1
 "D:/emsdk/upstream/bin\clang++.exe" -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=17 -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=D:\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat -v D:/build/test.cpp -c -o C:\Users\kdots\AppData\Local\Temp\emscripten_temp_1dvjasn1\test_0.o
clang version 15.0.0 (https://github.com/llvm/llvm-project 7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: D:\emsdk\upstream\bin
 (in-process)
 "D:\\emsdk\\upstream\\bin\\clang++.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name test.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v "-fcoverage-compilation-dir=D:\\emscripten" -resource-dir "D:\\emsdk\\upstream\\lib\\clang\\15.0.0" -D EMSCRIPTEN -D __EMSCRIPTEN_major__=3 -D __EMSCRIPTEN_minor__=1 -D __EMSCRIPTEN_tiny__=17 -isysroot "D:\\emscripten\\cache\\sysroot" -internal-isystem "D:\\emscripten\\cache\\sysroot/include/wasm32-emscripten/c++/v1" -internal-isystem "D:\\emscripten\\cache\\sysroot/include/c++/v1" -internal-isystem "D:\\emsdk\\upstream\\lib\\clang\\15.0.0\\include" -internal-isystem "D:\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "D:\\emscripten\\cache\\sysroot/include" -Werror=implicit-function-declaration -fdeprecated-macro "-fdebug-compilation-dir=D:\\emscripten" -ferror-limit 19 -fmessage-length=166 -fvisibility default -fgnuc-version=4.2.1 -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -iwithsysroot/include/SDL "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\\Users\\kdots\\AppData\\Local\\Temp\\emscripten_temp_1dvjasn1\\test_0.o" -x c++ D:/build/test.cpp
clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "D:\emscripten\cache\sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "D:\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 D:\emscripten\cache\sysroot/include/SDL
 D:\emscripten\cache\sysroot/include\compat
 D:\emscripten\cache\sysroot/include/c++/v1
 D:\emsdk\upstream\lib\clang\15.0.0\include
 D:\emscripten\cache\sysroot/include
End of search list.
 "D:/emsdk/upstream/bin\wasm-ld.exe" -o D:/build/test.wasm C:\Users\kdots\AppData\Local\Temp\emscripten_temp_1dvjasn1\test_0.o -LD:\emscripten\cache\sysroot\lib\wasm32-emscripten --whole-archive -lwasmfs-debug --no-whole-archive -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=_wasmfs_read_file --export=_wasmfs_write_file --export=_wasmfs_mkdir --export=_wasmfs_chdir --export=_wasmfs_symlink --export=_wasmfs_chmod --export=_wasmfs_identify --export=_wasmfs_readdir_start --export=_wasmfs_readdir_get --export=_wasmfs_readdir_finish --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=malloc --export=free --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024
 "D:/emsdk/node/14.18.2_64bit/bin/node.exe" D:\emscripten\src\compiler.js C:\Users\kdots\AppData\Local\Temp\tmp39dx14kp.json
 "D:/emsdk/upstream/bin\llvm-objcopy.exe" D:/build/test.wasm D:/build/test.wasm --remove-section=.debug* --remove-section=producers
 "D:/emsdk/node/14.18.2_64bit/bin/node.exe" D:\emscripten\tools\preprocessor.js C:\Users\kdots\AppData\Local\Temp\emscripten_temp_1dvjasn1\settings.js shell.html

Output with WasmFS:

test.js:2092 Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
    at Object.readFile (test.js:2092:67)
    at 5524 (test.js:1147:91)
    at _emscripten_asm_const_int (test.js:1373:31)
    at main (test.cpp:6)
    at main (test.wasm:0x895)
    at test.js:959:22
    at callMain (test.js:2743:15)
    at doRun (test.js:2800:23)
    at test.js:2811:7

Expected output (when building without WasmFS):

123

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions