rust-lang / rust-lang/rust

Cross-compilation default settings do not work, only show obscure error messages

Open
#143,184 22 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cross A-diagnostics A-driver C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I am trying to use the GHA aarch64-unknown-linux-gnu runners to build and run my code for armv7-unknown-linux-gnueabihf. Since my code depends on the rustc crates, I cannot do actual cross-compilation. Instead, I am installing the armv7-unknown-linux-gnueabihf version of rustc on that system. rustc itself runs successfully since I installed enough multiarch packages. However, Rust fails to actually build any binaries in this setup (specifically, it fails to build the build scripts):

  error: linking with `cc` failed: exit status: 1
    |
    = note:  "cc" "/tmp/rustcWH48QS/symbols.o" "<4 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcWH48QS/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "-o" "/home/runner/work/miri/miri/target/release/build/libc-3375c08ac196722c/build_script_build-3375c08ac196722c" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-rpath,<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib"
    = note: some arguments are omitted. use `--verbose` to show all linker arguments
    = note: /usr/bin/ld: /tmp/rustcWH48QS/symbols.o: error adding symbols: file in wrong format
            collect2: error: ld returned 1 exit status
            
  
  error: could not compile `libc` (build script) due to 1 previous error
  warning: build failed, waiting for other jobs to finish...
  error: linking with `cc` failed: exit status: 1
    |
    = note:  "cc" "/tmp/rustcwYoYoY/symbols.o" "<4 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcwYoYoY/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "-o" "/home/runner/work/miri/miri/target/release/build/zerocopy-f22a37c7a8ae1a41/build_script_build-f22a37c7a8ae1a41" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-rpath,<sysroot>/lib/rustlib/armv7-unknown-linux-gnueabihf/lib"
    = note: some arguments are omitted. use `--verbose` to show all linker arguments
    = note: /usr/bin/ld: /tmp/rustcwYoYoY/symbols.o: error adding symbols: file in wrong format
            collect2: error: ld returned 1 exit status
            
  
  error: could not compile `zerocopy` (build script) due to 1 previous error

I have no idea about any of the internals here, but I suspect that cc needs to be told that this is a cross-compilation situation, since the host cc will by default build for aarch64-unknown-linux-gnu but rustc is building for armv7-unknown-linux-gnueabihf. I tried to set the CC env var to arm-linux-gnueabihf-gcc but that changed nothing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the armv7-unknown-linux-gnueabihf build on the aarch64-unknown-linux-gnu GHA runner, including the failed build scripts and the attempted CC=arm-linux-gnueabihf-gcc setting. Start with rustc's cross-compilation and linking configuration entry points; done means the setup avoids the host linker mismatch or reports a useful diagnostic when configuration is incomplete.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, linux, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.