wasm-ld: error: --shared-memory is disallowed by .... because it was not compiled with 'atomics' or 'bulk-memory' features.

5,172 views
Skip to first unread message

Jasmeet Kaur

unread,
Apr 8, 2021, 4:11:16 PM4/8/21
to emscripten-discuss
Hi,
I am trying to use emscripton for a project. When I compile,  I get this error :
wasm-ld: error: --shared-memory is disallowed by .... because it was not compiled with 'atomics' or 'bulk-memory' features.
Can someone point me as to how to resolve this? And also explain as to why is this happening?
Environment info;
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.16
clang version 13.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project ad8010e598d9aa3747c34ce28aa2ba6de1650bd4)
Target: wasm32-unknown-emscripten
Thread model: posix

Thank you!

Thomas Lively

unread,
Apr 8, 2021, 4:17:10 PM4/8/21
to emscripte...@googlegroups.com
The object file specified in the error message was not compiled with -pthread, so atomic operations and thread-local data (if any) in its source were transformed to non-atomic operations and non-thread-local data. That transformation makes it unsafe to link that object into multi-threaded programs, so wasm-ld fails with that error message. The fix is to use -pthread when compiling that object.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/a9d08d47-9808-4205-bb71-e9990aa19cf7n%40googlegroups.com.

Jasmeet Kaur

unread,
Apr 8, 2021, 4:26:16 PM4/8/21
to emscripten-discuss
I am using -pthread flag : (makefile)
COMMON_LNFLAGS += -Lapps/libs -Ldemos/libs -L/usr/X11R6/lib64 -L/usr/X11R6/lib -pthread

and here is the compilation output :
emcc  -o ../../../../html/debug/snakebird.js  ../../../../objs_html/snakebird.js/debug/apps/snakebird/Driver.o  -lenvironments -lmapalgorithms -lalgorithms -lgraphalgorithms -lgraph -lutils -lguihtml -lgui -lSTUB -L../../../../html/debug -Lapps/libs -Ldemos/libs -L/usr/X11R6/lib64 -L/usr/X11R6/lib -pthread -g -s EXPORTED_FUNCTIONS="['_InitHOG', '_InitHOGArg', '_DoFrame', '_MouseEvent', '_HitKey', '_SetCanvasSize']" -s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]
Live child 0x5633c6243c40 (../../../../html/debug/snakebird.js) PID 22723
wasm-ld: error: --shared-memory is disallowed by ../../../../objs_html/snakebird.js/debug/apps/snakebird/Driver.o because it was not compiled with 'atomics' or 'bulk-memory' features.


Is this not correct?

Thomas Lively

unread,
Apr 8, 2021, 5:45:36 PM4/8/21
to emscripte...@googlegroups.com
That's the link command, since Driver.o is one of the inputs. You need to pass -pthread at compile time, where Driver.o is created, as well.

Jim Lloyd

unread,
Apr 8, 2021, 5:51:51 PM4/8/21
to emscripte...@googlegroups.com
My code has "-s: USE_PTHREADS" for both compile and link options. My CMake uses this snippet:

if (TARGET_WASM)
add_compile_options("SHELL:-s USE_PTHREADS")
add_link_options("SHELL:-s USE_PTHREADS")
endif()

Jasmeet Kaur

unread,
Apr 10, 2021, 10:07:41 AM4/10/21
to emscripten-discuss
hi,
i updated the makefile:
CC = emcc
COMMON_CFLAGS += -Wall -pthread

COMMON_CXXFLAGS += -I$(ROOT)/gui/ -I$(ROOT)/gui/GL/ -DNO_OPENGL -pthread

But this doesnt seem to work. How do i pass the flag during compile time for Driver.o?

Jim Lloyd

unread,
Apr 10, 2021, 12:13:57 PM4/10/21
to emscripte...@googlegroups.com, emscripten-discuss, Jasmeet Kaur
Note that
-pthreads
is not the same as
-s USE_PTHREADS
​I believe you need both options.

Alon Zakai

unread,
Apr 10, 2021, 12:25:53 PM4/10/21
to emscripte...@googlegroups.com, Jasmeet Kaur
-pthreads with an "s" is a typo, I think? clang ignores it:

clang-13: warning: argument unused during compilation: '-pthreads' [-Wunused-command-line-argument]

But -pthread (no "s") is identical to -s USE_PTHREADS.

Jasmeet, I think you need to debug your makefile. COMMON_CFLAGS may not reach the compile command. It may help to build one source file with EMCC_DEBUG=1 in the env to print out what compile command is run.

Reply all
Reply to author
Forward
0 new messages