WebAssembly / wasi-libc

WASI libc implementation for WebAssembly
https://wasi.dev
Other
847 stars 199 forks source link

undefined symbol: alarm (and maybe dup) #459

Open sporniket opened 9 months ago

sporniket commented 9 months ago

Context

Hello, I am trying to build yices2, (see there : https://github.com/sporniket/yices2-built-with-wasi-sdk ), I have tried wasi-sdk 19 and 20 without difference.

So far, I have

The problem

Now I am stuck with : wasm-ld: error: ../build/wasm32-unknown-wasi-release/lib/libyices.a(timeout.o): undefined symbol: alarm

Did I miss another build option or something, or is it not possible at all to build yices2 at the moment ?

Steps to reproduce

I use Ubuntu 20 LTS, uname -aLinux Asusia 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux with usual dev tools installed.

git clone --recurse-submodules https://github.com/sporniket/yices2-built-with-wasi-sdk.git
cd yices2-built-with-wasi-sdk
./build.sh

When performing the build, I have warnings about 2 undefined functions :

api/yices_api.c:1176:12: warning: call to undeclared function 'dup'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  tmp_fd = dup(fd);
           ^

[...]

utils/timeout.c:293:10: warning: call to undeclared function 'alarm'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  (void) alarm(delay);
         ^
utils/timeout.c:310:12: warning: call to undeclared function 'alarm'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    (void) alarm(0); // cancel the alarm
           ^
utils/timeout.c:325:12: warning: call to undeclared function 'alarm'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    (void) alarm(0);
           ^

Then it fails when during the linking step :

/home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/wasi-sdk-19.0/bin/clang --target=wasm32-unknown-wasi -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS --sysroot=/home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/wasi-sdk-19.0/share/wasi-sysroot -Wl,--strip-all -L/home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/gmp-6.3.0-prefix/lib --sysroot=/home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/wasi-sdk-19.0/share/wasi-sysroot  \
   -o ../build/wasm32-unknown-wasi-release/bin/yices ../build/wasm32-unknown-wasi-release/obj/frontend/yices.o ../build/wasm32-unknown-wasi-release/lib/libyices.a -lwasi-emulated-process-clocks -lwasi-emulated-signal -lgmp /home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/getopt_long.o  --sysroot=/home/dsporn/Projects/amaranth/YoWASP/yices2-built-with-wasi-sdk/wasi-sdk-19.0/share/wasi-sysroot
wasm-ld: error: ../build/wasm32-unknown-wasi-release/lib/libyices.a(timeout.o): undefined symbol: alarm
wasm-ld: error: ../build/wasm32-unknown-wasi-release/lib/libyices.a(timeout.o): undefined symbol: alarm
wasm-ld: error: ../build/wasm32-unknown-wasi-release/lib/libyices.a(timeout.o): undefined symbol: alarm

I have looked for the name alarm with commands like ar t wasi-sdk-19.0/share/wasi-sysroot/lib/wasm32-wasi/libc.a | grep ala on libc.a, libwasi-emulated-process-clocks.a and libwasi-emulated-signal.a, and in fact in the other libs found in wasi-sysroot too, without success.

I guess this will be the same for dup too.

However in wasi-libc repository, I can see alarm at https://github.com/WebAssembly/wasi-libc/blob/main/libc-top-half/musl/src/unistd/alarm.c, and dup at https://github.com/WebAssembly/wasi-libc/blob/main/libc-top-half/musl/src/unistd/dup.c

Build option

As seen in the build script, I am using -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS as well as -lwasi-emulated-process-clocks -lwasi-emulated-signal :

export CC="${WASI_SDK_PATH}/clang"
export CC_FOR_BUILD="gcc"
LIBS_BEGIN="-lwasi-emulated-process-clocks -lwasi-emulated-signal"
LIBS_END=" --sysroot=${SYSROOT}"

export CFLAGS="--target=wasm32-unknown-wasi -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS --sysroot=${SYSROOT}"
export LIBS="${LIBS_BEGIN} -lgmp $(pwd)/getopt_long.o ${LIBS_END}"
#export CPPFLAGS="-I${SYSROOT}/include/wasi -I${GMP_PREFIX_DIR}/include -I${YICES2_SRC_HOME} -I${YICES2_SRC_HOME}/include"
export CPPFLAGS="-I${GMP_PREFIX_DIR}/include -I${YICES2_SRC_HOME} -I${YICES2_SRC_HOME}/include"
export LDFLAGS="-Wl,--strip-all -L${GMP_PREFIX_DIR}/lib --sysroot=${SYSROOT}"
sbc100 commented 9 months ago

wasi-libc does not currently support either dup or alarm. You most likely will need to modify the yices2 source code (or maybe just the compile flags) to remove the use of those APIs.

(The alarm.c and dup.c files that you link to are part of the upstream musl project but neither of them is compiled when building wasi-libc).

sporniket commented 9 months ago

I see, thank you.