rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.17k stars 888 forks source link

unable to build powerpc gnuspe tier 3 arch support #3531

Closed th0ma7 closed 11 months ago

th0ma7 commented 12 months ago

Problem

Long-story short, maintainer for SynoCommunity which provides opensource package for using on Synology Linux based NAS.

in order for some of our packages to work out on Synology popwerpc qoriq I require to use powerpc-linux-gnuspe as otherwise resulting binaries do not work.

Using https://github.com/SynoCommunity/spksrc framwork along with associated Synology toolchain for this specifc arch I was able to build a stage1 compiler. The hope is then, using this stage1 build, to enable full support for the gnuspe variant.

It occurs that using the default Synology gcc cross-compiler I'm able to get close to the finish line but ends-up failing at rustc_llvm v0.0.0:

error: failed to run custom build command for `rustc_llvm v0.0.0 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/compiler/rustc_llvm)`

Caused by:
  process didn't exit successfully: `/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/target/debug/build/rustc_llvm-b45326f0c9a9f4b3/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-check-cfg=values(llvm_component,"ipo")
  cargo:rustc-check-cfg=values(llvm_component,"bitreader")
  cargo:rustc-check-cfg=values(llvm_component,"bitwriter")
  cargo:rustc-check-cfg=values(llvm_component,"linker")
  cargo:rustc-check-cfg=values(llvm_component,"asmparser")
  cargo:rustc-check-cfg=values(llvm_component,"lto")
  cargo:rustc-check-cfg=values(llvm_component,"coverage")
  cargo:rustc-check-cfg=values(llvm_component,"instrumentation")
  cargo:rustc-check-cfg=values(llvm_component,"x86")
  cargo:rustc-check-cfg=values(llvm_component,"arm")
  cargo:rustc-check-cfg=values(llvm_component,"aarch64")
  cargo:rustc-check-cfg=values(llvm_component,"amdgpu")
  cargo:rustc-check-cfg=values(llvm_component,"avr")
  cargo:rustc-check-cfg=values(llvm_component,"loongarch")
  cargo:rustc-check-cfg=values(llvm_component,"m68k")
  cargo:rustc-check-cfg=values(llvm_component,"csky")
  cargo:rustc-check-cfg=values(llvm_component,"mips")
  cargo:rustc-check-cfg=values(llvm_component,"powerpc")
  cargo:rustc-check-cfg=values(llvm_component,"systemz")
  cargo:rustc-check-cfg=values(llvm_component,"jsbackend")
  cargo:rustc-check-cfg=values(llvm_component,"webassembly")
  cargo:rustc-check-cfg=values(llvm_component,"msp430")
  cargo:rustc-check-cfg=values(llvm_component,"sparc")
  cargo:rustc-check-cfg=values(llvm_component,"nvptx")
  cargo:rustc-check-cfg=values(llvm_component,"hexagon")
  cargo:rustc-check-cfg=values(llvm_component,"riscv")
  cargo:rustc-check-cfg=values(llvm_component,"bpf")
  cargo:rerun-if-env-changed=RUST_CHECK
  cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR

  --- stderr
  thread 'main' panicked at compiler/rustc_llvm/build.rs:51:59:
  REAL_LIBRARY_PATH_VAR
  stack backtrace:
     0:     0x55a9e11a886c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3a50fc05234dc25f
     1:     0x55a9e11ea7c0 - core::fmt::write::h41e83b57b87e9771
     2:     0x55a9e119c7ef - std::io::Write::write_fmt::hdce39c9ad9841766
     3:     0x55a9e11a866c - std::sys_common::backtrace::print::h1bfd62876611aa97
     4:     0x55a9e11ccfda - std::panicking::default_hook::{{closure}}::h17c46ac087e88546
     5:     0x55a9e11ccdc0 - std::panicking::default_hook::h13666b4b062ac951
     6:     0x55a9e11cd49e - std::panicking::rust_panic_with_hook::hb9aabda64d0504fc
     7:     0x55a9e11a8e1b - std::panicking::begin_panic_handler::{{closure}}::h18e358aab0160522
     8:     0x55a9e11a8ab6 - std::sys_common::backtrace::__rust_end_short_backtrace::hf22579d6416687c0
     9:     0x55a9e11cd192 - rust_begin_unwind
    10:     0x55a9e112bd15 - core::panicking::panic_fmt::h91a39003a918ef49
    11:     0x55a9e112c353 - core::option::expect_failed::hdbc0e8de051845fc
    12:     0x55a9e1134edc - core::option::Option<T>::expect::h34ee4a792f3f1965
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/library/core/src/option.rs:894:21
    13:     0x55a9e112f762 - build_script_build::restore_library_path::hb2e1b7e64585ae13
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/compiler/rustc_llvm/build.rs:51:15
    14:     0x55a9e11303aa - build_script_build::main::h4fb266cde9fc8990
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/compiler/rustc_llvm/build.rs:113:5
    15:     0x55a9e112e5db - core::ops::function::FnOnce::call_once::h6b3a5c50542d0a48
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/library/core/src/ops/function.rs:250:5
    16:     0x55a9e112cc4e - std::sys_common::backtrace::__rust_begin_short_backtrace::h40a50028a2668c98
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/library/std/src/sys_common/backtrace.rs:154:18
    17:     0x55a9e1138e61 - std::rt::lang_start::{{closure}}::h80c94b634fc1a781
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/library/std/src/rt.rs:167:18
    18:     0x55a9e11cd036 - std::panicking::try::h8c98e8bc60bce26a
    19:     0x55a9e11b59e6 - std::rt::lang_start_internal::h1dd4610c6c6ac6b9
    20:     0x55a9e1138e3a - std::rt::lang_start::h8f7adb4b55347857
                                 at /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/library/std/src/rt.rs:166:17
    21:     0x55a9e113409e - main
    22:     0x7fed4f033d0a - __libc_start_main
    23:     0x55a9e112c50a - _start
    24:                0x0 - <unknown>
warning: build failed, waiting for other jobs to finish...
make[2]: *** [../../mk/spksrc.tc-rust.mk:62: rustc_target] Error 101
/home/spksrc/qoriq-debug/spksrc/cross/bat/work-qoriq-6.2.4/tc_vars.mk:1: *** An error occured while setting up the toolchain, please check the messages above.  Stop.
make[1]: Leaving directory '/home/spksrc/qoriq-debug/spksrc/cross/bat'

So I tried using an alternative option with clang and proper arch parameters -mcpu=e500v2 -mhard-float --sysroot=<mysysrootpath> but it fails a little earlier than with gcc at libffi:

 checking for powerpc-unknown-linux-gnuspe-gcc... clang-13
  checking whether the C compiler works... no

Steps

  1. presuming having a compatible spksrc container (docker/lxc)
  2. using changes I'm working on to force building powerpc gnuspe support (not yet uploaded online, associated PR being https://github.com/SynoCommunity/spksrc/pull/5879)
  3. stage1 build - assuming $(RUST_TARGET) is powerpc-unknown-linux-gnuspe:
    
        @$(MSG) "Building Tier 3 rust target: $(RUST_TARGET)"
        (cd $(WORK_DIR) && [ ! -d rust ] && git clone --depth 1 https://github.com/rust-lang/rust.git)
        (cd $(WORK_DIR)/rust && ./x setup compiler)
        (cd $(WORK_DIR)/rust && PATH=$(WORK_DIR)/$(TC_TARGET)/bin:$${PATH} ./x build --target $(RUST_TARGET))
        @$(MSG) "Building Tier 3 rust target: $(RUST_TARGET) - stage1 complete"
    ...
    Finished release [optimized] target(s) in 45.13s
    Build completed successfully in 0:07:37
    rustup toolchain link powerpc-stage1 /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/build/host/stage1
    ===>  Building Tier 3 rust target: powerpc-unknown-linux-gnuspe - stage1 complete
    rustup show
    Default host: x86_64-unknown-linux-gnu
    rustup home:  /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/../../distrib/rustup

installed toolchains

stable-x86_64-unknown-linux-gnu (default) nightly-x86_64-unknown-linux-gnu powerpc-stage1

active toolchain

nightly-x86_64-unknown-linux-gnu (directory override for '/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4') rustc 1.75.0-nightly (7adc89b69 2023-11-07)

rustup override set nightly info: using existing install for 'nightly-x86_64-unknown-linux-gnu' info: override toolchain for '/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4' set to 'nightly-x86_64-unknown-linux-gnu'

nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.75.0-nightly (7adc89b69 2023-11-07)

4. gnuspe arch build:

(cd /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust && PATH="/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/powerpc-e500v2-linux-gnuspe/bin:${PATH}" POWERPC_UNKNOWN_LINUX_GNUSPE_OPENSSL_DIR=/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/../../../toolkit/syno-qoriq-6.2.4/work/usr/ TARGET_CFLAGS="-mcpu=8548 -mhard-float -mfloat-gprs=double --sysroot=/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/powerpc-e500v2-linux-gnuspe/powerpc-e500v2-linux-gnuspe/sysroot" RUST_BACKTRACE=full cargo +powerpc-stage1 build -Zbuild-std=core,alloc --target powerpc-unknown-linux-gnuspe) Compiling compiler_builtins v0.1.103 Compiling core v0.0.0 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core) Compiling proc-macro2 v1.0.63 ... Compiling libffi-sys v2.3.0 Compiling rustversion v1.0.12 Compiling either v1.8.1 Compiling mime v0.3.17 Compiling itertools v0.10.5 Compiling libm v0.2.7 Compiling clippy v0.1.75 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/src/tools/clippy) Compiling rustc_llvm v0.0.0 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/compiler/rustc_llvm) Compiling curl v0.4.44 Compiling miri v0.1.0 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/src/tools/miri) error: failed to run custom build command for rustc_llvm v0.0.0 (/home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/compiler/rustc_llvm)

Caused by: process didn't exit successfully: /home/spksrc/qoriq-debug/spksrc/toolchain/syno-qoriq-6.2.4/work/rust/target/debug/build/rustc_llvm-b45326f0c9a9f4b3/build-script-build (exit status: 101) --- stdout ...


### Possible Solution(s)

A few ideas:
1. perhaps there are additional flags I could use over the tier 2 powerpc-linux-gnu that could make things to work out on `qoriq` without having to build gnuspe support?  Currently tried `-Ctarget-cpu=e500` and still failed.
2. fixing the build issue so it's possible to use Synology provided gcc version 4.9.x?
3. there may be a way to support clang on the libffi portion of the build (although it may fail later-on)?

### Notes

- Possibly related hints https://github.com/rust-lang/rust/issues/96394
- Hopefully not duplicating the bug issue database, https://github.com/rust-lang/rust/issues/117361

Synocommunity related bugs:
- https://github.com/SynoCommunity/spksrc/issues/5847
- https://github.com/SynoCommunity/spksrc/issues/5684

### Rustup version

```console
$ RUSTUP_HOME=/home/spksrc/qoriq-debug/spksrc/distrib/rustup CARGO_HOME=/home/spksrc/qoriq-debug/spksrc/distrib/cargo PATH=/home/spksrc/qoriq-debug/spksrc/distrib/cargo/bin:$PATH rustup --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.73.0 (cc66ad468 2023-10-03)`

### Installed toolchains

```console
RUSTUP_HOME=/home/spksrc/qoriq-debug/spksrc/distrib/rustup CARGO_HOME=/home/spksrc/qoriq-debug/spksrc/distrib/cargo PATH=/home/spksrc/qoriq-debug/spksrc/distrib/cargo/bin:$PATH rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/spksrc/qoriq-debug/spksrc/distrib/rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
powerpc-stage1

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.73.0 (cc66ad468 2023-10-03)
djc commented 11 months ago

It's a little unclear to me why you filed this as a rustup issue, it seems more like rust-lang/rust issue?

rami3l commented 11 months ago

It's a little unclear to me why you filed this as a rustup issue, it seems more like rust-lang/rust issue?

Yes, as I already replied on Discord:

I don't think you should file that issue in Rustup... Rather, you can try to transfer that issue to Rust.

I think it's appropriate to close this issue now for archiving purposes, and the discussion on this issue should be redirected to https://github.com/rust-lang/rust/issues/117361.