Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 2228297 - Undefined symbol 'errno' when linking with wasi-libc
Summary: Undefined symbol 'errno' when linking with wasi-libc
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: wasi-libc
Version: 38
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jan Staněk
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 2234907
TreeView+ depends on / blocked
 
Reported: 2023-08-02 01:30 UTC by Andrew Clayton
Modified: 2023-08-25 18:07 UTC (History)
2 users (show)

Fixed In Version: wasi-libc-20-4.fc40 wasi-libc-20-4.fc39
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2234907 (view as bug list)
Environment:
Last Closed: 2023-08-14 09:45:37 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Andrew Clayton 2023-08-02 01:30:31 UTC
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.

Comment 1 Andrew Clayton 2023-08-02 01:37:09 UTC
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.

Comment 2 Josh Stone 2023-08-09 18:05:51 UTC
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)

Comment 3 Josh Stone 2023-08-09 18:22:27 UTC
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.

Comment 4 Andrew Clayton 2023-08-11 15:00:22 UTC
Sounds good. Happy to test any new builds...

Comment 5 Jan Staněk 2023-08-14 09:26:25 UTC
Thanks both of you for the report and the suggested fix, it now works on my machine :) Update should follow shortly.

Comment 6 Fedora Update System 2023-08-14 09:44:06 UTC
FEDORA-2023-d36d498dc0 has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2023-d36d498dc0

Comment 7 Fedora Update System 2023-08-14 09:45:37 UTC
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.

Comment 8 Jan Staněk 2023-08-14 10:08:53 UTC
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.

Comment 9 Fedora Update System 2023-08-16 09:51:32 UTC
FEDORA-2023-1276d16f5b has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-1276d16f5b

Comment 10 Fedora Update System 2023-08-16 09:54:37 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.