Bug 2228297
| Summary: | Undefined symbol 'errno' when linking with wasi-libc | ||
|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | Andrew Clayton <andrew> |
| Component: | wasi-libc | Assignee: | Jan Staněk <jstanek> |
| Status: | CLOSED ERRATA | QA Contact: | |
| Severity: | medium | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 38 | CC: | jistone, jstanek |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | wasi-libc-20-4.fc40 wasi-libc-20-4.fc39 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2023-08-14 09:45:37 UTC | Type: | --- |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
Forgot to add that looking for the errno definition in the libraries (with llvm-nm), from the the wasi-sysroot v20.0 tarball pulled from GitHub we see errno.o: 00000000 D errno in libc.a whereas in the libc.a from the Fedora 38 wasm32-wasi-static package we see errno.o: 00000000 D __EINVAL 00000004 D __ENOMEM and I only see references to 'U errno' and no 'D errno' in any of the packaged libraries/objects. That's curious. In wasm32-wasi-static's libc.a, I see *two* entries that look like: errno.o: 00000000 D __EINVAL 00000004 D __ENOMEM Whereas in rust-std-static-wasm32-wasi, which still bundles its own copy, there is one entry like that, and another with "D errno". (They only other difference in those libc.a symbols is having dlmalloc.o vs. emmalloc.o) There are two separate errno.c sources that create errno.o objects in libc.a:
libc-bottom-half/cloudlibc/src/libc/errno/errno.c (errno)
libc-bottom-half/sources/errno.c (__EINVAL and __ENOMEM)
However, "%global toolchain clang" enables the post-install /usr/lib/rpm/redhat/brp-llvm-compile-lto-elf, which unpacks the archive (ar x), looks for LLVM bitcode to compile in each object, and then re-packs them (ar r). So with two errno.o, the second overwrites the first while unpacking, and then that's also written on top of the first in the archive when repacking.
I think we could undefine %__brp_llvm_compile_lto_elf (or redefine it to %{nil}) to skip that step.
Sounds good. Happy to test any new builds... Thanks both of you for the report and the suggested fix, it now works on my machine :) Update should follow shortly. FEDORA-2023-d36d498dc0 has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2023-d36d498dc0 FEDORA-2023-d36d498dc0 has been pushed to the Fedora 40 stable repository. If problem still persists, please make note of it in this bug report. Note: I have trouble building this for F38 ATM, seems something is broken in koji: https://koji.fedoraproject.org/koji/taskinfo?taskID=104820303. The builds will be incoming once that is resolved. FEDORA-2023-1276d16f5b has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-1276d16f5b FEDORA-2023-1276d16f5b has been pushed to the Fedora 39 stable repository. If problem still persists, please make note of it in this bug report. |
Using the following simple reproducer and linking against the Fedora 38 wasm32-wasi-static libs results in a linker error $ cat e.c #include <errno.h> int main(void) { errno = 0; return errno; } $ clang --target=wasm32-wasi --sysroot=/usr/wasm32-wasi -o e.wasm e.c wasm-ld: error: /tmp/e-78d8d7.o: undefined symbol: errno wasm-ld: error: /tmp/e-78d8d7.o: undefined symbol: errno clang-16: error: linker command failed with exit code 1 (use -v to see invocation) However doing the same with the wasi-sysroot v20.0 tarball from https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sysroot-20.0.tar.gz works fine $ clang --target=wasm32-wasi --sysroot=/tmp/wasi-sysroot -o e.wasm e.c $ Reproducible: Always Steps to Reproduce: 1. Try to compile and link the above program Actual Results: Linker error wasm-ld: error: /tmp/e-78d8d7.o: undefined symbol: errno wasm-ld: error: /tmp/e-78d8d7.o: undefined symbol: errno clang-16: error: linker command failed with exit code 1 (use -v to see invocation) Expected Results: Successful compilation/linking.