I ran into this building Firefox's wasm sandboxed libraries (RLBox) with
llvm-toolchain-22 1:22.1.2-1ubuntu1 on resolute, and tracked down the
cause.

The wasm32 libc++ and libc++abi are compiled with C++ exceptions
enabled, although debian/rules configures both with
LIBCXX_ENABLE_EXCEPTIONS=OFF and LIBCXXABI_ENABLE_EXCEPTIONS=OFF. Those
options leave out cxa_exception.cpp and cxa_personality.cpp, which
define the exception runtime, but -fno-exceptions never reaches the
compiler, so the remaining objects still call that runtime. In the
published libc++-22-dev-wasm32, 23 objects in libc++.a
(stdlib_new_delete.cpp.o among them, as in the autopkgtest output above)
reference __cxa_allocate_exception, __cxa_throw, __cxa_begin_catch or
__cxa_rethrow, and nothing in libc++.a, libc++abi.a,
libclang_rt.builtins-wasm32.a or wasi-libc defines them.

-fno-exceptions is missing because the configure step of the wasm32
libcxx build fails every compiler check. From the amd64 build log of
1:22.1.2-1ubuntu1 (https://launchpad.net/ubuntu/+source/llvm-
toolchain-22/1:22.1.2-1ubuntu1/+build/32732749):

```
-- Detecting CXX compiler ABI info - failed
-- Performing Test CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG - Failed
-- Performing Test CXX_SUPPORTS_EHS_FLAG - Failed
```

All 47 "Performing Test" checks of that step fail, so libcxx's
cxx_add_exception_flags() drops -fno-exceptions, along with every other
flag it adds only after checking it. The linker flags of that step are:

```
CMAKE_EXE_LINKER_FLAGS="-Wl,--package-metadata=%7B...%7D -Wl,-z,relro 
-L/<<PKGBUILDDIR>>/build-llvm/tools/clang/stage2-bins/lib"
```

Debian's build of llvm-toolchain-22 1:22.1.8-3 (arch all on
buildd.debian.org), whose wasm rules have the same settings, passes
CMAKE_EXE_LINKER_FLAGS="-Wl,-z,relro -L.../stage2-bins/lib" to the same
step. There the compiler ABI is detected, 37 checks pass including
CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG, and its libc++-22-dev-wasm32 has no
references to these functions. The only difference in the flags is the
-Wl,--package-metadata which Ubuntu's dpkg-buildflags adds, so wasm-ld
presumably rejects it and every test link fails. I could not run wasm-ld
myself to see its exact error.

A fix would be to filter -Wl,--package-metadata=% out of the LDFLAGS
used for the wasm builds in debian/rules, the way STAGE_2_WASM_CFLAGS
already filters out options wasm does not support. That makes the checks
pass again, and with them -fno-exceptions reaches the compiler. The
tasks here also list llvm-toolchain-18 and -21; I only checked 22.

Until then, a consumer can define the missing functions as stubs which
call abort(), which is what libc++ built without exceptions does in
their place. Firefox's wasm link also needed _Unwind_GetIP,
_Unwind_GetLanguageSpecificData, _Unwind_GetRegionStart, _Unwind_SetGR
and _Unwind_SetIP, which gcc_personality_v0.c.obj in
libclang_rt.builtins-wasm32.a references and no wasm32 library defines.
I have not checked whether those go away with the fix above.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2169046

Title:
  autopkgtests various wasm-ld-18: error:
  /usr/lib/wasm32-wasi/libc++.a(stdlib_new_delete.cpp.o): undefined
  symbol

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-18/+bug/2169046/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to