emscripten-core / emscripten-core/emscripten
stack overflow when pass many args
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I compiled program using next command `emcc -sSTACK_OVERFLOW_CHECK=2 -sSAFE_HEAP=1 -sALLOW_MEMORY_GROWTH ./main.cxx`. When I try to launch program and pass many arguments I get stack overflow error. What do I do wrong? Because when I compiled program via usual tools like `clang, gcc, g++`. I don't get the stack overflow error.
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.33 (c1927f22708aa9a26a5956bab61de083e8d3e463)
clang version 17.0.0 (https://github.com/llvm/llvm-project 671eeece457f6a5da7489f7b48f7afae55327b8b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/peach/tools/emsdk/upstream/bin
```
**Failing command line in full:**
main.cxx
```cpp
#include
int main(int argc, char *argv[])
{
std::cout << "Count args: " << argc << std::endl;
std::cout << "Hello Wasm world!" << std::endl;
return 0;
}
```
run.sh
```sh
#! /bin/env sh
args="..."
node ./a.out.js ${args}
```
output
```
Aborted(stack overflow (Attempt to set SP to 0xffffffe0, with stack limits [0x00000000 - 0x00010000]). If you require more stack space build with -sSTACK_SIZE=)
/home/peach/Projects/wasm/a.out.js:79
throw ex;
^
RuntimeError: Aborted(stack overflow (Attempt to set SP to 0xffffffe0, with stack limits [0x00000000 - 0x00010000]). If you require more stack space build with -sSTACK_SIZE=)
at abort (/home/peach/Projects/wasm/a.out.js:670:10)
at ___handle_stack_overflow (/home/peach/Projects/wasm/a.out.js:1079:2)
at stackAlloc (:wasm-function[1641]:0x2990c)
at /home/peach/Projects/wasm/a.out.js:695:20
at allocateUTF8OnStack (/home/peach/Projects/wasm/a.out.js:4032:12)
at /home/peach/Projects/wasm/a.out.js:4309:35
at Array.forEach ()
at callMain (/home/peach/Projects/wasm/a.out.js:4308:7)
at doRun (/home/peach/Projects/wasm/a.out.js:4343:21)
at run (/home/peach/Projects/wasm/a.out.js:4355:3)
```
Contributor guide
Assessment
This issue has not been assessed yet.