Skip to content

undefined symbol: alarm (and maybe dup) #459

Closed

Description

@sporniket

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

  • succesfully build GMP lib.
  • had to patch yices to somehow get rid of setjmp/longjmp (I forked the original repo to version those patches)

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 -a ⇒ Linux 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.

  • clone with submodule the repository
  • cd to the cloned repository
  • invoke the build script : in summary, it downloads WASI-SDK (19, but I also tried with 20), it downloads and build GMP, and then it try to build yices2
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 :

  • dup()
  • alarm()
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}"

Activity

  1. sbc100 commented on Jan 2, 2024

    @sbc100
    Member

    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).

  2. sporniket commented on Jan 2, 2024

    @sporniket
    Author

    I see, thank you.

  3. abrown commented on Jun 2, 2025

    @abrown
    Contributor

    In talking to @alexcrichton, @sbc100, @sunfishcode: alarm would require support for signals, which is a bigger topic (see WebAssembly/design#1446); we think we can support dup in wasip2. Closing for now; feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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