Hi, I’m attempting to build the zig compiler from source, and consistently run into this error:
fatal linker error: unhandled relocation type R_X86_64_PC64
This happens when I build from source using cmake and the system C, Clang, LLVM, etc. I’ve verified that all the dependencies are installed with compatible versions, and reproduced this on multiple commits on master. The failure seems to happen when the stage 2 compiler is building the stage 3 compiler.
[100%] Building stage3
install
└─ install zig
└─ compile exe zig Debug native 2 errors
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x1c
note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x2c
note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
error: 2 compilation errors
failed command: /home/abs/workspace/zig/build/zig2 build-exe -fallow-so-scripts --stack 48234496 /home/abs/workspace/zig/build/zigcpp/libzigcpp.a /usr/lib/libclang-cpp.so.21.1 /usr/lib/liblldMinGW.so /usr/lib/liblldELF.so /usr/lib/liblldCOFF.so /usr/lib/liblldWasm.so /usr/lib/liblldMachO.so /usr/lib/liblldCommon.so -lLLVM-21 /usr/lib/libstdc++.so -lunwind -fno-sanitize-thread -ODebug -I /usr/include -I /usr/include -L /usr/lib --dep aro --dep build_options -Mroot=/home/abs/workspace/zig/src/main.zig -Maro=/home/abs/workspace/zig/lib/compiler/aro/aro.zig -Mbuild_options=.zig-cache/c/c59001929ba6452ad1c9a5223a5cf30b/options.zig -lc --cache-dir .zig-cache --global-cache-dir /home/abs/.cache/zig --name zig --zig-lib-dir lib/ --listen=-
It also happens when I try to build zig-bootstrap, in the final step in the build when we are rebuilding the compiler for the target architecture:
install
└─ install generated to doc/langref.html
└─ run exe docgen (langref.html)
└─ WriteFile Assembly Syntax Explained.out
└─ run exe doctest (verbose_cimport_flag.out) failure
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x1c
note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x2c
note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
I’ve tried all the following all of the following commands for zig-bootstrap:
- ./build native-linux-gnu native
- ./build native-linux-gnu znver4
- ./build x86_64-linux-gnu znver4
- ./build x86_64-linux-musl znver4
I’ve sanity checked that a basic hello world zig program compiles fine when using a prebuilt. I’m running this on an arch based, 64-bit system with an AMD 7700X cpu. Any help figuring this out would be appreciated!