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

AVR: Compilation in --release mode fails with LLVM ERROR: Not supported instr #82104

Closed
mbuesch opened this issue Feb 14, 2021 · 8 comments · Fixed by #96845
Closed

AVR: Compilation in --release mode fails with LLVM ERROR: Not supported instr #82104

mbuesch opened this issue Feb 14, 2021 · 8 comments · Fixed by #96845
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way.

Comments

@mbuesch
Copy link

mbuesch commented Feb 14, 2021

When compiling the following minimal AVR template in --release mode, the compiler aborts with an LLVM error

https://github.com/avr-rust/template-bin.git

(This is an empty template with an empty main that does nothing.)

$ cargo build --target avr-atmega328p.json -Z build-std=core --release                                          
   Compiling compiler_builtins v0.1.39                                                                                                                     
   Compiling core v0.0.0 (.../rust-unstable/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)                     
   Compiling rustc-std-workspace-core v1.99.0 (.../rust-unstable/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc
-std-workspace-core)                                                         
   Compiling avr-std-stub v1.0.2                                             
LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:47>>                                                      
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                               

In debug mode the build works correctly:

$ cargo build --target avr-atmega328p.json -Z build-std=core                                                    
   Compiling core v0.0.0 (.../rust-unstable/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)                     
   Compiling compiler_builtins v0.1.39                                       
   Compiling rustc-std-workspace-core v1.99.0 (.../rust-unstable/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc
-std-workspace-core)                                                                                                                                       
   Compiling avr-std-stub v1.0.2                                             
   Compiling template-bin v0.1.0 (.../avr-rust-template)                                                                                  
    Finished dev [unoptimized + debuginfo] target(s) in 14.61s   

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (8e54a2113 2021-02-13)
binary: rustc
commit-hash: 8e54a21139ae96a2aca3129100b057662e2799b9
commit-date: 2021-02-13
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
@mbuesch mbuesch added the C-bug Category: This is a bug. label Feb 14, 2021
@jonas-schievink jonas-schievink added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way. labels Feb 14, 2021
@Rynibami
Copy link

I’ve got the same problem. I am building my software based upon the AVR template "avr-atmega328p.json” which I called "avr-unknown-gnu-atmega2560.json”. This file looks mostly identical to the existing atmega’s on the web :

{
    "arch": "avr",
    "cpu": "atmega2560",
    "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
    "eh-frame-header": false,
    "env": "",
    "exe-suffix": ".elf",
    "executables": true,
    "is-builtin": true,
    "late-link-args": {
        "gcc": [
            "-lgcc"
        ]
    },
    "linker": "avr-gcc",
    "linker-flavor": "gcc",
    "linker-is-gnu": true,
    "llvm-target": "avr-unknown-unknown",
    "no-builtins": true,
    "os": "unknown",
    "pre-link-args": {
        "gcc": [
            "-mmcu=atmega2560",
            "-Wl,--as-needed"
        ]
    },
    "target-c-int-width": "16",
    "target-endian": "little",
    "target-pointer-width": "16",
    "vendor": "unknown"
}

I tried to build my project (which is just empty) on the nightly and stable versions, but I get the same type of error:

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

Caused by:
  process didn't exit successfully: `rustc --crate-name compiler_builtins /Users/***/.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=3 -C panic=abort -C embed-bitcode=no --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' -C metadata=358757d918a0ced2 -C extra-filename=-358757d918a0ced2 --out-dir /Users/***/ctrlr/target/avr-unknown-gnu-atmega2560/release/deps --target /Users/***/ctrlr/avr-unknown-gnu-atmega2560.json -Z force-unstable-if-unmarked -L dependency=/Users/***/ctrlr/target/avr-unknown-gnu-atmega2560/release/deps -L dependency=/Users/***/ctrlr/target/release/deps --extern core=/Users/***/ctrlr/target/avr-unknown-gnu-atmega2560/release/deps/librustc_std_workspace_core-0fe1efb82ffd1726.rmeta --cap-lints allow --cfg 'feature="unstable"'` (exit code: 101)

@Rahix
Copy link

Rahix commented Feb 23, 2021

This is caused by rust-lang/compiler-builtins#400. A fix is pending in LLVM, but not yet merged... In the meantime, you can use the nightly-2021-01-07 compiler version:

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

@LvInSaNevL
Copy link

@Rahix sorry to reopen this older issue but I'm seeing the same issues. I've tried like 3 different versions of the rust compiler, plus the current (1.55) version, and they all have the exact same issue?

@Rahix
Copy link

Rahix commented Jul 15, 2021

nightly-2021-01-07 is the last working version as of now. We're still blocked on a fix landing in LLVM which is pending review (see the compiler-builtins issue linked above).

@mbuesch
Copy link
Author

mbuesch commented Dec 17, 2021

Is there any plan to resolve this issue?

@agausmann
Copy link
Contributor

@mbuesch They are working on fixing the underlying bug in LLVM - D114611

@mbuesch
Copy link
Author

mbuesch commented Dec 21, 2021

Thanks for the update, @agausmann

@mbuesch
Copy link
Author

mbuesch commented May 19, 2022

Thanks for fixing this bug! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants