emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.37k stars 3.25k forks source link

RuntimeError: memory access out of bounds #22041

Open ManishJu opened 1 month ago

ManishJu commented 1 month ago

I am trying to compile the raytracing in a weekend which is perfectly compiling in the Xcode Here is the link to the repo I am compiling , its a simple c++ raytracer : https://github.com/ManishJu/Raytracer_2ndWeek.git Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61-git clang version 19.0.0git

Failing command line in full:

emcc main.cpp -O3 -o 1.html  -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=10000000  && node --node-memory-debug  a.out.js

Here is the console log I am getting :


...../a.out.js:128
      throw ex;
      ^

RuntimeError: memory access out of bounds
    at wasm://wasm/001b0002:wasm-function[289]:0x37aab
    at wasm://wasm/001b0002:wasm-function[272]:0x35936
    at wasm://wasm/001b0002:wasm-function[123]:0xf9ec
    at wasm://wasm/001b0002:wasm-function[123]:0xfa5b
    at wasm://wasm/001b0002:wasm-function[123]:0xfa5b
    at wasm://wasm/001b0002:wasm-function[123]:0xfa5b
    at wasm://wasm/001b0002:wasm-function[123]:0xfa5b
    at wasm://wasm/001b0002:wasm-function[125]:0x10242
    at ..../a.out.js:641:12
    at callMain ..../a.out.js:4936:15)

Node.js v22.2.0

The issue is similar to issue #21848 . I tried using optimisation flag and increasing stack size but with no success

chopikus commented 1 month ago

Can confirm the same issue in my project https://github.com/chopikus/game-of-life

Seems that the changes in the version 3.1.60 broke something. 3.1.59 works for me just fine

sbc100 commented 1 month ago

Can you try building with -g (or --profiling-funcs) so that you get a more meaningful backtrace?

Can you also try building with -fsanitize=address and/or -sSAFE_HEAP?

Finally, if non of that helps, if would be great to track down exactly which emsdk change causes the regressions by bisecting: https://emscripten.org/docs/contributing/developers_guide.html?highlight=developer#bisecting

ManishJu commented 1 month ago

Can you try building with -g (or --profiling-funcs) so that you get a more meaningful backtrace?

Similar results

Can you also try building with -fsanitize=address and/or -sSAFE_HEAP?

Similar results with -fsanitize=address but on adding -sSAFE_HEAP I get this error :

emcc: error: ASan does not work with SAFE_HEAP

sbc100 commented 1 month ago

Can you try building with -g (or --profiling-funcs) so that you get a more meaningful backtrace?

Similar results

But you should see symbol names in the backtrace in this case no?

Can you also try building with -fsanitize=address and/or -sSAFE_HEAP?

Similar results with -fsanitize=address but on adding -sSAFE_HEAP I get this error :

emcc: error: ASan does not work with SAFE_HEAP

ManishJu commented 1 month ago

But you should see symbol names in the backtrace in this case no?

They were not there ...

sbc100 commented 4 weeks ago

But you should see symbol names in the backtrace in this case no?

They were not there ...

I think your first step then is to figure out why that is. Linking with --profiling-funcs should result in the final binary containing a name section which gives names to each function. Are you running any tools after emscripten that might be removing the name section? Can you inspect the resulting wasm file and check that it has a name section?