Skip to content

sem_open() produces internal error: mmapAlloc called but emscripten_builtin_memalign native symbol not exported #19202

@inobelar

Description

@inobelar

sem_open() call produces:

internal error: mmapAlloc called but emscripten_builtin_memalign native symbol not exported

main.cpp:

#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <semaphore.h>       /* For sem_open(), sem_close(), sem_unlink() */

#include <stdio.h>           /* For fputs() */

int main(int argc, char** argv)
{
    fputs("sem_open()\n", stdout);

    sem_t* s = sem_open("/my_semaphore", O_CREAT, 0644, 0);
    if (s == SEM_FAILED) {
        fputs("Failed to create semaphore!\n", stdout);
        return 1;
    }

    fputs("sem_close()\n", stdout);
    sem_close(s);

    fputs("sem_unlink()\n", stdout);
    sem_unlink("/my_semaphore");

    fputs("exit\n", stdout);
    return 0;
}

Compile command:

$ emcc -v --std=c++11 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -pthread ./main.cpp -o main.html 

image


Version of emscripten/emsdk:

$ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.34 (57b21b8fdcbe3ebb523178b79465254668eab408)
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
Target: wasm32-unknown-emscripten
Thread model: posix

Full link command and output with -v appended:

emcc -v --std=c++11 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -pthread ./main.cpp -o main.html 
 "/home/yurii/work/emscripten/emsdk/upstream/bin/clang" --version
 "/home/yurii/work/emscripten/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_SHARED_MEMORY__=1 -DEMSCRIPTEN --sysroot=/home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v --std=c++11 -pthread -matomics -mbulk-memory ./main.cpp -c -o /tmp/emscripten_temp_hzg_8tcb/main_0.o
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/yurii/work/emscripten/emsdk/upstream/bin
 (in-process)
 "/home/yurii/work/emscripten/emsdk/upstream/bin/clang-17" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +atomics -target-feature +bulk-memory -target-feature +mutable-globals -target-feature +sign-ext -target-cpu generic -target-feature +atomics -target-feature +bulk-memory -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/yurii/Downloads/emsc_sem_test -resource-dir /home/yurii/work/emscripten/emsdk/upstream/lib/clang/17 -D __EMSCRIPTEN_SHARED_MEMORY__=1 -D EMSCRIPTEN -isysroot /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /home/yurii/work/emscripten/emsdk/upstream/lib/clang/17/include -internal-isystem /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include --std=c++11 -fdeprecated-macro -fdebug-compilation-dir=/home/yurii/Downloads/emsc_sem_test -ferror-limit 19 -fvisibility=default -pthread -fgnuc-version=4.2.1 -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_hzg_8tcb/main_0.o -x c++ ./main.cpp
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
 /home/yurii/work/emscripten/emsdk/upstream/lib/clang/17/include
 /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
emcc: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
 "/home/yurii/work/emscripten/emsdk/upstream/bin/wasm-ld" -o main.wasm /tmp/emscripten_temp_hzg_8tcb/main_0.o -L/home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten /home/yurii/work/emscripten/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/crtbegin.o -lGL-mt -lal -lhtml5 -lstubs-debug -lnoexit -lc-mt-debug -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-debug-mt-noexcept -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmpvg3a51ol.undefined --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=_emscripten_thread_init --export-if-defined=_emscripten_thread_exit --export-if-defined=_emscripten_thread_crashed --export-if-defined=_emscripten_tls_init --export-if-defined=pthread_self --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --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_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=emscripten_dispatch_to_thread_ --export=_emscripten_thread_free_data --export=emscripten_main_runtime_thread_id --export=emscripten_main_thread_process_queued_calls --export=_emscripten_run_in_main_runtime_thread_js --export=emscripten_stack_set_limits --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=2147483648 --stack-first
 "/home/yurii/work/emscripten/emsdk/upstream/bin/wasm-emscripten-finalize" --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers main.wasm -o main.wasm --detect-features
 "/home/yurii/work/emscripten/emsdk/node/14.18.2_64bit/bin/node" /home/yurii/work/emscripten/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpos_n67_b.json
 "/home/yurii/work/emscripten/emsdk/upstream/bin/llvm-objcopy" main.wasm main.wasm --remove-section=.debug* --remove-section=producers
 "/home/yurii/work/emscripten/emsdk/node/14.18.2_64bit/bin/node" /home/yurii/work/emscripten/emsdk/upstream/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_hzg_8tcb/main.js growableHeap -o /tmp/emscripten_temp_hzg_8tcb/main.jso1.js
 "/home/yurii/work/emscripten/emsdk/node/14.18.2_64bit/bin/node" /home/yurii/work/emscripten/emsdk/upstream/emscripten/tools/preprocessor.js /tmp/emscripten_temp_hzg_8tcb/settings.js worker.js --expandMacros
 "/home/yurii/work/emscripten/emsdk/node/14.18.2_64bit/bin/node" /home/yurii/work/emscripten/emsdk/upstream/emscripten/tools/preprocessor.js /tmp/emscripten_temp_hzg_8tcb/settings.js shell.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions