ziglang / zig-bootstrap

take off every zig
368 stars 86 forks source link

zstd link errors while cross-compiling to `x86_64-linux-musl` from macos #136

Closed lun-4 closed 1 year ago

lun-4 commented 1 year ago

Running from Mac OS 12: ./build -j12 x86_64-linux-musl baseline

It compiled LLVM for the host, Zig for the host, LLVM for the target, but failed on the last step: Zig for the target (added -x to set for the debug command output).

+ cd .../zig-bootstrap/zig
+ .../zig-bootstrap/out/host/bin/zig build --prefix .../zig-bootstrap/out/zig-x86_64-linux-musl-baseline --search-prefix .../zig-bootstrap/out/x86_64-linux-musl-baseline -Dstatic-llvm -Drelease -Dstrip -Dtarget=x86_64-linux-musl -Dcpu=baseline -Dversion-string=0.10.0-dev.4560+828735ac0 -Denable-stage1
LLD Link... ld.lld: error: undefined symbol: ZSTD_compressBound
>>> referenced by Compression.cpp:113 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:113)
>>>               Compression.cpp.o:(llvm::compression::zstd::compress(llvm::ArrayRef<unsigned char>, llvm::SmallVectorImpl<unsigned char>&, int)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a

ld.lld: error: undefined symbol: ZSTD_compress
>>> referenced by Compression.cpp:116 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:116)
>>>               Compression.cpp.o:(llvm::compression::zstd::compress(llvm::ArrayRef<unsigned char>, llvm::SmallVectorImpl<unsigned char>&, int)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a

ld.lld: error: undefined symbol: ZSTD_isError
>>> referenced by Compression.cpp:118 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:118)
>>>               Compression.cpp.o:(llvm::compression::zstd::compress(llvm::ArrayRef<unsigned char>, llvm::SmallVectorImpl<unsigned char>&, int)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a
>>> referenced by Compression.cpp:136 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:136)
>>>               Compression.cpp.o:(llvm::compression::zstd::uncompress(llvm::ArrayRef<unsigned char>, unsigned char*, unsigned long&)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a

ld.lld: error: undefined symbol: ZSTD_decompress
>>> referenced by Compression.cpp:130 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:130)
>>>               Compression.cpp.o:(llvm::compression::zstd::uncompress(llvm::ArrayRef<unsigned char>, unsigned char*, unsigned long&)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a

ld.lld: error: undefined symbol: ZSTD_getErrorName
>>> referenced by Compression.cpp:136 (.../zig-bootstrap/llvm/lib/Support/Compression.cpp:136)
>>>               Compression.cpp.o:(llvm::compression::zstd::uncompress(llvm::ArrayRef<unsigned char>, unsigned char*, unsigned long&)) in archive .../zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libLLVMSupport.a
error: FileNotFound

The libzstd.a archive that is in the --search-prefix does contain symbols that the linker called missing, like ZSTD_compress:

$ nm ./zig-bootstrap/out/x86_64-linux-musl-baseline/lib/libzstd.a | grep 'ZSTD_compress'
[...]
00000000000059a0 T ZSTD_compress
[...]
andrewrk commented 1 year ago

Perhaps this is the commit you need? https://github.com/ziglang/zig/pull/13299/commits/8fc7b4d1401a70358bf54023363178d9c3e1f9de

It's part of https://github.com/ziglang/zig/pull/13299 which I'm planning to merge as soon as passes the CI.

lun-4 commented 1 year ago

That sounds about it, will test once I'm available! The compile times are a monster against time itself.

andrewrk commented 1 year ago

Indeed. You're talking to someone who built LLVM 7 times today alone

lun-4 commented 1 year ago

The mentioned commit is for CMake, not build.zig, so the one I cherry picked was https://github.com/ziglang/zig/pull/13299/commits/73c2e91a0dee356048898d5b72e01969af9097e3. That fixes the mentioned error!

On unrelated news, screenie-2022-10-26-14_01_03