emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

RuntimeError: memory access out of bounds

Open ManishJu opened this issue 1 year ago • 7 comments

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

ManishJu avatar Jun 02 '24 11:06 ManishJu

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

chopikus avatar Jun 02 '24 22:06 chopikus

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

sbc100 avatar Jun 03 '24 17:06 sbc100

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

ManishJu avatar Jun 04 '24 16:06 ManishJu

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

sbc100 avatar Jun 04 '24 16:06 sbc100

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

They were not there ...

ManishJu avatar Jun 05 '24 08:06 ManishJu

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?

sbc100 avatar Jun 05 '24 13:06 sbc100

@ManishJu I tried compiling your program and it didnt crash 0_o

I did this command

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

I spent a few hours making a small example that would trigger the bug and failed 🙃

chopikus avatar Jul 12 '24 21:07 chopikus