Skip to content

Cross-compiling from aarch64 to x86_64 fails (unrecognized command-line option '-m64) #119500

Closed as not planned
@erikschul

Description

@erikschul

Setup code
The runner should ideally setup correctly on either platform, and compile to either target.
Using debian12, running in docker.
Using cross is not an option (docker-in-docker etc.).

apt-get install -y gcc make \
    gcc-aarch64-linux-gnu \
    gcc-i686-linux-gnu \
    gcc-arm-linux-gnueabi \
    binutils \
    binutils-aarch64-linux-gnu \
    g++-aarch64-linux-gnu \
    g++-x86-64-linux-gnu \
    libc6-dev-arm64-cross

rustup update
rustup target add x86_64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-gnu

Error

cargo build --target=x86_64-unknown-linux-gnu

fails with

cc: error: unrecognized command-line option '-m64'

which makes sense if it's using cc, which only supports these targets:
cc -E -march=help -xc /dev/null

# 0 "/dev/null"
cc1: error: unknown value ‘help’ for ‘-march’
cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a native

So I tried installing x86-64 gcc and setting it:

export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc

but its valid targets are:

nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client rocketlake icelake-server cascadelake tigerlake cooperlake sapphirerapids alderlake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm x86-64 x86-64-v2 x86-64-v3 x86-64-v4 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 znver3 btver1 btver2

so I need to change the target to -mx86-64.

I tried overriding with RUSTFLAGS but that didn't work.

Problem

  • how can I override the -m target?
  • is there a better way?

Alternatives
It works with zigbuild: (I haven't tried to run the x86_64 binary)

cargo install cargo-zigbuild
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17
cargo zigbuild --target x86_64-unknown-linux-gnu.2.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions