Repository: bitcoin
Issue: build: depends cros-compile using Clang fails
Labels: Build system

Seems like CMake is getting confused, and trying to build and link a `x86_64` binary, when it's meant to be (and thinks it is, according to the  configure output) building for `aarch64`:
```bash
make -C depends/ CC=clang CXX=clang++ AR=llvm-ar NM=llvm-nm RANLIB=llvm-ranlib STRIP=llvm-strip NO_QT=1 NO_WALLET=1 NO_USDT=1 NO_ZMQ=1 -j18 HOST=aarch64-linux-gnu
<snip>
copying packages: boost libevent
to: /root/ci_scratch/depends/aarch64-linux-gnu
To build Bitcoin Core with these packages, pass '--toolchain /root/ci_scratch/depends/aarch64-linux-gnu/toolchain.cmake' to the first CMake invocation.

cmake -B build --toolchain /root/ci_scratch/depends/aarch64-linux-gnu/toolchain.cmake
<snip>
Cross compiling ....................... TRUE, for Linux, aarch64
C++ compiler .......................... Clang 18.1.3, /usr/bin/clang++
<snip>
cmake --build build -j18 --target bitcoind --verbose
[ 98%] Linking CXX executable bitcoind
cd /root/ci_scratch/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/bitcoind.dir/link.txt --verbose=1
/usr/bin/clang++ -pipe -std=c++20 -O2 -O2 -g -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -fPIE -pie CMakeFiles/bitcoind.dir/bitcoind.cpp.o CMakeFiles/bitcoind.dir/init/bitcoind.cpp.o -o bitcoind  libbitcoin_node.a libbitcoin_common.a libbitcoin_consensus.a secp256k1/lib/libsecp256k1.a util/libbitcoin_util.a crypto/libbitcoin_crypto.a crypto/libbitcoin_crypto_sse41.a crypto/libbitcoin_crypto_avx2.a crypto/libbitcoin_crypto_x86_shani.a ../libleveldb.a ../libcrc32c.a ../libcrc32c_sse42.a ../libminisketch.a univalue/libunivalue.a /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_pthreads.a /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_core.a  
/usr/bin/ld: /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a(http.c.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a(http.c.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a(http.c.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a(http.c.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a: error adding symbols: file in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [src/CMakeFiles/bitcoind.dir/build.make:130: src/bitcoind] Error 1
```
Maybe there's something missing from the toolchain that we should be passing through. The libs in depends have been compiled for aarch64, i.e:
```bash
objdump -x /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a | grep aarch64
In archive /root/ci_scratch/depends/aarch64-linux-gnu/lib/libevent_extra.a:
event_tagging.c.o:     file format elf64-littleaarch64
architecture: aarch64, flags 0x00000011:
http.c.o:     file format elf64-littleaarch64
```

However CMake is building x86_64 object files:
```bash
file build/CMakeFiles/leveldb.dir/src/leveldb/db/filename.cc.o
build/CMakeFiles/leveldb.dir/src/leveldb/db/filename.cc.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
```
and binaries:
```bash
file build/src/bitcoin-util 
build/src/bitcoin-util: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=4ccab1d492154df5dd9a115e6bbc52371d7439b1, for GNU/Linux 3.2.0, with debug_info, not stripped
```