AlexAltea / unicorn.js

Unicorn CPU emulator framework port for JavaScript
https://alexaltea.github.io/unicorn.js/
GNU General Public License v2.0
566 stars 36 forks source link

script compile error #19

Closed netpipe closed 3 years ago

netpipe commented 4 years ago

./configure --cc="/run/media/netpipe/df7f53ef-2a98-4562-a498-7da578dab660/Dev/libs/Scripting/emsdk/upstream/emscripten/emcc" --extra-cflags="-DUNICORN_HAS_X86 -DUNICORN_HAS_ARM -DUNICORN_HAS_ARMEB -DUNICORN_HAS_M68K -DUNICORN_HAS_ARM64 -DUNICORN_HAS_ARM64EB -DUNICORN_HAS_MIPS -DUNICORN_HAS_MIPSEL -DUNICORN_HAS_MIPS64 -DUNICORN_HAS_MIPS64EL -DUNICORN_HAS_SPARC -fPIC -fvisibility=hidden" --target-list="x86_64-softmmu, arm-softmmu, armeb-softmmu, m68k-softmmu, aarch64-softmmu, aarch64eb-softmmu, mips-softmmu, mipsel-softmmu, mips64-softmmu, mips64el-softmmu, sparc-softmmu,sparc64-softmmu," --disable-debug-info --python=/usr/bin/python

ERROR: "/run/media/netpipe/df7f53ef-2a98-4562-a498-7da578dab660/Dev/libs/Scripting/emsdk/upstream/emscripten/emcc" either does not exist or does not work

have not tried moving the sdk around to /opt yet. emcc command works and the path is correct

AlexAltea commented 4 years ago

Whatever the error is, I don't think it's caused by Unicorn.js. Check your $PATH and $EMSCRIPTEN variables and make sure they are pointing to the proper location.

itszn commented 4 years ago

This seems to be an issue in the qemu config script. It tries to do things like do test programs and other checks which fail

KevOrr commented 4 years ago

I get the same issue, it happens when unicorn/qemu/configure is called. It's certainly finding LLVM and emscripten just fine. Here's unicorn/qemu/config.log. I believe it's when it tries to compile for wasm64 on line 432 or so.

smeng9 commented 3 years ago

My building environment is Ubuntu 20.04 64 bit, I assume you guys who initially raised the issue are also running 64 bit systems, and have Emscripten set up correctly.

@itszn @KevOrr I have checked the qemu configure script, it needs to be patched here https://github.com/unicorn-engine/unicorn/blob/5dbc640b9a2dae735fb663ede90f3900ad43f6d5/qemu/configure#L600 by changing -m64 to -m32 flag because Emscripten wasm is 32 bit only. Other wise the pthread check will fail. There will also be some pointer length check that fail.

We also need to patch the cflags by adding -fno-stack-protector and potentially remove stack-protector https://github.com/unicorn-engine/unicorn/blob/5dbc640b9a2dae735fb663ede90f3900ad43f6d5/qemu/configure#L716 here to disable the unresolved symbol __stack_chk_guard . It seems stack protector may become the default by main stream compilers but may still not get supported by emcc.

After these steps it will be able to generate object files. Then we probably need to set up a maximum memory limit, as pthread and memory growth support is very complicated. https://emscripten.org/docs/porting/pthreads.html#special-considerations Depending on Emscripten version you need to use WASM_MEM_MAX or MAXIMUM_MEMORY.

Now after all .o files are built I seems to stuck. Different versions of Emscripten have different behaviors on failing. I have tried following: 1.38.33+ shared:ERROR: Memory growth is not supported with pthreads without wasm 1.39+ shared:ERROR: If pthreads and memory growth are enabled, WASM_MEM_MAX must be set 2.0+ Fail at this line https://github.com/WebAssembly/binaryen/blob/c9f2e9b7b24182e830f39c176170d5ca64d3d05e/src/ir/block-utils.h#L56

If I wish to work out a patch of issue #20 #21 I have to un concatinate the files in dist folder, make changes and concatinate it back, which is very inconvenient for me. @AlexAltea When you have a chance could you take a look at the build issue?

smeng9 commented 3 years ago

Update: I resolved the issue and successfully compiled. Just Downgrade the Emsdk version and the compilation works for me No need to change any part of the configure file ./emsdk install sdk-fastcomp-1.37.23-64bit It indeed has to be > 1.37.9 but < 1.38. Old Emscripten package name follows a very different naming standard.

AlexAltea commented 3 years ago

@AlexAltea When you have a chance could you take a look at the build issue?

Unfortunately I have no time to port the current build scripts to the latest Emscripten SDK version. If pinning an old version gets Unicorn.js compiled, then that's good enough. Of course, pull requests are open if anyone feels like taking the effort. :-)

KevOrr commented 3 years ago

Wow, I'll have to try this out again later. I stalled my project at the time but now I'll have to pick things back up again!

smeng9 commented 3 years ago

Unfortunately I have no time to port the current build scripts to the latest Emscripten SDK version. If pinning an old version gets Unicorn.js compiled, then that's good enough. Of course, pull requests are open if anyone feels like taking the effort. :-)

Yes, pinning an old version of Emsdk works good for me. We can probably update the pinned versions in building section in readme.md to reflect compatibility. For new version of Emsdk, I am just posting here the changes to share my experience so someone can pick it up later.

AlexAltea commented 3 years ago

I've updated the README.md to clarify the required Emscripten SDK version. Thanks @smeng9 for the information!

smeng9 commented 3 years ago

@netpipe I have reproduced the exact same issue. For "emscripten either does not exist or does not work" issue, the real reason is in emsdk 1.39+ "uname -m" detected cpu architecture flag will cause emcc clang to fail.

If we add a flag --cpu=i386 to https://github.com/unicorn-engine/unicorn/blob/5dbc640b9a2dae735fb663ede90f3900ad43f6d5/Makefile#L215 that will bring the cflags from -m64 to -m32 which would resolve the issue.

I have added a patch that can resolve the compilation issue up to 1.39.15 1.38.48. Update: Compile is successful for 1.39.15, but fails at runtime for another reason Update2: Some additional issues are resolved #24 and emsdk version can be good till 1.40.1 2.0.3

AlexAltea commented 3 years ago

Closing this issue, since the original message was unrelated to Unicorn.js and the follow-ups have been solved by pinning the EMSDK version. Also, I'll update the README.md file to reflect that the pinned version should know be 1.38.48.

smeng9 commented 3 years ago

Hi @AlexAltea in README.md the supported emsdk version can be 2.0.7 now.

emsdk version below 1.39.16 will have runtime issue after merging #24 because emsdk introduced breaking change in 1.39.16 as the module is initialized as a promise rather than normal object after this version.

we can directly use $ ./emsdk install 2.0.7 to setup emsdk

Also the python2 can be deprecated after the patch in README.md

AlexAltea commented 3 years ago

Oh, good to know. Thanks @smeng9! I'll update the README.md again.