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

Failed to build on armv7 musl target on Alpine Linux #415

Closed
messense opened this issue Sep 27, 2022 · 14 comments
Closed

Failed to build on armv7 musl target on Alpine Linux #415

messense opened this issue Sep 27, 2022 · 14 comments

Comments

@messense
Copy link
Contributor

messense commented Sep 27, 2022

https://gitlab.alpinelinux.org/messense/aports/-/jobs/853878

rustc version information:

$ rustc -vV
rustc 1.64.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: armv7-alpine-linux-musleabihf
release: 1.64.0
LLVM version: 14.0.6

error message:

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:13:9
   |
13 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:25:9
   |
25 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:40:9
   |
40 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:51:9
   |
51 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:66:9
   |
66 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:83:9
   |
83 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:101:9
    |
101 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:120:9
    |
120 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e[596](https://gitlab.alpinelinux.org/messense/aports/-/jobs/853878#L596)3aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:140:9
    |
140 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:161:9
    |
161 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:183:9
    |
183 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:206:9
    |
206 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:230:9
    |
230 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> /home/buildozer/.cargo/registry/src/github.com-1285ae84e5963aae/rustix-0.35.10/src/backend/linux_raw/arch/inline/arm.rs:255:9
    |
255 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^
   Compiling console v0.15.1
   Compiling rand_core v0.6.4
   Compiling uuid v0.8.2
   Compiling time v0.3.14
   Compiling charset v0.1.3
   Compiling addr2line v0.17.0
   Compiling dirs v4.0.0
   Compiling nb-connect v1.2.0
   Compiling matchers v0.1.0
   Compiling num-complex v0.4.2
   Compiling url v2.3.1
   Compiling parking_lot v0.12.1
   Compiling tar v0.4.38
   Compiling digest v0.9.0
   Compiling crypto-mac v0.11.1
   Compiling block-buffer v0.10.3
error: could not compile `rustix` due to 14 previous errors
warning: build failed, waiting for other jobs to finish...
@messense messense changed the title Failed to build on armv7 musl target Failed to build on armv7 musl target on Alpine Linux Sep 27, 2022
@sunfishcode
Copy link
Member

Thanks for the report! I've started working on a fix in #416.

@sunfishcode
Copy link
Member

I can't find any upstream Rust Linux arm targets that enable thumb-mode which hit this. Would you be able to test whether #416 fixes the problem?

@messense
Copy link
Contributor Author

RUSTFLAGS="-C target-feature=+thumb-mode" cargo build --target armv7-unknown-linux-musleabihf
   Compiling bitflags v1.3.2
   Compiling linux-raw-sys v0.0.46
   Compiling libc v0.2.133
   Compiling io-lifetimes v1.0.0-rc1
   Compiling rustix v0.36.0-rc2 (/Users/messense/Projects/rustix)
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:13:9
   |
13 |         in("r7") nr.to_asm(),

RUSTFLAGS="-C target-feature=+thumb-mode" still gives me the same error.

docker run --rm -it --platform linux/arm/v7 alpine:edge
/ # uname -a
Linux 91928fdcd8a2 5.15.0-47-generic #51-Ubuntu SMP Fri Aug 12 08:18:32 UTC 2022 armv7l Linux
/ # apk add git cargo
/ # RUSTC_BOOTSTRAP=1 rustc -Zunstable-options --print target-spec-json
{
  "abi": "eabihf",
  "arch": "arm",
  "crt-static-respected": true,
  "data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
  "dynamic-linking": true,
  "env": "musl",
  "features": "+v7,+vfp3,-d32,+thumb-mode,+thumb2",
  "has-rpath": true,
  "has-thread-local": true,
  "is-builtin": true,
  "llvm-target": "armv7-alpine-linux-musleabihf",
  "max-atomic-width": 64,
  "need-rpath": true,
  "os": "linux",
  "position-independent-executables": true,
  "relro-level": "full",
  "static-position-independent-executables": true,
  "target-family": [
    "unix"
  ],
  "target-mcount": "\u0001mcount",
  "target-pointer-width": "32",
  "vendor": "alpine"
}
/ # cd
~ # git clone https://github.com/bytecodealliance/rustix.git
Cloning into 'rustix'...
remote: Enumerating objects: 13387, done.
remote: Counting objects: 100% (80/80), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 13387 (delta 29), reused 24 (delta 9), pack-reused 13307
Receiving objects: 100% (13387/13387), 2.65 MiB | 9.56 MiB/s, done.
Resolving deltas: 100% (9323/9323), done.
~/rustix # cargo build --features=all-apis
    Updating crates.io index
  Downloaded itoa v1.0.3
  Downloaded bitflags v1.3.2
  Downloaded once_cell v1.15.0
  Downloaded libc v0.2.133
  Downloaded linux-raw-sys v0.0.46
  Downloaded io-lifetimes v1.0.0-rc1
  Downloaded 6 crates (1.5 MB) in 2.53s
   Compiling io-lifetimes v1.0.0-rc1
   Compiling libc v0.2.133
   Compiling rustix v0.36.0-rc2 (/root/rustix)
   Compiling bitflags v1.3.2
   Compiling once_cell v1.15.0
   Compiling itoa v1.0.3
   Compiling linux-raw-sys v0.0.46
error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:13:9
   |
13 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:25:9
   |
25 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:40:9
   |
40 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:51:9
   |
51 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:66:9
   |
66 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
  --> src/backend/linux_raw/arch/inline/arm.rs:83:9
   |
83 |         in("r7") nr.to_asm(),
   |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:101:9
    |
101 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:120:9
    |
120 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:140:9
    |
140 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:161:9
    |
161 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:183:9
    |
183 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:206:9
    |
206 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:230:9
    |
230 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: cannot use register `r7`: the frame pointer (r7) cannot be used as an operand for inline asm
   --> src/backend/linux_raw/arch/inline/arm.rs:255:9
    |
255 |         in("r7") nr.to_asm(),
    |         ^^^^^^^^^^^^^^^^^^^^

error: could not compile `rustix` due to 14 previous errors

Also fails in Alpine Linux armv7l docker container.

@messense
Copy link
Contributor Author

I just tried this code

#[cfg(not(target_arch = "arm"))]
compile_error!("not arm");

#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
compile_error!("arm thumb-mode");

#[cfg(all(target_arch = "arm", not(target_feature = "thumb-mode")))]
compile_error!("arm no thumb-mode");
  • cargo build gives error: not arm because I'm on M2 Mac which is aarch64.
  • cargo b --target armv7-unknown-linux-musleabihf gives error: arm no thumb-mode
  • RUSTFLAGS="-C target-feature=+thumb-mode" cargo build --target armv7-unknown-linux-musleabihf also gives error: arm no thumb-mode

So it looks like the target-feature cfg isn't working.

@nibon7
Copy link

nibon7 commented Sep 28, 2022

#[cfg(target_feature= "thumb-mode")] is false on alpine linux (rust 1.64.0)

@messense
Copy link
Contributor Author

~ # rustc --print cfg
debug_assertions
panic="unwind"
target_arch="arm"
target_endian="little"
target_env="musl"
target_family="unix"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="linux"
target_pointer_width="32"
target_vendor="alpine"
unix

Indeed.

@nibon7
Copy link

nibon7 commented Sep 28, 2022

~ # rustc --print cfg
debug_assertions
panic="unwind"
target_arch="arm"
target_endian="little"
target_env="musl"
target_family="unix"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="linux"
target_pointer_width="32"
target_vendor="alpine"
unix

no target_feature="thumb-mode" 🤣

@messense
Copy link
Contributor Author

$ rustc --print cfg --target armv7-unknown-linux-musleabihf -C target-feature=+thumb-mode
debug_assertions
panic="unwind"
target_arch="arm"
target_endian="little"
target_env="musl"
target_family="unix"
target_feature="crt-static"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="linux"
target_pointer_width="32"
target_vendor="unknown"
unix

$ rustc +nightly --print cfg --target armv7-unknown-linux-musleabihf -C target-feature=+thumb-mode
debug_assertions
panic="unwind"
target_abi="eabihf"
target_arch="arm"
target_endian="little"
target_env="musl"
target_family="unix"
target_feature="aclass"
target_feature="crt-static"
target_feature="dsp"
target_feature="llvm14-builtins-abi"
target_feature="thumb-mode"
target_feature="thumb2"
target_feature="v5te"
target_feature="v6"
target_feature="v6k"
target_feature="v6t2"
target_feature="v7"
target_feature="vfp2"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_has_atomic_equal_alignment="16"
target_has_atomic_equal_alignment="32"
target_has_atomic_equal_alignment="64"
target_has_atomic_equal_alignment="8"
target_has_atomic_equal_alignment="ptr"
target_has_atomic_load_store="16"
target_has_atomic_load_store="32"
target_has_atomic_load_store="64"
target_has_atomic_load_store="8"
target_has_atomic_load_store="ptr"
target_os="linux"
target_pointer_width="32"
target_thread_local
target_vendor="unknown"
unix

Seems like it's working on nightly Rust, not on stable yet.

@messense
Copy link
Contributor Author

I just tried this code

#[cfg(not(target_arch = "arm"))]
compile_error!("not arm");

#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
compile_error!("arm thumb-mode");

#[cfg(all(target_arch = "arm", not(target_feature = "thumb-mode")))]
compile_error!("arm no thumb-mode");
  • cargo build gives error: not arm because I'm on M2 Mac which is aarch64.
  • cargo b --target armv7-unknown-linux-musleabihf gives error: arm no thumb-mode
  • RUSTFLAGS="-C target-feature=+thumb-mode" cargo build --target armv7-unknown-linux-musleabihf also gives error: arm no thumb-mode

So it looks like the target-feature cfg isn't working.

This also correctly outputs error: arm thumb-mode on nightly when running RUSTFLAGS="-C target-feature=+thumb-mode" cargo +nightly build --target armv7-unknown-linux-musleabihf.

@messense
Copy link
Contributor Author

Related rust-lang/rust#83975 (comment)

@sunfishcode
Copy link
Member

Thanks for that info! I didn't realize the target_feature was only exposed on nightly. I've now opened #420 with a fix that detects whether the target supports r7 at build time, which avoids that issue.

@messense
Copy link
Contributor Author

messense commented Sep 30, 2022

Still the same error with #420 when building with

RUSTFLAGS="-C target-feature=+thumb-mode" cargo build --target armv7-unknown-linux-musleabihf

(I think maybe it's because can_compile did not pickup RUSTFLAGS? See rust-lang/cargo#4423)

But now it works in Alpine Linux armv7 container.

algitbot pushed a commit to alpinelinux/aports that referenced this issue Sep 30, 2022
this was the setting before, even though it's different from our gcc
target. but this breaks compilation of the compiler itself for now, due
to a vendored crate.

see bytecodealliance/rustix#415
@messense
Copy link
Contributor Author

Closing as completed now that #420 is merged and Alpine Linux removed thumb-mode.

Repository owner moved this from Issues to Done in @messense's open-source contributions Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants