CEmu icon indicating copy to clipboard operation
CEmu copied to clipboard

Compiling to WebAssembly

Open Vishram1123 opened this issue 1 year ago • 8 comments

(Thanks for reporting an issue! Please make sure to fill out the blanks below.)

What's wrong, and with what software version?


  • Operating System: MacOS Ventura (Also tried in Fedora 36)
  • CEmu version: Commit d606eb3982442a8df0d044b453cf5fc195c6f45d
  • Describe your issue: When attempting to compile to WebAssembly (using emmake make -f emscripten.mk and make -f emscripten.mk), the compilation fails, as symbols are not found by wasm-ld. This is done by just recursively cloning the repo (git clone --recursive https://github.com/CE-Programming/CEmu), going to the core directory (cd CEmu/core) and compiling (with above command)

What are the steps to reproduce this issue?


  1. git clone --recursive https://github.com/CE-Programming/CEmu
  2. cd CEmu/core
  3. emmake make -f emscripten.mk or make -f emscripten.mk

Any logs, error output, screenshot, other comments...?


(Same in both cases):

Error log from make command
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 asic.c -o asic.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 backlight.c -o backlight.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 bus.c -o bus.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 cert.c -o cert.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 control.c -o control.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 cpu.c -o cpu.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
emcc -W -Wall -O3 -DDEBUG_SUPPORT -s TOTAL_MEMORY=33554432 --llvm-lto 3 -s INVOKE_RUN=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=0 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'ccall', 'cwrap']" --closure 0 -s WASM=0 emu.c -o emu.bc
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
emcc: warning: object file output extension (.bc) used for non-object output.  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
wasm-ld: error: /var/folders/5h/z9gzm9hj5kvdxr9bqtrqx95r0000gn/T/emscripten_temp__sygnx5u/emu_0.o: undefined symbol: cpu
emcc: error: '/opt/homebrew/Cellar/emscripten/3.1.20/libexec/llvm/bin/wasm-ld -o emu.wasm /var/folders/5h/z9gzm9hj5kvdxr9bqtrqx95r0000gn/T/emscripten_temp__sygnx5u/emu_0.o -L/opt/homebrew/Cellar/emscripten/3.1.20/libexec/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=getTempRet0 --export=setTempRet0 --export=__get_temp_ret --export=__set_temp_ret --export-table -z stack-size=5242880 --initial-memory=33554432 --no-entry --max-memory=33554432 --global-base=1024' failed (returned 1)
make: *** [emu.bc] Error 1

Vishram1123 avatar Oct 02 '22 14:10 Vishram1123

Oh, also to note, the regular build with just make works; I am able to build the core.

Vishram1123 avatar Oct 02 '22 15:10 Vishram1123

I'm not able to repro with the latest commit on master (as of this comment) and emscripten (after an update, it shows emcc (Emscripten gcc/clang-like replacement) 1.39.8 (commit 1458145cf4f3db0fb548343e6acab267eef8e4ef).

No error here, it builds cemu_web.js and cemu_web.js.mem just fine, hmmm

adriweb avatar Oct 02 '22 23:10 adriweb

ok for some reason, I guess my emscripten is the latest of... an old branch. I'll update to the actual-latest one in a bit.

adriweb avatar Oct 02 '22 23:10 adriweb

Alright, I updated to emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.24-git (f6c46570e3780e52050bf822a07b342ec4bdddbe) and I'm still not getting errors (a buunch of warnings because some things are obsolete/deprecated, but...)

adriweb avatar Oct 02 '22 23:10 adriweb

Ok, I will try that. I installed the brew version of emscripten on my Mac and compiled from source (installing latest) on Fedora

Vishram1123 avatar Oct 03 '22 00:10 Vishram1123

I am on the same version of Emscripten as you are (3.1.24-git (f6c46570e3780e52050bf822a07b342ec4bdddbe)), but I am still getting the error wasm-ld: error: /tmp/emscripten_temp_k39cf52w/emu_0.o: undefined symbol: cpu. Am I running the right command (make -f emscripten.mk)?

Vishram1123 avatar Oct 03 '22 01:10 Vishram1123

Yep, and I'm also running it on macOS... this is weird.

adriweb avatar Oct 03 '22 06:10 adriweb

Oh I did it on Fedora, I'll try on my mac

Vishram1123 avatar Oct 03 '22 13:10 Vishram1123