Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustc cross-compiling to aarch64-unknown-linux-gnu uses wrong compiler #82519

Closed
ghost opened this issue Feb 25, 2021 · 6 comments
Closed

Rustc cross-compiling to aarch64-unknown-linux-gnu uses wrong compiler #82519

ghost opened this issue Feb 25, 2021 · 6 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Feb 25, 2021

Cross compiling from x86_64 to aarch64 uses /usr/bin/ld instead of /usr/bin/aarch64-linux-gnu-ld
This happens using stable and nightly version of rust toolchians/targets

Code

any simple code

fn main() {
    println!("a message");
}

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (a15f484b9 2021-02-22)
binary: rustc
commit-hash: a15f484b918a4533ad633ea903ccce82910af342
commit-date: 2021-02-22
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

RUST_BACKTRACE=1 cargo build --target aarch64-unknown-linux-gnu

  = note: /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/avery/Documents/git/plage/target/aarch64-unknown-linux-gnu/debug/deps/plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status

file plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o

plage-7843fadef320354a.1115kt21cxrb61jx.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped

@ghost ghost added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2021
@ghost
Copy link
Author

ghost commented Feb 25, 2021

The issue comes from it using the wrong cc compiler. It prints out a very long command before the errors using "cc", copying it and changing cc to aarch64-linux-gnu-gcc works without any errors. This means rustc is calling the wrong compiler.

@ghost ghost changed the title Rustc cross-compiling to aarch64-unknown-linux-gnu uses /usr/bin/ld Rustc cross-compiling to aarch64-unknown-linux-gnu uses wrong compiler Feb 25, 2021
@jonas-schievink jonas-schievink removed the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 25, 2021
@nagisa

This comment has been minimized.

@nagisa
Copy link
Member

nagisa commented Feb 25, 2021

Ah, my bad, I missed that this is not about rustbuild, but about using rustc in crosscompiling regular programs.

As far as I know there are no such heuristics when invoking plain rustc. It is a responsibility of the user to specify the linkers etc to use (via e.g. -Clinker when invoking rustc directly and via corresponding configuration in cargo when building via cargo).

@ghost
Copy link
Author

ghost commented Feb 25, 2021

  [target.aarch64-unknown-linux-gnu]
  linker = "aarch64-linux-gnu-ld"

cargo +nightly b --target aarch64-unknown-linux-gnu

still uses the incorrect compiler and linker (cc & /usr/bin/ld)

@nagisa
Copy link
Member

nagisa commented Feb 25, 2021

That would mean its either a bug in cargo, or cargo can't find your cargo config (as documented here). Where did you put the file with these contents?

Another caveat is that you want to use aarch64-linux-gnu-cc as your linker, rather than the bare ld – there is a way to use ld (-Clinker-flavor=ld), but by default we rely on cc to do the job of finding the libraries, etc.

@ghost
Copy link
Author

ghost commented Feb 25, 2021

Cargo.toml works now. Thank you for the help.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants