emscripten-core / emscripten-core/emscripten

--shared-memory is disallowed when using -sSHARED_MEMORY=1 compiling C++ code

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

Description

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.13 (531257621816c200bc7c3be53129494afd029aec)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5c6ed60c517c47b25b6b25d8ac3666d0e746b0c3)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\toyobayashi\Projects\emsdk\upstream\bin
```

**Failing command line in full:**
```
C:\Users\toyobayashi\Projects\emxx-shared-memory-repro>em++ -sSHARED_MEMORY=1 -sALLOW_MEMORY_GROWTH=1 --js-library=library_napi.js -o out/myobject.js emnapi.c myobject.cc main.cc
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
wasm-ld: error: --shared-memory is disallowed by cxa_default_handlers.o because it was not compiled with 'atomics' or 'bulk-memory' features.
em++: error: 'C:/Users/toyobayashi/Projects/emsdk/upstream/bin\wasm-ld.exe -o out/myobject.wasm C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_8n173m2y\emnapi_0.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_8n173m2y\myobject_1.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_8n173m2y\main_2.o -LC:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024' failed (returned 1)
```

**Full link command and output with `-v` appended:**
```
"C:/Users/toyobayashi/Projects/emsdk/upstream/bin\wasm-ld.exe" -o out/myobject.wasm C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\emnapi_0.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\myobject_1.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\main_2.o -LC:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024
wasm-ld: error: --shared-memory is disallowed by cxa_default_handlers.o because it was not compiled with 'atomics' or 'bulk-memory' features.
em++: error: 'C:/Users/toyobayashi/Projects/emsdk/upstream/bin\wasm-ld.exe -o out/myobject.wasm C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\emnapi_0.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\myobject_1.o C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_d1j8pdc_\main_2.o -LC:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024' failed (returned 1)
```

**Repro:**
[https://github.com/toyobayashi/emxx-shared-memory-repro](https://github.com/toyobayashi/emxx-shared-memory-repro)

------

C++ hello world is also failed to compile with `-sSHARED_MEMORY=1`

main.cc

```cpp
#include

int main() {
std::cout << "em++" << std::endl;
return 0;
}
```

```
C:\Users\toyobayashi\Projects\emxx-shared-memory-repro>em++ -sSHARED_MEMORY=1 -o main.js main.cc
wasm-ld: error: --shared-memory is disallowed by ios.o because it was not compiled with 'atomics' or 'bulk-memory' features.
em++: error: 'C:/Users/toyobayashi/Projects/emsdk/upstream/bin\wasm-ld.exe -o main.wasm C:\Users\toyobayashi\AppData\Local\Temp\emscripten_temp_z4sx8wwx\main_0.o -LC:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\toyobayashi\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
```

But C is all OK.

main.c

```c
#include

int main() {
printf("emcc\n");
return 0;
}
```

```
C:\Users\toyobayashi\Projects\emxx-shared-memory-repro>emcc -sSHARED_MEMORY=1 -o main.js main.c
# OK! output main.js and main.wasm
```

Forgive my stupidity if this is not a bug.

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.