When trying to detect libatomic, LLD fails to respect CMake's request to check existence

I get cmake/modules/CheckAtomic.cmake:59
Host compiler appears to require libatomic, but cannot find it.

I think this is either a bug in CMake or LLVM’s Linker. I’m using the WASI-SDK from here. Note: cross-posted to the CMake discourse.

This is while trying to cross-compile LLVM 13 for WASI using the following command line:

cmake ../../../3rdParty/llvm-project/llvm -G "Ninja" -DWASI_SDK_PREFIX=/opt/wasi-sdk --toolchain=/opt/wasi-sdk/share/cmake/wasi-sdk.cmake -DCMAKE_C_FLAGS="--sysroot=/opt/wasi-sdk/share/wasi-sysroot -mno-atomics" -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DLLVM_USE_HOST_TOOLS:BOOL=ON -DCMAKE_HOST_SYSTEM_NAME="Linux" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../3rdParty/llvm-wasi/debug -DCMAKE_CROSSCOMPILING_EMULATOR="wasmer" -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -DLLVM_ENABLE_THREADS=OFF

Edit

CMake’s invokation of Clang and Wasm-LD is as follows:
: && /opt/wasi-sdk/bin/clang --target=wasm32-wasi --sysroot=/opt/wasi-sdk/share/wasi-sysroot -mno-atomics -DCHECK_FUNCTION_EXISTS=__atomic_fetch_add_4 -Werror=unguarded-availability-new CMakeFiles/cmTC_44e46.dir/CheckFunctionExists.c.obj -o cmTC_44e46 -latomic && :
wasm-ld: error: unable to find library -latomic
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Edit2

Using the latest release candidate solved nothing. Filing a bug report.