emscripten-core / emscripten-core/emscripten

RuntimeError: operation does not support unaligned accesses

Open
#14,439 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I'm trying to port an app to webasm. After slaying many dragons I finally got it to compile and run only to segfault almost immediately. With `-s SAFE_HEAP=1` I get:

```
segmentation fault
segmentation fault
/home/build/src/lyx.js:150
throw ex;
^

RuntimeError: abort(segmentation fault) at Error
at jsStackTrace (/home/build/src/lyx.js:2353:17)
at stackTrace (/home/build/src/lyx.js:2370:16)
at abort (/home/build/src/lyx.js:1783:44)
at segfault (/home/build/src/lyx.js:783:3)
at SAFE_HEAP_LOAD_i32_4_A (wasm-function[29585]:29)
at _GLOBAL__sub_I_Menus.cpp (wasm-function[10262]:79)
at __wasm_call_ctors (wasm-function[164]:2959)
at Module.___wasm_call_ctors (/home/build/src/lyx.js:11627:45)
at func (/home/build/src/lyx.js:1969:93)
at callRuntimeCallbacks (/home/build/src/lyx.js:1535:7)
at abort (/home/build/src/lyx.js:1789:9)
at segfault (/home/build/src/lyx.js:783:3)
at SAFE_HEAP_LOAD_i32_4_A (wasm-function[29585]:29)
at _GLOBAL__sub_I_Menus.cpp (wasm-function[10262]:79)
at __wasm_call_ctors (wasm-function[164]:2959)
at Module.___wasm_call_ctors (/home/build/src/lyx.js:11627:45)
at func (/home/build/src/lyx.js:1969:93)
at callRuntimeCallbacks (/home/build/src/lyx.js:1535:7)
at initRuntime (/home/build/src/lyx.js:1572:3)
at doRun (/home/build/src/lyx.js:12954:5)
```
The last recognizable/googleable thing I see is `_GLOBAL__sub_I_Menus.cpp` which brings me [here](https://github.com/cburschka/lyx/blob/master/src/frontends/qt/Menus.cpp#L2169) but more importantly [here](https://stackoverflow.com/a/66254512/9045206) which says it has something to do with `` being included. Not sure (I'm not a C++ dev).

I tried running with `-fsanitize=address` to find the problem but couldn't get it to work because I kept getting OOM no matter how I set `TOTAL_MEMORY`

```
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 60424192 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 55377920 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 52887552 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
Failed to grow the heap from 50331648 bytes to 52887552 bytes, not enough memory!
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 60424192 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 55377920 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
emscripten_realloc_buffer: Attempted to grow heap from 50331648 bytes to 52887552 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Unable to grow instance memory.
Failed to grow the heap from 50331648 bytes to 52887552 bytes, not enough memory!
==42==FATAL: AddressSanitizer: internal allocator is out of memory trying to allocate 0x17 bytes
```

So I'm stuck for how to debug. Note that I'm already compiling/linking with a slew of flags

```
-Wcast-align -Wover-aligned -s WARN_UNALIGNED=1 -s ASSERTIONS=1
```

which I got from [here](https://github.com/emscripten-core/emscripten/issues/10418) (which btw makes me suspect it has something to do with atomics since I am using `-pthread`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.