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

LLVM ERROR: Not supported instr #124

Closed
sobolevn opened this issue Jan 8, 2021 · 23 comments · Fixed by #268
Closed

LLVM ERROR: Not supported instr #124

sobolevn opened this issue Jan 8, 2021 · 23 comments · Fixed by #268
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM

Comments

@sobolevn
Copy link

sobolevn commented Jan 8, 2021

I am using this example: https://github.com/Rahix/avr-hal/tree/d17a441a667dd65e5a9be75b0e71d1beadf93e84/boards/arduino-uno

I have also executed rustup component add rust-src

And it fails to compile with this error:

» cargo +nightly build --example uno-blink
   Compiling compiler_builtins v0.1.39
   Compiling nb v1.0.0
   Compiling cfg-if v0.1.10
   Compiling bare-metal v0.2.5
   Compiling void v1.0.2
   Compiling vcell v0.1.3
   Compiling ufmt-write v0.1.0 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
   Compiling panic-halt v0.2.0
   Compiling nb v0.1.3
   Compiling avr-device v0.2.3
   Compiling ufmt v0.1.0 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
   Compiling embedded-hal v0.2.4
LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:40>>
error: could not compile `compiler_builtins`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

My versions:

  • rust
» rustup --version
rustup 1.23.1 (2020-12-03)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.51.0-nightly (c8915eebe 2021-01-07)`
  • avr
» avr-gcc --version
avr-gcc (Homebrew AVR GCC 9.3.0) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • And macos 10.14
@lights0123
Copy link
Contributor

Try --release?

@sobolevn
Copy link
Author

sobolevn commented Jan 8, 2021

It is a bit different, but still the same 🙂

» cargo +nightly build --example uno-blink --release 
   Compiling compiler_builtins v0.1.39
   Compiling core v0.0.0 (/Users/sobolev/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.58
   Compiling semver-parser v0.7.0
   Compiling proc-macro-hack v0.5.19
   Compiling paste v1.0.4
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling quote v1.0.8
   Compiling bare-metal v0.2.5
   Compiling rustc-std-workspace-core v1.99.0 (/Users/sobolev/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling avr-device-macros v0.2.3
   Compiling ufmt-macros v0.1.1 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
   Compiling nb v1.0.0
   Compiling ufmt-write v0.1.0 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
   Compiling void v1.0.2
   Compiling vcell v0.1.3
   Compiling cfg-if v0.1.10
   Compiling panic-halt v0.2.0
   Compiling nb v0.1.3
   Compiling avr-device v0.2.3
   Compiling embedded-hal v0.2.4
LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:40>>
error: could not compile `compiler_builtins`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

With --verbose:

   Compiling embedded-hal v0.2.4
     Running `rustc --crate-name embedded_hal /Users/sobolev/.cargo/registry/src/github.com-1ecc6299db9ec823/embedded-hal-0.2.4/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=s -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 --cfg 'feature="unproven"' -C metadata=503a59343e486e01 -C extra-filename=-503a59343e486e01 --out-dir /Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps --target /Users/sobolev/Desktop/avr-hal/avr-specs/avr-atmega328p.json -L dependency=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps -L dependency=/Users/sobolev/Desktop/avr-hal/target/release/deps --extern 'noprelude:compiler_builtins=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps/libcompiler_builtins-afa03ed941a63b4f.rmeta' --extern 'noprelude:core=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps/libcore-30308749cc1695e3.rmeta' --extern nb=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps/libnb-e03ff2173c96de6e.rmeta --extern void=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps/libvoid-4cf9d65885018701.rmeta -Z unstable-options --cap-lints allow`
LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:40>>
error: could not compile `compiler_builtins`

Caused by:
  process didn't exit successfully: `rustc --crate-name compiler_builtins /Users/sobolev/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=s -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' -C metadata=afa03ed941a63b4f -C extra-filename=-afa03ed941a63b4f --out-dir /Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps --target /Users/sobolev/Desktop/avr-hal/avr-specs/avr-atmega328p.json -Z force-unstable-if-unmarked -L dependency=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps -L dependency=/Users/sobolev/Desktop/avr-hal/target/release/deps --extern core=/Users/sobolev/Desktop/avr-hal/target/avr-atmega328p/release/deps/librustc_std_workspace_core-2709fdbb3f7a5de3.rmeta --cap-lints allow --cfg 'feature="unstable"'` (exit code: 101)
warning: build failed, waiting for other jobs to finish...
error: build failed

I have also tried a clean build with:

  • reinstalled rust and rustup
  • reinstalled rust-std

Still the same.

@sobolevn
Copy link
Author

sobolevn commented Jan 8, 2021

I have made a reproduction:

FROM rustlang/rust:nightly-slim

RUN apt-get update \
  && apt-get install --no-install-recommends -y \
    avr-libc \
    binutils-avr \
    gcc-avr \
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && apt-get clean -y && rm -rf /var/lib/apt/lists/*

COPY . /code

WORKDIR /code/boards/arduino-uno

RUN rustup component add rust-src
RUN cargo +nightly build --example uno-blink

Steps:
0. Add this Dockerfile in the root of the project
0,5. Ignore or delete any target/ dirs

  1. Run docker build --tag=ard .

This is the output:

Step 6/6 : RUN cargo +nightly build --example uno-blink
 ---> Running in fde0189b88d8
    Updating git repository `https://github.com/Rahix/ufmt.git`
    Updating crates.io index
 Downloading crates ...
  Downloaded nb v0.1.3
  Downloaded paste v1.0.4
  Downloaded rustc_version v0.2.3
  Downloaded semver-parser v0.7.0
  Downloaded quote v1.0.8
  Downloaded proc-macro2 v1.0.24
  Downloaded proc-macro-hack v0.5.19
  Downloaded vcell v0.1.3
  Downloaded void v1.0.2
  Downloaded cfg-if v0.1.10
  Downloaded unicode-xid v0.2.1
  Downloaded syn v1.0.58
  Downloaded avr-device-macros v0.2.3
  Downloaded avr-device v0.2.3
  Downloaded semver v0.9.0
  Downloaded panic-halt v0.2.0
  Downloaded nb v1.0.0
  Downloaded embedded-hal v0.2.4
  Downloaded bare-metal v0.2.5
 Downloading crates ...
  Downloaded cc v1.0.60
  Downloaded compiler_builtins v0.1.39
  Downloaded getopts v0.2.21
  Downloaded hashbrown v0.9.0
  Downloaded addr2line v0.14.0
  Downloaded gimli v0.23.0
  Downloaded miniz_oxide v0.4.0
  Downloaded adler v0.2.3
  Downloaded object v0.22.0
  Downloaded unicode-width v0.1.8
  Downloaded rustc-demangle v0.1.18
  Downloaded libc v0.2.79
   Compiling compiler_builtins v0.1.39
   Compiling core v0.0.0 (/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.58
   Compiling semver-parser v0.7.0
   Compiling proc-macro-hack v0.5.19
   Compiling paste v1.0.4
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling quote v1.0.8
   Compiling bare-metal v0.2.5
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:40>>
error: could not compile `compiler_builtins`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
The command '/bin/sh -c cargo +nightly build --example uno-blink' returned a non-zero code: 101

@lights0123
Copy link
Contributor

Regression in nightly-2021-01-08, rust version 1.51.0-nightly (c8915eebe 2021-01-07), should probably file a compiler-builtins bug. Diff, probably because the last 4 months of changes in compiler-builtins were used.

@Rahix Rahix added the compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM label Jan 13, 2021
@Rahix
Copy link
Owner

Rahix commented Jan 25, 2021

We have identified the problem, let's see how it will be solved. In the meantime, for anyone stumbling upon this issue: Just use an older toolchain like nightly-2021-01-07 for now. With rustup, installing and using it will be as easy as:

rustup toolchain install nightly-2021-01-07
# ...
cargo +nightly-2021-01-07 build

@Urhengulas
Copy link

Thank you for the workaround!
Is there a way to support you in fixing it?

Rahix added a commit that referenced this issue Jan 27, 2021
Due to a compiler regression [1], latest nightly builds of the compiler are
currently broken.  Instead, suggest using the last working build which was
`nightly-2021-01-07`.  This commit can hopefully be reverted once the compiler
is fixed again.

[1]: rust-lang/compiler-builtins#400
Ref: #124
nbigaouette added a commit to nbigaouette/robot-car that referenced this issue Feb 14, 2021
Newer nightly fails to compile:

    LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:45>>
    error: could not compile `compiler_builtins`

Already reported upstream:
Rahix/avr-hal#124 (comment)
@ewpratten
Copy link

For anyone that needs this information:

Rust nightly-2020-11-20 is the last version that was built that both doesn't have this issue, and had a successful rls build.

So, if you are (for example) looking for a release where you can work with avr-hal and have VSCode give you useful autocomplete and highlighting, 2020-11-20 is the version to use.

Sources: toolsuite build info and rustdatehash

@sobolevn
Copy link
Author

sobolevn commented Mar 1, 2021

One more solution to rls problem (2021-01-07 does not have rls component): rls can be replaced with https://github.com/rust-analyzer/rust-analyzer

@mike-kfed
Copy link

I found it's easiest to create a file called rust-toolchain in your projects directory with following content

[toolchain]
channel = "nightly-2021-01-07"
components = ["rust-src"]

afterwards you can simply run cargo build and all is fine :)

@ewpratten
Copy link

For my own future reference: these are the docs for rust-toolchain files.

@Urhengulas
Copy link

I found it's easiest to create a file called rust-toolchain in your projects directory with following content

[toolchain]
channel = "nightly-2021-01-07"
components = ["rust-src"]

afterwards you can simply run cargo build and all is fine :)

This is actually super helpful. Thanks for the tip!

@lf-
Copy link

lf- commented Mar 15, 2021

@waynevanson
Copy link

Rust nightly-2020-11-20 is the last version that was built that both doesn't have this issue, and had a successful rls build.

Thank you! I was looking for this!

@djdisodo
Copy link

djdisodo commented Jul 9, 2021

gcc backend will be soon supported for rust
so can we use them instead?

@stappersg
Copy link
Contributor

stappersg commented Jul 9, 2021 via email

@stappersg
Copy link
Contributor

Pardon my way too whity response.

Yes please, keep sharing possible solutions.
Do notify when GCC Rust arrives.

@ssmgcode
Copy link

ssmgcode commented Aug 5, 2021

Hi everyone. Same problem here, I just cargo generate --git https://github.com/Rahix/avr-hal-template.git and then cargo build.
The output:

$ cargo build
   Compiling compiler_builtins v0.1.49
   Compiling core v0.0.0 (/home/ssmg/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.28
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.74
   Compiling semver-parser v0.7.0
   Compiling proc-macro-hack v0.5.19
   Compiling paste v1.0.5
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling quote v1.0.9
   Compiling bare-metal v0.2.5
   Compiling rustc-std-workspace-core v1.99.0 (/home/ssmg/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling nb v1.0.0
   Compiling cfg-if v0.1.10
   Compiling void v1.0.2
   Compiling ufmt-write v0.1.0
   Compiling vcell v0.1.3
LLVM ERROR: Not supported instr: <MCInst 296 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:39>>
error: could not compile `compiler_builtins`
warning: build failed, waiting for other jobs to finish...
error: build failed

I've tried rustup toolchain install nightly-2021-01-07 and in my rust-toonchail.toml:

[toolchain]
channel = "nightly-2021-01-07"
components = [ "rust-src" ]

and then cargo build I got:

   Compiling compiler_builtins v0.1.49
   Compiling nb v1.0.0
   Compiling bare-metal v0.2.5
   Compiling ufmt-write v0.1.0
   Compiling vcell v0.1.3
   Compiling void v1.0.2
   Compiling cfg-if v0.1.10
   Compiling cfg-if v1.0.0
   Compiling panic-halt v0.2.0
   Compiling ufmt v0.1.0
   Compiling nb v0.1.3
   Compiling avr-device v0.3.1
   Compiling embedded-hal v0.2.6
LLVM ERROR: Not supported instr: <MCInst 296 <MCOperand Reg:1> <MCOperand Imm:13> <MCOperand Reg:40>>
error: could not compile `compiler_builtins`
warning: build failed, waiting for other jobs to finish...
error: build failed

and with cargo +nightly-2021-01-07 build I got:

error: "/home/ssmg/.rustup/toolchains/nightly-2021-01-07-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src

but I make rustup component add rust-src and I obtain the same output.

Thank you for your help and time.

@lights0123
Copy link
Contributor

@ssmgcode you need to add the rust-src component for the particular toolchain. I believe you can use the same +«toolchain-version» trick you can use with other Rust commands.

@Rahix
Copy link
Owner

Rahix commented Aug 5, 2021

@ssmgcode, it seems your rustup is not picking up rust-toolchain.toml? What version of rustup do you have? Maybe you need to do a rustup self update?

@ssmgcode
Copy link

ssmgcode commented Aug 6, 2021

@ssmgcode you need to add the rust-src component for the particular toolchain. I believe you can use the same +«toolchain-version» trick you can use with other Rust commands.

Thank you! I made rustup +nightly-2021-01-07 component add rust-src, deleted the project folder and create it again from template. Then I just cargo build and it worked nicely!

@ssmgcode
Copy link

ssmgcode commented Aug 6, 2021

@ssmgcode, it seems your rustup is not picking up rust-toolchain.toml? What version of rustup do you have? Maybe you need to do a rustup self update?

Yes, it seemed, it was a really weird thing. My rustup version is rustup 1.24.3 (ce5817a94 2021-05-31), I think it's a recent version because I started using Rust and installed it a month ago, sort of.

Thank you for your time guys, this makes me happy.

@Patryk27
Copy link
Contributor

Patryk27 commented May 8, 2022

Heads-up: rust-lang/rust#96845 🙂

@Rahix
Copy link
Owner

Rahix commented May 9, 2022

This is huge, thank you so much for your efforts here @Patryk27!

zeenix added a commit to zeenix/ag-lcd that referenced this issue Apr 2, 2023
The underlying [issue] in avr-hal has been fixed.

[issue]: Rahix/avr-hal#124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM
Projects
None yet
Development

Successfully merging a pull request may close this issue.