cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.53k stars 365 forks source link

binutils too old to be compatible with recent nightlies #1319

Open CryZe opened 1 year ago

CryZe commented 1 year ago

Checklist

Describe your issue

Recent Rust nightlies require a newer linker version:

  = note: LC_ALL="C" PATH="/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/rust/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcaQRPRI/symbols.o" "/target/debug/build/libc-f32428b039fdb8c6/build_script_build-f32428b039fdb8c6.build_script_build.234a671006178bd0-cgu.0.rcgu.o" "/target/debug/build/libc-f32428b039fdb8c6/build_script_build-f32428b039fdb8c6.build_script_build.234a671006178bd0-cgu.1.rcgu.o" "/target/debug/build/libc-f32428b039fdb8c6/build_script_build-f32428b039fdb8c6.build_script_build.234a671006178bd0-cgu.2.rcgu.o" "/target/debug/build/libc-f32428b039fdb8c6/build_script_build-f32428b039fdb8c6.2l6typj27svajb46.rcgu.o" "-Wl,--as-needed" "-L" "/target/debug/deps" "-L" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-19964a87984cce8a.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-0ad64a60ea2c4aaa.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-37a5cbc9c5c20c04.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-e8cedd2960ff146a.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-5deb081ad96d9130.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-22c964fd8f2dfaf9.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-6971442fd1c2cfbb.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-ec7906ee77b1d540.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-4307a3ebc7f0bfcf.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-c2ab156d57b93da1.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-763bbb8717f828b7.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-eb9ba65f17380c5d.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-4286d0bf3addfc05.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fa17a4d002f91ad9.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ff4ae84067796be3.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-6f47c72c85a10103.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-cd2f2bc505f56f50.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-ec02dd343723da85.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-4df0073ab5846ddb.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/target/debug/build/libc-f32428b039fdb8c6/build_script_build-f32428b039fdb8c6" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: /usr/bin/ld: /rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-19964a87984cce8a.rlib(std-19964a87984cce8a.std.f6dab3b182b9be26-cgu.0.rcgu.o): TLS transition from R_X86_64_TLSLD to R_X86_64_TPOFF32 against `_ZN3std9panicking11panic_count17LOCAL_PANIC_COUNT7__getit3VAL17h178ac08236b8843dE.0' at 0x5af in section `.text._ZN3std2rt19lang_start_internal17h1dd1442605b126fbE' failed
          /rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-19964a87984cce8a.rlib: error adding symbols: Bad value
          collect2: error: ld returned 1 exit status

cross seems to use GNU ld (GNU Binutils for Ubuntu) 2.26.1 on the problematic targets. I don't know which version resolves the problem, but I do know that the problem goes away with the latest version.

What target(s) are you cross-compiling for?

x86_64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5, cargo 1.74.0-nightly (2cc50bc0b 2023-08-22)

Example

cross +nightly build --target x86_64-unknown-linux-gnu

Additional information / notes

Rust issue https://github.com/rust-lang/rust/issues/115239

Emilgardis commented 1 year ago

the latest images works, using ld 2.34

$ CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_IMAGE="ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main" \ 
  cross-util run --target x86_64-unknown-linux-gnu -- "ld --version"
GNU ld (GNU Binutils for Ubuntu) 2.34

Make sure that ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main is actually updated, cross doesn't pull in the latest images for a tag like main/edge

$ docker pull ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main
docker pull ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main
main: Pulling from cross-rs/x86_64-unknown-linux-gnu
edaedc954fb5: Already exists           
3ba6a39e216b: Pull complete
ceb9f63710c9: Pull complete
b09634800521: Pull complete
6c70d1c0e806: Pull complete
8b1d4c95c4a4: Pull complete
c710eb4c7c4b: Pull complete
da0191c7c407: Pull complete
0e1376e6048d: Pull complete
fb5bccee428c: Pull complete
913a127e772e: Pull complete
44e47dfe46b9: Pull complete
2a23a22cb021: Pull complete
f204b9544051: Pull complete
Digest: sha256:30235811948871aef514c986f0f991fa9b56385910210038d8354e9bf63d06e2
Status: Downloaded newer image for ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main
ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main
$ docker image ls ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main     
REPOSITORY                                  TAG       IMAGE ID       CREATED        SIZE
ghcr.io/cross-rs/x86_64-unknown-linux-gnu   main      396b40224753   38 hours ago   1.46GB

To solve this, you can either use below workaround to update the image cross uses, or use cross installed from main (and ensuring that the image is updated).

Quick workaround for users on 0.2.5, note that cross 0.2.5 has Ubuntu 16.04, newer cross uses Ubuntu 20.04.

env:

# set to latest image
CROSS_TARGET_X86_64_UNKNOWN_LINUX_GNU_IMAGE=ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main

config:

# Cross.toml
[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"

Or

# Cargo.toml
[package.metadata.cross.target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"
Emilgardis commented 1 year ago

closed by accident

VorpalBlade commented 1 year ago

Upgrading the default distro is however not a great idea either. Since you need to build on a sufficiently old version of glibc to not get errors when trying to run the binary on other distros (notably: stable Debian, RHEL/CentOS). Some care is needed to ensure that this doesn't break.

Emilgardis commented 1 year ago

We provide a unknown-linux-gnu centos7 images to make this easier, however it uses ld 2.27

[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main-centos"

we also have integration with cargo-zigbuild which lets you choose glibc version, https://github.com/cross-rs/cross/wiki/Configuration#buildzig