zig
zig copied to clipboard
undefined references in bootstrap build of 0.13
Zig Version
zig-bootstrap-0.13.0
Steps to Reproduce and Observed Behavior
tar -xf zig-bootstrap-0.13.0.tar.xz
cd zig-bootstrap-0.13.0
PATH=/opt/gcc-14.1.0/bin:$PATH LD_LIBRARY_PATH=/opt/gcc-14.1.0/lib64 ./build x86_64-linux-gnu x86_64
...
[ 84%] Building C object CMakeFiles/zig2.dir/zig2.c.o
[ 89%] Building C object CMakeFiles/zig2.dir/compiler_rt.c.o
[ 94%] Linking CXX executable zig2
/usr/bin/ld: CMakeFiles/zig2.dir/zig2.c.o: in function posix_getrandom__2384': zig2.c:(.text+0x5ba80a): undefined reference to getrandom'
/usr/bin/ld: CMakeFiles/zig2.dir/zig2.c.o: in function posix_copy_file_range__2600': zig2.c:(.text+0x6046f7): undefined reference to copy_file_range'
collect2: error: ld returned 1 exit status
CMakeFiles/zig2.dir/build.make:1126: recipe for target 'zig2' failed
make[2]: *** [zig2] Error 1
CMakeFiles/Makefile2:117: recipe for target 'CMakeFiles/zig2.dir/all' failed
make[1]: *** [CMakeFiles/zig2.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
Expected Behavior
successful build?
Try x86_64-linux-gnu.2.24 instead, or whatever glibc version you actually have. Zig defaults to 2.28, which has both of those functions.
Thank you, but that did not change the result.
I tried defining getrandom() and file_copy_range() and adding the object files to out/build-zig-host/CMakeFiles/zig2.dir/link.txt and rerunning the build command, but it overwrote link.txt and still failed.
Where are these two files called in the source tree? Maybe I can fix them instead.
I removed the prototypes for external getrandom() and copy_file_range(). I set the value of posix_copy_file_range_global_has_copy_file_range__66093 to false. I replaced the calls to getrandom() and copy_file_range() with zeroes. For getrandom(), there is a switch that falls back to getting entropy from /dev/urandom, and it does not complain. For copy_file_range(), I am hoping there is something similar.
zig2 compiled and linked.
But... when I try to build the hello-world program with zig2, it goes into an infinite loop and prints Semantic Analysis zig_libc Code Generation over and over. LD_LIBRARY_PATH=/opt/gcc-14.1.0/lib64 ./zig2 run --zig-lib-dir /sources/zig/zig-bootstrap-0.13.0/zig/lib hello.zig
The main build says that it is building stage 3, but gives no indication that it is not also in this infinite loop.
Any ideas? Thank you.
Having the same issue. Building with
rm -rf build/ && cmake -S. -Bbuild/ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -GNinja -DCLANG_INCLUDE_DIRS=/home/toby/micromamba/envs/for-zig/ && ninja -Cbuild/
in a dedicated conda env on WSL.
FAILED: zig2
: && /home/toby/micromamba/envs/for-zig/bin/g++ -g -Wl,-z,stack-size=0x10000000 CMakeFiles/zig2.dir/zig2.c.o CMakeFiles/zig2.dir/compiler_rt.c.o -o zig2 zigcpp/libzigcpp.a /home/toby/micromamba/envs/for-zig/lib/libclang-cpp.so.19.1 /home/toby/micromamba/envs/for-zig/lib/liblldMinGW.a /home/toby/micromamba/envs/for-zig/lib/liblldELF.a /home/toby/micromamba/envs/for-zig/lib/liblldCOFF.a /home/toby/micromamba/envs/for-zig/lib/liblldWasm.a /home/toby/micromamba/envs/for-zig/lib/liblldMachO.a /home/toby/micromamba/envs/for-zig/lib/liblldCommon.a -lLLVM-19 -lrt -ldl -lpthread -lm -lz -lzstd -lxml2 -lpthread -lm -lz -lzstd -lxml2 && :
/home/toby/micromamba/envs/for-zig/bin/../lib/gcc/x86_64-conda-linux-gnu/14.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: CMakeFiles/zig2.dir/zig2.c.o: in function `posix_getrandom__2630':
/home/toby/git/zig/build/zig2.c:722471:(.text+0x47efee): undefined reference to `getrandom'
/home/toby/micromamba/envs/for-zig/bin/../lib/gcc/x86_64-conda-linux-gnu/14.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: CMakeFiles/zig2.dir/zig2.c.o: in function `posix_copy_file_range__2848':
/home/toby/git/zig/build/zig2.c:752526:(.text+0x4cc40d): undefined reference to `copy_file_range'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.