Linker error when building rust toolchain on x86_64 to target and run on i586 machines

Hello all.

I'm attempting to compile the Rust toolchain to target and run on a really old computer (AMD K6-2+/500), but build it on my modern desktop (Threadripper 1950X). This is part of adding xorg to the Gentoo image I have going for it, and I need a Rust toolchain as spidermonkey uses Rust and is apparently a dependency of polkit these days, which is a dependency of pam, which is a dependency of elogind, and so on. The default Gentoo Rust scripts don't seem to understand i586 and end up building an i686 toolchain instead, meaning all the Rust programs try to run SSE and SSE2 instructions. So here I am building from source manually so I can understand the whole process first, then hack up dev-lang/rust-bin to install my custom one.

I cloned rust from GitHub, checked out the 1.56.1 tag, updated and init'd the submodules, and ran the setup script. Rust doesn't seem to be too happy about trying to compile 32-bit toolchains with a 64-bit rust compiler, so we set the build toolchain as i686 and the run host and target to i586.

# set target and host to i586-unknown-linux-gnu, generates config.toml
./x.py setup --build i686-unknown-linux-gnu --host i586-unknown-linux-gnu --target i586-unknown-linux-gnu -j 32

# build toolchain
./x.py dist --build i686-unknown-linux-gnu --host i586-unknown-linux-gnu --target i586-unknown-linux-gnu -j 32

It runs for about 15 minutes before failing to link when building the stage1 compiler artifacts. The symbols it's complaining about suggest an unsatisfied dependency on zlib.

Building stage1 compiler artifacts (i686-unknown-linux-gnu -> i586-unknown-linux-gnu)
   Compiling rustc-main v0.0.0 (/home/nlewis/Sources/rust/compiler/rustc)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m32" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/rustc_main-8dca1282a3ea6fe5.rustc_main.049335a6-cgu.0.rcgu.o" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/rustc_main-8dca1282a3ea6fe5.rustc_main.049335a6-cgu.1.rcgu.o" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/rustc_main-8dca1282a3ea6fe5.rustc_main.049335a6-cgu.2.rcgu.o" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/rustc_main-8dca1282a3ea6fe5.rustc_main.049335a6-cgu.3.rcgu.o" "-Wl,--as-needed" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/release/deps" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/build/psm-575ab1ac3c62167e/out" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/build/rustc_llvm-a25318d4dac0e88d/out" "-L" "/home/nlewis/Sources/rust/build/i586-unknown-linux-gnu/llvm/build/lib" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1/lib/rustlib/i586-unknown-linux-gnu/lib" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps" "-lrustc_driver-758e2c9545688f16" "-Wl,--start-group" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1/lib/rustlib/i586-unknown-linux-gnu/lib" "-lstd-13a451e692cd4b84" "-Wl,--end-group" "-Wl,-Bstatic" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1/lib/rustlib/i586-unknown-linux-gnu/lib/libcompiler_builtins-c6f3a48116e83ade.rlib" "-Wl,-Bdynamic" "-lstdc++" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1/lib/rustlib/i586-unknown-linux-gnu/lib" "-o" "/home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/rustc_main-8dca1282a3ea6fe5" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-Wl,-rpath,$ORIGIN/../lib"
  = note: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: /home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/librustc_driver-758e2c9545688f16.so: undefined reference to `uncompress'
          /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: /home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/librustc_driver-758e2c9545688f16.so: undefined reference to `compress2'
          /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: /home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/librustc_driver-758e2c9545688f16.so: undefined reference to `crc32'
          /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: /home/nlewis/Sources/rust/build/i686-unknown-linux-gnu/stage1-rustc/i586-unknown-linux-gnu/release/deps/librustc_driver-758e2c9545688f16.so: undefined reference to `compressBound'
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `rustc-main` due to previous error
Build completed unsuccessfully in 0:00:49

Does anyone know what I'm missing here?

This seems to be an as of yet unknown problem (to me) resulting from my build environment.

Compiling rust this way worked perfectly fine from the i386 Ubuntu 20.04 docker container (i386/ubuntu:20.04), which required the packages build-essential, curl, git, ninja-build, cmake, python3, pkg-config, and libssl-dev iirc). You also have to set PKG_CONFIG_ALLOW_CROSS=1.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.