Stream: wamr

Topic: warning: failed to link import function


view this post on Zulip Salvatore Bramante (Jan 29 2024 at 10:28):

Hello, I'm trying to execute on wamr a simple multithread program on arm cortex a53 (zephyr os), compilation goes well but it shows this log

-- west build: running target run
[0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-a53
*** Booting Zephyr OS build zephyr-v3.5.0-4528-g04de43b1a119 ***
[00:00:00:000 - 4002F990]: warning: failed to link import function (env, pthread_create)
[00:00:00:000 - 4002F990]: warning: failed to link import function (env, pthread_join)
Exception: failed to call unlinked import function (env, pthread_create)

I’ve also enabled wasi-libc of course. My compiling command is

/$HOME/wasi-sdk-21.0/bin/clang     \
   --target=wasm32-wasi-threads -pthread -z stack-size=524288 -Wl,--initial-memory=1048576 \
   --sysroot=/$HOME/wasi-sdk-21.0/share/wasi-sysroot  \
   -Wl,--allow-undefined-file=/$HOME/wasi-sdk-21.0/share/wasi-sysroot/share/wasm32-wasi-threads/defined-symbols.txt \
   -Wl,--strip-all,--no-entry -nostdlib \
   -Wl,--export=main \
   -Wl,--export=__data_end, -Wl,--export=__heap_base \
   -Wl,--allow-undefined \
   -o $WASM_BIN $C_FILE

I’ve also tried to not use -nostdlib flag but this led to blank output. Anyone can help me? Thanks in advance :)

view this post on Zulip YAMAMOTO Takashi (Jan 29 2024 at 11:12):

use this instead

/$HOME/wasi-sdk-21.0/bin/clang     \
   --target=wasm32-wasi-threads -pthread -z stack-size=524288 -Wl,--initial-memory=1048576 \
   -o $WASM_BIN $C_FILE

view this post on Zulip Salvatore Bramante (Jan 29 2024 at 11:17):

I've just tried but it gives me blank output (I've included a print before creating a thread but is not shown)

-- west build: running target run
[0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-a53
*** Booting Zephyr OS build zephyr-v3.5.0-4528-g04de43b1a119 ***

I'm calling this module in a C program so, to my mind, I've to export the module main function

view this post on Zulip YAMAMOTO Takashi (Jan 29 2024 at 12:01):

in wasi, the entry point is usually _start, which is provided by crt.

view this post on Zulip YAMAMOTO Takashi (Jan 29 2024 at 12:03):

given your stack-size and --initial-memory values, i guess it won't be able to create a thread.

view this post on Zulip Salvatore Bramante (Jan 29 2024 at 12:04):

I should give bigger stack and initial memory?

view this post on Zulip YAMAMOTO Takashi (Jan 29 2024 at 12:04):

have you flushed your printf output? depending on configurations, your stdout might not be line-buffered.

view this post on Zulip YAMAMOTO Takashi (Jan 29 2024 at 12:05):

smaller stack and larger memory

view this post on Zulip Salvatore Bramante (Jan 30 2024 at 09:45):

I've tried to double the initial memory and reduce stack but nothing happened. I do not think that the missing prints are related to stdout flush because with my first command:

/$HOME/wasi-sdk-21.0/bin/clang     \
   --target=wasm32-wasi-threads -pthread -z stack-size=524288 -Wl,--initial-memory=1048576 \
   --sysroot=/$HOME/wasi-sdk-21.0/share/wasi-sysroot  \
   -Wl,--allow-undefined-file=/$HOME/wasi-sdk-21.0/share/wasi-sysroot/share/wasm32-wasi-threads/defined-symbols.txt \
   -Wl,--strip-all,--no-entry -nostdlib \
   -Wl,--export=main \
   -Wl,--export=__data_end, -Wl,--export=__heap_base \
   -Wl,--allow-undefined \
   -o $WASM_BIN $C_FILE

prinft worked but pthread did not. The command you have suggested works only on my host machine (darwin) and not on my target (zephyr/qemu_cortex_a53).

view this post on Zulip YAMAMOTO Takashi (Feb 15 2024 at 13:05):

I do not think that the missing prints are related to stdout flush

have you tried to flush it?


Last updated: Nov 22 2024 at 17:03 UTC