emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.37k stars 3.25k forks source link

wasm-ld: error: 'atomics' feature is disallowed (protobuf) #17665

Open nsourligas opened 1 year ago

nsourligas commented 1 year ago

Hi,

I am trying to compile my Qt5 application (using protobuf) into wasm following Qt instructions. But the compilation fails at the last generated file which is the application js file and it's probably related to protobuf libraries. Any idea why this is happening?

QMAKE_CXXFLAGS += -s USE_PTHREADS=1 -s WASM_MEM_MAX=536870912
QMAKE_CFLAGS += -s USE_PTHREADS=1 -s WASM_MEM_MAX=536870912
QMAKE_LFLAGS += -pthread -s WASM_MEM_MAX=536870912
CC=emcc CXX=em++ AR=emar cmake .. -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/home/nikolaos.sourligkas/protobuf-wasm
emmake make libprotoc libprotobuf-lite
emmake make install libprotoc libprotobuf-lite
em++ -s WASM=1 -s FULL_ES2=1 -s FULL_ES3=1 -s USE_WEBGL2=1 -s EXIT_RUNTIME=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"] --bind -s FETCH=1 -pthread -s WASM_MEM_MAX=536870912 -O2 -s ALLOW_MEMORY_GROWTH=1 -o ./suntracker3-qt5.js main.o Tracking.o WindSpeed.o WindGraph.o WindGraphPoint.o FrontendInfo.o TrackerMatrix.o TrackerTelemetry.o TrackerMatrixModel.o DatabaseManager.o WebSocketClient.o suntracker3-qt5.js_plugin_import.o suntracker3-qt5.js_qml_plugin_import.o frontend.pb.o SunSpinBox_qml.o HomePage_qml.o SunHorizontalHeaderView_qml.o LineChart_qml.o SettingsPage_qml.o SunComboBox_qml.o TrackerMatrix_qml.o CButton_qml.o Login_qml.o SettingsLogin_qml.o main_qml.o qmlcache_loader.o qrc_qml_qmlcache.o moc_Tracking.o moc_WindSpeed.o moc_WindGraph.o moc_WindGraphPoint.o moc_FrontendInfo.o moc_TrackerMatrix.o moc_TrackerTelemetry.o moc_TrackerMatrixModel.o moc_DatabaseManager.o moc_WebSocketClient.o   -pthread -L/home/nikolaos.sourligkas/protobuf-wasm/lib -lprotobuf /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_hangul.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_openwnn.a /opt/Qt/5.15.0/wasm_32/lib/libqtopenwnn.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_pinyin.a /opt/Qt/5.15.0/wasm_32/lib/libqtpinyin.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_tcime.a /opt/Qt/5.15.0/wasm_32/lib/libqttcime.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_thai.a /opt/Qt/5.15.0/wasm_32/plugins/platforms/libqwasm.a /opt/Qt/5.15.0/wasm_32/lib/libQt5EventDispatcherSupport.a /opt/Qt/5.15.0/wasm_32/lib/libQt5FontDatabaseSupport.a /opt/Qt/5.15.0/wasm_32/lib/libqtfreetype.a /opt/Qt/5.15.0/wasm_32/lib/libQt5EglSupport.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqgif.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqicns.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqico.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqjpeg.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqtga.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqtiff.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqwbmp.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqwebp.a /opt/Qt/5.15.0/wasm_32/lib/libQt5WebSockets.a /opt/Qt/5.15.0/wasm_32/qml/QtCharts/libqtchartsqml2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Charts.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/libqtquickvirtualkeyboardplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Layouts/libqquicklayoutsplugin.a /opt/Qt/5.15.0/wasm_32/qml/Qt/labs/folderlistmodel/libqmlfolderlistmodelplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/Settings/libqtquickvirtualkeyboardsettingsplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/Styles/libqtquickvirtualkeyboardstylesplugin.a /opt/Qt/5.15.0/wasm_32/lib/libQt5VirtualKeyboard.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Svg.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Widgets.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick.2/libqtquick2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Templates.2/libqtquicktemplates2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtGraphicalEffects/private/libqtgraphicaleffectsprivate.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Window.2/libwindowplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtGraphicalEffects/libqtgraphicaleffectsplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Imagine/libqtquickcontrols2imaginestyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Material/libqtquickcontrols2materialstyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Fusion/libqtquickcontrols2fusionstyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Universal/libqtquickcontrols2universalstyleplugin.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QuickControls2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QuickTemplates2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Quick.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Gui.a /opt/Qt/5.15.0/wasm_32/lib/libqtlibpng.a /opt/Qt/5.15.0/wasm_32/lib/libqtharfbuzz.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QmlModels.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Qml.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Network.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Core.a /opt/Qt/5.15.0/wasm_32/lib/libqtpcre2.a   
root:WARNING: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271
wasm-ld: error: 'atomics' feature is disallowed by arena.cc.o, so --shared-memory must not be used
wasm-ld: error: Target feature 'atomics' used in main.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in Tracking.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in WindSpeed.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in WindGraph.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in WindGraphPoint.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in FrontendInfo.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in TrackerMatrix.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in TrackerTelemetry.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in TrackerMatrixModel.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in DatabaseManager.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in WebSocketClient.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in suntracker3-qt5.js_plugin_import.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in suntracker3-qt5.js_qml_plugin_import.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in frontend.pb.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in SunSpinBox_qml.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in HomePage_qml.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in SunHorizontalHeaderView_qml.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in LineChart_qml.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: Target feature 'atomics' used in SettingsPage_qml.o is disallowed by arena.cc.o. Use --no-check-features to suppress.
wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
shared:ERROR: '/home/nikolaos.sourligkas/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_nvijanr4/suntracker3-qt5.wasm --lto-O0 main.o Tracking.o WindSpeed.o -L/home/nikolaos.sourligkas/emsdk/upstream/emscripten/system/local/lib WindGraph.o -L/home/nikolaos.sourligkas/emsdk/upstream/emscripten/system/lib WindGraphPoint.o -L/home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj FrontendInfo.o TrackerMatrix.o TrackerTelemetry.o TrackerMatrixModel.o DatabaseManager.o WebSocketClient.o suntracker3-qt5.js_plugin_import.o suntracker3-qt5.js_qml_plugin_import.o frontend.pb.o SunSpinBox_qml.o HomePage_qml.o SunHorizontalHeaderView_qml.o LineChart_qml.o SettingsPage_qml.o SunComboBox_qml.o TrackerMatrix_qml.o CButton_qml.o Login_qml.o SettingsLogin_qml.o main_qml.o qmlcache_loader.o qrc_qml_qmlcache.o moc_Tracking.o moc_WindSpeed.o moc_WindGraph.o moc_WindGraphPoint.o moc_FrontendInfo.o moc_TrackerMatrix.o moc_TrackerTelemetry.o moc_TrackerMatrixModel.o moc_DatabaseManager.o moc_WebSocketClient.o -L/home/nikolaos.sourligkas/protobuf-wasm/lib /home/nikolaos.sourligkas/protobuf-wasm/lib/libprotobuf.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_hangul.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_openwnn.a /opt/Qt/5.15.0/wasm_32/lib/libqtopenwnn.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_pinyin.a /opt/Qt/5.15.0/wasm_32/lib/libqtpinyin.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_tcime.a /opt/Qt/5.15.0/wasm_32/lib/libqttcime.a /opt/Qt/5.15.0/wasm_32/plugins/virtualkeyboard/libqtvirtualkeyboard_thai.a /opt/Qt/5.15.0/wasm_32/plugins/platforms/libqwasm.a /opt/Qt/5.15.0/wasm_32/lib/libQt5EventDispatcherSupport.a /opt/Qt/5.15.0/wasm_32/lib/libQt5FontDatabaseSupport.a /opt/Qt/5.15.0/wasm_32/lib/libqtfreetype.a /opt/Qt/5.15.0/wasm_32/lib/libQt5EglSupport.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqgif.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqicns.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqico.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqjpeg.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqtga.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqtiff.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqwbmp.a /opt/Qt/5.15.0/wasm_32/plugins/imageformats/libqwebp.a /opt/Qt/5.15.0/wasm_32/lib/libQt5WebSockets.a /opt/Qt/5.15.0/wasm_32/qml/QtCharts/libqtchartsqml2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Charts.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/libqtquickvirtualkeyboardplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Layouts/libqquicklayoutsplugin.a /opt/Qt/5.15.0/wasm_32/qml/Qt/labs/folderlistmodel/libqmlfolderlistmodelplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/Settings/libqtquickvirtualkeyboardsettingsplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/VirtualKeyboard/Styles/libqtquickvirtualkeyboardstylesplugin.a /opt/Qt/5.15.0/wasm_32/lib/libQt5VirtualKeyboard.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Svg.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Widgets.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick.2/libqtquick2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Templates.2/libqtquicktemplates2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.a /opt/Qt/5.15.0/wasm_32/qml/QtGraphicalEffects/private/libqtgraphicaleffectsprivate.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Window.2/libwindowplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtGraphicalEffects/libqtgraphicaleffectsplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Imagine/libqtquickcontrols2imaginestyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Material/libqtquickcontrols2materialstyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Fusion/libqtquickcontrols2fusionstyleplugin.a /opt/Qt/5.15.0/wasm_32/qml/QtQuick/Controls.2/Universal/libqtquickcontrols2universalstyleplugin.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QuickControls2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QuickTemplates2.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Quick.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Gui.a /opt/Qt/5.15.0/wasm_32/lib/libqtlibpng.a /opt/Qt/5.15.0/wasm_32/lib/libqtharfbuzz.a /opt/Qt/5.15.0/wasm_32/lib/libQt5QmlModels.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Qml.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Network.a /opt/Qt/5.15.0/wasm_32/lib/libQt5Core.a /opt/Qt/5.15.0/wasm_32/lib/libqtpcre2.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libc-mt.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libcompiler_rt.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libc-wasm.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libc++-mt-noexcept.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libc++abi-mt-noexcept.a --whole-archive /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libembind-rtti.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libfetch-mt.a --no-whole-archive /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libgl-mt-webgl2-full_es3.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libdlmalloc-mt.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libpthread-mt.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libc_rt_wasm.a /home/nikolaos.sourligkas/emsdk/upstream/emscripten/cache/wasm-obj/libsockets-mt.a --allow-undefined --import-memory --import-table --shared-memory -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --strip-debug --export __wasm_call_ctors --export __data_end --export main --export malloc --export free --export setThrew --export __errno_location --export fflush --export emscripten_get_global_libc --export __pthread_tsd_run_dtors --export _register_pthread_ptr --export pthread_self --export __emscripten_pthread_data_constructor --export emscripten_futex_wake --export memalign --export _ZSt18uncaught_exceptionv --export emscripten_GetProcAddress --export strstr --export emscripten_webgl_make_context_current --export emscripten_webgl_get_current_context --export emscripten_builtin_free --export _get_environ --export emscripten_builtin_memalign --export realloc --export _get_tzname --export _get_daylight --export _get_timezone --export htonl --export htons --export ntohs --export strlen -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=536870912 --global-base=1024' failed (1)
Makefile:311: recipe for target 'suntracker3-qt5.js' failed
make: *** [suntracker3-qt5.js] Error 1
15:58:42: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project suntracker3-qt5 (kit: Qt 5.15.0 WebAssembly)
When executing step "Make"
15:58:42: Elapsed time: 00:15.
tlively commented 1 year ago

arena.cc is not being compiled with -pthread but all those other files are being compiled with -pthread. To fix it, make sure that all your files are being compiled with -pthread or that none of them are.

nsourligas commented 1 year ago

@tlively

arena.cc is part of protobuf source files and I think that it's being compiled by default with -pthread. And that's why it's very weird that I am always getting the same error with atomics.

CC=emcc CXX=em++ AR=emar cmake .. -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/home/anteam/protobuf-wasm

-- The C compiler identification is Clang 11.0.0
-- The CXX compiler identification is Clang 11.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/anteam/emsdk/upstream/emscripten/emcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/anteam/emsdk/upstream/emscripten/em++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- 
-- 3.15.8.0
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
-- Configuring done
-- Generating done
tlively commented 1 year ago

Something must be going wrong there because arena.cc is definitely not being compiled with -pthread.

nsourligas commented 1 year ago

@tlively you think it's a good idea to force somehow the protobuf library compilation with -pthread option?

tlively commented 1 year ago

Yes, unless you don't need threads, in which case the better fix would be compile the rest of your app without -pthread.