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

ran out of registers for AVR atmega4809 #112140

Closed
cpt-n3mo opened this issue May 31, 2023 · 11 comments
Closed

ran out of registers for AVR atmega4809 #112140

cpt-n3mo opened this issue May 31, 2023 · 11 comments
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)

Comments

@cpt-n3mo
Copy link

cpt-n3mo commented May 31, 2023

Good day..

I have been trying to compile some code for a atmega4809, following the rust embedded book.
but im running into quite some problems,..

used the following device jsons with either atmega4809 || avrxmega3 cpu setting,
pack was downloaded from the official place

{
    "arch": "avr",
    "atomic-cas": false,
    "cpu": "atmega4809",
    "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,
    "late-link-args": {
        "gcc": [
            "-lgcc"
        ]
    },
    "linker": "avr-gcc",
    "linker-is-gnu": true,
    "llvm-target": "avr-unknown-unknown",
    "code-model": "small",
    "max-atomic-width": 8,
    "no-default-libraries": false,
    "os": "unknown",
    "pre-link-args": {
        "gcc": [
            "-mmcu=atmega4809",
            "-B./packs/gcc/dev/atmega4809/"

        ]
    },
    "target-c-int-width": "16",
    "target-endian": "little",
    "target-pointer-width": "16",
    "vendor": "unknown"
}

.cargo/config.toml

[build]
target = "./avr-4809.json"


[unstable]
build-std = ["core"]

while using nightly-2022-10-22 it gives me a SIGSEGV with release tag

➜  arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json --release
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.82
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling avr-std-stub v1.0.3
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x28bdd83)[0x7fedeb0bdd83]
/usr/lib/libc.so.6(+0x39ab0)[0x7fede84c2ab0]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm12MachineInstr15addRegisterDeadENS_8RegisterEPKNS_18TargetRegisterInfoEb+0xe7)[0x7fede6e364e7]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm13LiveIntervals17computeDeadValuesERNS_12LiveIntervalEPNS_15SmallVectorImplIPNS_12MachineInstrEEE+0x141)[0x7fede6e9b5c1]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm13LiveIntervals12shrinkToUsesEPNS_12LiveIntervalEPNS_15SmallVectorImplIPNS_12MachineInstrEEE+0x3e8)[0x7fede6e9b1f0]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm13LiveRangeEdit17eliminateDeadDefsERNS_15SmallVectorImplIPNS_12MachineInstrEEENS_8ArrayRefINS_8RegisterEEE+0x18c)[0x7fede6c75c8c]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(+0x5cece1a)[0x7fede72ece1a]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm12RegAllocBase16postOptimizationEv+0x17)[0x7fede6be8e35]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(+0x59e2f70)[0x7fede6fe2f70]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xb0f)[0x7fede7029c1f]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7fede70290ef]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.66.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x210)[0x7fede6d4b95c]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23b73a2)[0x7fedeabb73a2]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23b6cf9)[0x7fedeabb6cf9]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23b4c5a)[0x7fedeabb4c5a]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23b2105)[0x7fedeabb2105]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23b1117)[0x7fedeabb1117]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23af548)[0x7fedeabaf548]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/librustc_driver-fd3fbd78313e2ee9.so(+0x23148a9)[0x7fedeab148a9]
/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/libstd-7b2106000b625742.so(rust_metadata_std_631fbe326a1fa8e7+0xff583)[0x7fede8779583]
/usr/lib/libc.so.6(+0x8744b)[0x7fede851044b]
/usr/lib/libc.so.6(+0x10ae40)[0x7fede8593e40]
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2021 /home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=a775a4ac62b5815b -C extra-filename=-a775a4ac62b5815b --out-dir /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps --target /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/avr-4809.json -Z force-unstable-if-unmarked -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)

while using nightly-2022-10-22 without --release

 arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling compiler_builtins v0.1.82
error: ran out of registers during register allocation

error: could not compile `core` due to previous error
warning: build failed, waiting for other jobs to finish...

using nightly-2022-12-08 without --release gives again a SIGSEGV

arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.84
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x3295713)[0x7f06fec95713]
/usr/lib/libc.so.6(+0x39ab0)[0x7f06fb6b5ab0]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(_ZN4llvm12MachineInstr10addOperandERNS_15MachineFunctionERKNS_14MachineOperandE+0x1e6)[0x7f06f9c00580]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(+0x4c8e8cc)[0x7f06f948e8cc]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(+0x4c8e61f)[0x7f06f948e61f]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xafd)[0x7f06fa179851]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7f06fa178d33]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.67.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x21a)[0x7f06f9f5575a]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277da82)[0x7f06fe17da82]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277d445)[0x7f06fe17d445]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277b397)[0x7f06fe17b397]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277884d)[0x7f06fe17884d]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277770e)[0x7f06fe17770e]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x277667e)[0x7f06fe17667e]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x2692a24)[0x7f06fe092a24]
/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/librustc_driver-e0c8ab3d159f8c4e.so(+0x404a393)[0x7f06ffa4a393]
/usr/lib/libc.so.6(+0x8744b)[0x7f06fb70344b]
/usr/lib/libc.so.6(+0x10ae40)[0x7f06fb786e40]
   Compiling avr-std-stub v1.0.3
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2021 /home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b4da6b00cf28ed56 -C extra-filename=-b4da6b00cf28ed56 --out-dir /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/debug/deps --target /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/avr-4809.json -Z force-unstable-if-unmarked -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/debug/deps -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/debug/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)

using nightly-2022-12-08 with --release

 arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json --release
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.84
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling avr-std-stub v1.0.3
   Compiling arduino_test v0.1.0 (/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test)
error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: "avr-gcc" "-mmcu=atmega4809" "-B./packs/gcc/dev/atmega4809/" "/tmp/rustcPtISzx/symbols.o" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/arduino_test-b4126c1cca60c38f.arduino_test.968f6c9b-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps" "-L" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/release/deps" "-L" "/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/avr-4809/lib" "-Wl,-Bstatic" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/libcompiler_builtins-0dc899707a19c0d5.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/home/n3m0/.rustup/toolchains/nightly-2022-12-08-x86_64-unknown-linux-gnu/lib/rustlib/avr-4809/lib" "-o" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/arduino_test-b4126c1cca60c38f.elf" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1"
  = note: /usr/bin/avr-ld: avr architecture of input file `/tmp/rustcPtISzx/symbols.o' is incompatible with avr:103 output
          collect2: error: ld returned 1 exit status

error: could not compile `arduino_test` due to previous error;

using latest nighly-2023-05-30 with --release

 arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json --release
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.92
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling avr-std-stub v1.0.3
LLVM ERROR: Expected a constant shift amount!
error: could not compile `compiler_builtins` (lib)
warning: build failed, waiting for other jobs to finish...

using latest nighly-2023-05-30 without --release

arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling compiler_builtins v0.1.92
error: ran out of registers during register allocation

error: could not compile `core` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...

anyone know how to solve this..?

@cpt-n3mo cpt-n3mo added the C-bug Category: This is a bug. label May 31, 2023
@apiraino apiraino added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ and removed O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels May 31, 2023
@Jules-Bertholet
Copy link
Contributor

@rustbot label O-avr

@rustbot rustbot added the O-AVR Target: AVR processors (ATtiny, ATmega, etc.) label May 31, 2023
@Nilstrieb Nilstrieb changed the title Crosscompiling for AVR atmega4809 ran out of registers for AVR atmega4809 May 31, 2023
@cpt-n3mo
Copy link
Author

digging some more...

using different nightly versions

at least from nightly-2023-02-28 to nightly-23-03-21 it will SIGSEGV with this error

 arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json
   Compiling compiler_builtins v0.1.87
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x31c6a93)[0x7f3c397c6a93]
/usr/lib/libc.so.6(+0x39ab0)[0x7f3c362b9ab0]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(_ZN4llvm12MachineInstr10addOperandERNS_15MachineFunctionERKNS_14MachineOperandE+0x193)[0x7f3c348005e9]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(+0x4bffcfb)[0x7f3c33fffcfb]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(+0x4bffa3f)[0x7f3c33fffa3f]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xb1a)[0x7f3c34d260aa]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x7f3c34d2556f]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.70.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x26d)[0x7f3c34b53f33]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x273a258)[0x7f3c38d3a258]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x2739c7a)[0x7f3c38d39c7a]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x2737cb9)[0x7f3c38d37cb9]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x26b92ad)[0x7f3c38cb92ad]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x26b853a)[0x7f3c38cb853a]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x26b7638)[0x7f3c38cb7638]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/librustc_driver-897e90da9cc472c4.so(+0x267bbf6)[0x7f3c38c7bbf6]
/home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/libstd-8c5537594e196f18.so(rust_metadata_std_f90515c7d1e58fcd+0x109e53)[0x7f3c36573e53]
/usr/lib/libc.so.6(+0x8744b)[0x7f3c3630744b]
/usr/lib/libc.so.6(+0x10ae40)[0x7f3c3638ae40]
   Compiling avr-std-stub v1.0.3
error: could not compile `core` (lib)

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2021 /home/n3m0/.rustup/toolchains/nightly-2023-03-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=212 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=dc3001404680ced0 -C extra-filename=-dc3001404680ced0 --out-dir /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/debug/deps --target /home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/avr-4809.json -Z force-unstable-if-unmarked -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/debug/deps -L dependency=/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/debug/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)

nightly-2023-03-22 and later it seems to run out of registers. with following error.

 arduino_test git:(master) ✗ cargo build -Z build-std=core --target ./avr-4809.json
   Compiling compiler_builtins v0.1.87
   Compiling core v0.0.0 (/home/n3m0/.rustup/toolchains/nightly-2023-03-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/n3m0/.rustup/toolchains/nightly-2023-03-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
error: ran out of registers during register allocation

error: could not compile `core` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...

@workingjubilee
Copy link
Contributor

Please add this to your Cargo.toml

[profile.release]
lto = true

and tell me if it builds in --release mode?

@cpt-n3mo
Copy link
Author

Please add this to your Cargo.toml

[profile.release]
lto = true

and tell me if it builds in --release mode?

Thanks for your response !

no sadly this does not build either..

@workingjubilee
Copy link
Contributor

huh, that usually fixes things.

@cpt-n3mo
Copy link
Author

cpt-n3mo commented Jun 1, 2023

For now I did get it to work using nightly-2022-10-22 using --release not using the lto setting, so for now I can compile, while it still fails without --release

but not on current release with --release and lto set to true, I will update you on the error as I cant remember it, im not at my workstation at the moment.

Kind Regards,

@Patryk27
Copy link
Contributor

Patryk27 commented Jun 2, 2023

Hi, the error message when compiling without --release, i.e.:

error: ran out of registers during register allocation

... is kinda expected because AVR is such a tiny target platform that unoptimized Rust code simply wouldn't fit there - I don't think there's much Rust / LLVM can do (maybe except for improving the error message somehow).

(( edit: although apparently codegen-units = 1 seems to make the development build pass! ))

The other error, though:

LLVM ERROR: Expected a constant shift amount!

... is suspicious; I'll try to take look over the weekend 🙂

@Patryk27
Copy link
Contributor

Patryk27 commented Jun 2, 2023

Okie, that's a regression on LLVM's side:
rust-lang/compiler-builtins#523 (comment)

I'll try to review that patch and submit it to LLVM folks.

@cpt-n3mo
Copy link
Author

cpt-n3mo commented Jun 2, 2023

Hi, the error message when compiling without --release, i.e.:

error: ran out of registers during register allocation

... is kinda expected because AVR is such a tiny target platform that unoptimized Rust code simply wouldn't fit there - I don't think there's much Rust / LLVM can do (maybe except for improving the error message somehow).

(( edit: although apparently codegen-units = 1 seems to make the development build pass! ))

The other error, though:

LLVM ERROR: Expected a constant shift amount!

... is suspicious; I'll try to take look over the weekend slightly_smiling_face

this indeed seems logical.. a better errors would indeed be nice though..
i tried the following
latest nightly

...

[profile.release]
lto =  true
codegen-units = 1

.cargo/config.toml

[build]
target = "./avr-4809.json"

[unstable]
build-std = ["core"]

with as a result ..

error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/n3m0/.cargo/bin:/home/n3m0/bin:/usr/local/bin:/home/n3m0/.cargo/bin:/home/n3m0/bin:/usr/local/bin:/home/n3m0/.cargo/bin:/home/n3m0/bin:/usr/local/bin:/home/n3m0/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin:/home/n3m0/.dotnet/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin" VSLANG="1033" "avr-gcc" "-mmcu=atmega4809" "-B./packs/gcc/dev/atmega4809/" "/tmp/rustceNlzo9/symbols.o" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/arduino_test-9684d2f2d3c866e1.arduino_test.96d99bdb83ad904b-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps" "-L" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/release/deps" "-L" "/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/avr-4809/lib" "-Wl,-Bstatic" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/libcompiler_builtins-ab34cea393c6698a.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-z,noexecstack" "-L" "/home/n3m0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/avr-4809/lib" "-o" "/home/n3m0/Mounts/DATA3/rust_lang_tuts/arduino_test/target/avr-4809/release/deps/arduino_test-9684d2f2d3c866e1.elf" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1"
  = note: /usr/bin/avr-ld: avr architecture of input file `/tmp/rustceNlzo9/symbols.o' is incompatible with avr:103 output
          collect2: error: ld returned 1 exit status

using the same settings with nightly-2022-10-22 seems to compile.

@Patryk27
Copy link
Contributor

Patryk27 commented Jun 3, 2023

Progress: patch tested & submitted (rust-lang/compiler-builtins#523 (comment)).

benshi001 pushed a commit to llvm/llvm-project that referenced this issue Jul 19, 2023
Currently our AVRShiftExpand pass expands only 32-bit shifts, with the
assumption that other kinds of shifts (e.g. 64-bit ones) are
automatically reduced to 8-bit ones by LLVM during ISel.

However this is not always true and causes problems in the rust-lang runtime.

This commit changes the logic a bit, so that instead of expanding only
32-bit shifts, we expand shifts of all types except 8-bit and 16-bit.

This is not the most optimal solution, because 64-bit shifts can be
expanded to 32-bit shifts which has been deeply optimized.

I've checked the generated code using rustc + simavr, and all shifts
seem to behave correctly.

Spotted in the wild in rustc:
rust-lang/compiler-builtins#523
rust-lang/rust#112140

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D154785
@workingjubilee
Copy link
Contributor

This should be fixed now with LLVM 17!

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. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)
Projects
None yet
Development

No branches or pull requests

7 participants
@Patryk27 @apiraino @cpt-n3mo @workingjubilee @rustbot @Jules-Bertholet and others