Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 914731 - dev-lang/zig fails to build at stage3: zig build-exe zig ReleaseFast native 5 errors, ld.lld: undefined symbol
Summary: dev-lang/zig fails to build at stage3: zig build-exe zig ReleaseFast native 5...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Eric Joldasov
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2023-09-26 06:11 UTC by Yiyang Wu
Modified: 2023-11-28 15:43 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build.log (build.log,21.23 KB, text/x-log)
2023-09-26 06:12 UTC, Yiyang Wu
Details
emerge --info (emerge-info.txt,6.06 KB, text/plain)
2023-09-26 06:12 UTC, Yiyang Wu
Details
zig2-show-builtin-RHEL8 (zig2-show-builtin-RHEL8.log,3.14 KB, text/x-log)
2023-09-28 01:26 UTC, Yiyang Wu
Details
zig2-show-builtin-Debian12 (zig2-show-builtin-Debian12.log,2.95 KB, text/x-log)
2023-09-28 01:27 UTC, Yiyang Wu
Details
new-zig2-show-builtin-Debian12 (new-zig2-show-builtin-Debian12.log,2.95 KB, text/x-log)
2023-10-29 15:10 UTC, Yiyang Wu
Details
new-zig2-show-builtin-RHEL8 (new-zig2-show-builtin-RHEL8.log,3.14 KB, text/x-log)
2023-10-29 15:10 UTC, Yiyang Wu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yiyang Wu 2023-09-26 06:11:19 UTC
When emerging dev-lang/zig on Gentoo Prefix with sys-devel/lld:16, the last step of compilation, compiling stage3/bin/zig, failed with

[19/19] cd /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0 && /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zig2 build --prefix /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/stage3 --zig-lib-dir /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib -Dconfig_h=/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dno-langref -Dno-autodocs -Dtarget=native -Dcpu=native -Dversion-string=0.11.0
FAILED: stage3/bin/zig /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/stage3/bin/zig 
cd /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0 && /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zig2 build --prefix /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/stage3 --zig-lib-dir /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib -Dconfig_h=/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dno-langref -Dno-autodocs -Dtarget=native -Dcpu=native -Dversion-string=0.11.0
zig build-exe zig ReleaseFast native: error: the following command failed with 5 compilation errors:
/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zig2 build-exe --stack 33554432 /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/src/main.zig /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zigcpp/libzigcpp.a /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/libclang-cpp.so.16 /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldMinGW.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldELF.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldCOFF.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldWasm.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldMachO.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/liblldCommon.so /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64/libLLVM-16.so /home/wuyy/gentoo_prefix/usr/lib/gcc/x86_64-pc-linux-gnu/13/libstdc++.so -lunwind -lc -OReleaseFast --cache-dir /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache --global-cache-dir /tmp/portage/dev-lang/zig-0.11.0/homedir/.cache/zig --name zig --mod build_options::/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/c/8be3380d7aa95aa051fdfc613f919a48/options.zig --deps build_options -I /home/wuyy/gentoo_prefix/usr/lib/llvm/16/include -I /home/wuyy/gentoo_prefix/usr/lib/llvm/16/include -L /home/wuyy/gentoo_prefix/usr/lib/llvm/16/lib64 -I /home/wuyy/gentoo_prefix/usr/lib/llvm/16/include --zig-lib-dir /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib --listen=- 
Build Summary: 2/5 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- install zig transitive failure
   +- zig build-exe zig ReleaseFast native 5 errors
error: ld.lld: undefined symbol: __libc_single_threaded
    note: referenced by zig_clang_cc1_main.cpp
    note:               zig_clang_cc1_main.cpp.o:(cc1_main(llvm::ArrayRef<char const*>, char const*, void*)) in archive /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zigcpp/libzigcpp.a
    note: referenced by zig_clang_cc1_main.cpp
    note:               zig_clang_cc1_main.cpp.o:(cc1_main(llvm::ArrayRef<char const*>, char const*, void*)) in archive /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zigcpp/libzigcpp.a
    note: referenced by zig_clang_cc1_main.cpp
    note:               zig_clang_cc1_main.cpp.o:(cc1_main(llvm::ArrayRef<char const*>, char const*, void*)) in archive /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zigcpp/libzigcpp.a
    note: referenced 6 more times
error: ld.lld: undefined symbol: pthread_attr_setstacksize
    note: referenced by Thread.zig:699 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:699)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(Thread.Pool.init)
    note: referenced by Thread.zig:699 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:699)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(main.serve)
error: ld.lld: undefined symbol: pthread_attr_setguardsize
    note: referenced by Thread.zig:700 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:700)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(Thread.Pool.init)
    note: referenced by Thread.zig:700 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:700)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(main.serve)
error: ld.lld: undefined symbol: pthread_create
    note: referenced by Thread.zig:703 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:703)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(Thread.Pool.init)
    note: referenced by Thread.zig:703 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:703)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(main.serve)
error: ld.lld: undefined symbol: pthread_join
    note: referenced by Thread.zig:731 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:731)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(Thread.Pool.join)
    note: referenced by Thread.zig:731 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:731)
    note:               /tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/o/96df9fe3edb2ed3b0deecf123f3b66fe/zig.o:(main.serve)
    note: referenced by Thread.zig:731 (/tmp/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib/std/Thread.zig:731)

Reproducible: Always
Comment 1 Yiyang Wu 2023-09-26 06:12:24 UTC
Created attachment 871468 [details]
build.log
Comment 2 Yiyang Wu 2023-09-26 06:12:38 UTC
Created attachment 871469 [details]
emerge --info
Comment 3 Yiyang Wu 2023-09-26 06:17:40 UTC
Similar to https://github.com/ziglang/zig/issues/11137, and it may be caused by detecting the wrong libc version, like https://github.com/ziglang/zig/issues/6469, but this is prefix, so maybe zig is looking into hosts' libc
Comment 4 Yiyang Wu 2023-09-27 02:16:00 UTC
Update:

On another prefix with Debian host (the original bug report is produced on RHEL 8 host where /lib64 -> /usr/lib64 contains libm.so and other libraries), the error messages are:

```
FAILED: stage3/bin/zig /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/stage3/bin/zig 
cd /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0 && /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zig2 build --prefix /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/stage3 --zig-lib-dir /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib -Dconfig_h=/fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dno-langref -Dno-autodocs -Dtarget=native -Dcpu=native -Dversion-string=0.11.0
zig build-exe zig ReleaseFast native: error: the following command failed with 1 compilation errors:
/fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zig2 build-exe --stack 33554432 /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/src/main.zig /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/build/zigcpp/libzigcpp.a /opt/gentoo/usr/lib/llvm/16/lib64/libclang-cpp.so.16 /opt/gentoo/usr/lib/llvm/16/lib64/liblldMinGW.so /opt/gentoo/usr/lib/llvm/16/lib64/liblldELF.so /opt/gentoo/usr/lib/llvm/16/lib64/liblldCOFF.so /opt/gentoo/usr/lib/llvm/16/lib64/liblldWasm.so /opt/gentoo/usr/lib/llvm/16/lib64/liblldMachO.so /opt/gentoo/usr/lib/llvm/16/lib64/liblldCommon.so /opt/gentoo/usr/lib/llvm/16/lib64/libLLVM-16.so /opt/gentoo/usr/lib/gcc/x86_64-pc-linux-gnu/13/libstdc++.so -lunwind -lc -OReleaseFast --cache-dir /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache --global-cache-dir /fast/portage/dev-lang/zig-0.11.0/homedir/.cache/zig --name zig --mod build_options::/fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/zig-cache/c/8be3380d7aa95aa051fdfc613f919a48/options.zig --deps build_options -I /opt/gentoo/usr/lib/llvm/16/include -I /opt/gentoo/usr/lib/llvm/16/include -L /opt/gentoo/usr/lib/llvm/16/lib64 -I /opt/gentoo/usr/lib/llvm/16/include --zig-lib-dir /fast/portage/dev-lang/zig-0.11.0/work/zig-0.11.0/lib --listen=- 
Build Summary: 2/5 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- install zig transitive failure
   +- zig build-exe zig ReleaseFast native 1 errors
error: ld.lld: cannot open /lib64/libm.so.6: No such file or directory
```

So it's more evident that something goes wrong when zig detects system lib locations
Comment 5 Eric Joldasov 2023-09-27 15:59:36 UTC
Can you share output of:

* getconf GNU_LIBC_VERSION
* zig2 build-exe --show-builtin

on both systems please? Thanks in advance!
Comment 6 Yiyang Wu 2023-09-28 01:24:43 UTC
(In reply to Eric Joldasov from comment #5)
> Can you share output of:
> 
> * getconf GNU_LIBC_VERSION

They both omit glibc 2.37

While if I run /usr/bin/getconf GNU_LIBC_VERSION, RHEL 8 gives glibc 2.28 and Debian 12 gives glibc 2.36

> * zig2 build-exe --show-builtin

The output of ${BUILD_DIR}/zig2 build-exe --show-builtin will be uploaded as attachments
Comment 7 Yiyang Wu 2023-09-28 01:26:03 UTC
Created attachment 871619 [details]
zig2-show-builtin-RHEL8
Comment 8 Yiyang Wu 2023-09-28 01:27:30 UTC
Created attachment 871620 [details]
zig2-show-builtin-Debian12
Comment 9 Eric Joldasov 2023-09-28 06:13:04 UTC
I see, thanks! Guess I need to return getconf patch for a while.
Comment 10 Larry the Git Cow gentoo-dev 2023-10-27 02:59:14 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=42ac667416fe133255c3baca620e9af61315cb3b

commit 42ac667416fe133255c3baca620e9af61315cb3b
Author:     Eric Joldasov <bratishkaerik@getgoogleoff.me>
AuthorDate: 2023-10-10 03:12:16 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-10-27 02:53:03 +0000

    dev-lang/zig: patch 0.11.0 to use getconf when detecting glibc version
    
    Bug: https://bugs.gentoo.org/914731
    Bug: https://bugs.gentoo.org/914101
    
    Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
    Signed-off-by: Sam James <sam@gentoo.org>

 .../zig/files/zig-0.11.0-first-try-getconf.patch   | 109 +++++++++++++++++++++
 .../{zig-0.11.0.ebuild => zig-0.11.0-r1.ebuild}    |   4 +
 2 files changed, 113 insertions(+)
Comment 11 Yiyang Wu 2023-10-29 15:08:55 UTC
Sorry, after applying the patch, the `./zig2 build-exe --show-builtin` command shows glibc version to 2.36, but not 2.37 which is the output of `getconf GNU_LIBC_VERSION`. And the build error remains the same.

And I noticed that, before applying this patch, both system `./zig2 build-exe --show-builtin` gives glibc version 2.19, despite the Gentoo prefix has 2.37, while RHEL 8 has 2.19 and Debian 12 has 2.36. After the patch, `./zig2 build-exe --show-builtin` both gives 2.36. It looks very weird.

I will add the output prefixed with "new-" in attachments.
Comment 12 Yiyang Wu 2023-10-29 15:10:04 UTC
Created attachment 873664 [details]
new-zig2-show-builtin-Debian12
Comment 13 Yiyang Wu 2023-10-29 15:10:43 UTC
Created attachment 873665 [details]
new-zig2-show-builtin-RHEL8
Comment 14 Eric Joldasov 2023-11-22 12:54:52 UTC
Hello, could you please re-test this again with latest dev-lang/zig-0.11.0 ebuild? Thanks in advance.
Comment 15 Yiyang Wu 2023-11-24 12:07:55 UTC
(In reply to Eric Joldasov from comment #14)
> Hello, could you please re-test this again with latest dev-lang/zig-0.11.0
> ebuild? Thanks in advance.

I just tried with latest portage commit 54b20cb55a644f07faa7f426118e4ff9b6c4d8e9 and the issue remains the same.

I think the https://bugs.gentoo.org/attachment.cgi?id=873664(In reply to Yiyang Wu from comment #11)
> Sorry, after applying the patch, the `./zig2 build-exe --show-builtin`
> command shows glibc version to 2.36, but not 2.37 which is the output of
> `getconf GNU_LIBC_VERSION`. And the build error remains the same.
> 
> And I noticed that, before applying this patch, both system `./zig2
> build-exe --show-builtin` gives glibc version 2.19, despite the Gentoo
> prefix has 2.37, while RHEL 8 has 2.19 and Debian 12 has 2.36. After the
> patch, `./zig2 build-exe --show-builtin` both gives 2.36. It looks very
> weird.
> 
> I will add the output prefixed with "new-" in attachments.

Above are my test results after the fix, and I didn't notice any new commit introduced to dev-lang/zig-0.11.0 since then. So I guess the issue is still here.
Comment 16 Eric Joldasov 2023-11-28 14:01:18 UTC
(In reply to Yiyang Wu from comment #15)
> (In reply to Eric Joldasov from comment #14)
> > Hello, could you please re-test this again with latest dev-lang/zig-0.11.0
> > ebuild? Thanks in advance.
> 
> I just tried with latest portage commit
> 54b20cb55a644f07faa7f426118e4ff9b6c4d8e9 and the issue remains the same.
> 
> I think the https://bugs.gentoo.org/attachment.cgi?id=873664(In reply to
> Yiyang Wu from comment #11)
> > Sorry, after applying the patch, the `./zig2 build-exe --show-builtin`
> > command shows glibc version to 2.36, but not 2.37 which is the output of
> > `getconf GNU_LIBC_VERSION`. And the build error remains the same.
> > 
> > And I noticed that, before applying this patch, both system `./zig2
> > build-exe --show-builtin` gives glibc version 2.19, despite the Gentoo
> > prefix has 2.37, while RHEL 8 has 2.19 and Debian 12 has 2.36. After the
> > patch, `./zig2 build-exe --show-builtin` both gives 2.36. It looks very
> > weird.
> > 
> > I will add the output prefixed with "new-" in attachments.
> 
> Above are my test results after the fix, and I didn't notice any new commit
> introduced to dev-lang/zig-0.11.0 since then. So I guess the issue is still
> here.

Hello, and thanks again. Sentence with "portage commit" confused me a little, do you refer to main repository? If yes: seems like new fix was included before this commit. 

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=08419414eebb1bb26e9e72cffb66ce81a0e64751 commit with fix; IIUC you refer to this? https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=54b20cb55a644f07faa7f426118e4ff9b6c4d8e9 . It contains two new commits for zig package. You can verify if new patch is here by checking whether dev-lang/zig-9999 has new `llvm` use flag in your tree.
Comment 17 Yiyang Wu 2023-11-28 15:43:37 UTC
(In reply to Eric Joldasov from comment #16)
> Hello, and thanks again. Sentence with "portage commit" confused me a
> little, do you refer to main repository? If yes: seems like new fix was
> included before this commit.
> 
> https://gitweb.gentoo.org/repo/gentoo.git/commit/
> ?id=08419414eebb1bb26e9e72cffb66ce81a0e64751 commit with fix; IIUC you refer
> to this?
> https://gitweb.gentoo.org/repo/gentoo.git/commit/
> ?id=54b20cb55a644f07faa7f426118e4ff9b6c4d8e9 . It contains two new commits
> for zig package. You can verify if new patch is here by checking whether
> dev-lang/zig-9999 has new `llvm` use flag in your tree.

Yes, I was using https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=54b20cb55a644f07faa7f426118e4ff9b6c4d8e9 which contains the two new commits, and I also confirms that dev-lang/zig-9999 has new `llvm` use flag in my tree.