Skip to content

Unhelpful error message on risc-v using the asm! macro with register extractions #54315

@liamnaddell

Description

@liamnaddell

(this is my first issue, sorry)

This is sort of a bug and sort of a feature request/cry for help. All of the following stuff is new to me, so this is probably user error.

The code I tried is attached below
diosix.tar.gz

If you take the src/kernel/main.rs function, and replace the a2 with r, the rust compiler no longer segfaults!

I expected some kind of helpful error about how you can't use the a2 register, but got the following beauty:

./build.sh --triple riscv32imac-unknown-none-elf --platform sifive_e
[+] Building for riscv32 SiFive-E series
   Compiling diosix v2.0.0 (/home/liam/repos/diosix)
warning: function is never used: `serial_write`
  --> src/kernel/main.rs:39:1
   |
39 | fn serial_write(s: &str) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(dead_code)] on by default
error: Could not compile `diosix`.
To learn more, run the command again with --verbose.
make: *** [Makefile:2: all] Error 101

when the --verbose flag is added, you get

./build.sh --triple riscv32imac-unknown-none-elf --platform sifive_e
[+] Building for riscv32 SiFive-E series
       Fresh version_check v0.1.4
       Fresh libc v0.2.43
       Fresh ucd-util v0.1.1
       Fresh utf8-ranges v1.0.1
       Fresh bare-metal v0.2.3
       Fresh memchr v2.0.2
       Fresh regex-syntax v0.6.2
       Fresh riscv v0.3.0
       Fresh aho-corasick v0.6.8
       Fresh lazy_static v1.1.0
       Fresh thread_local v0.3.6
       Fresh regex v1.0.5
   Compiling diosix v2.0.0 (/home/liam/repos/diosix)
     Running `rustc --crate-name kernel src/kernel/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort --cfg 'feature="sifive_e"' -C metadata=332af80c5eb5cf4e -C extra-filename=-332af80c5eb5cf4e --out-dir /home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -C ar=riscv32-elf-ar -C linker=riscv32-elf-ld -L dependency=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/home/liam/repos/diosix/target/release/deps --extern riscv=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps/libriscv-9f27c1cf8cae7478.rlib -C link-arg=-Tsrc/platform/riscv32/sifive_e/link.ld -L native=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/build/diosix-8a0e4656ce8eac69/out -l static=entry`
warning: function is never used: `serial_write`
  --> src/kernel/main.rs:39:1
   |
39 | fn serial_write(s: &str) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(dead_code)] on by default
error: Could not compile `diosix`.
Caused by:
  process didn't exit successfully: `rustc --crate-name kernel src/kernel/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort --cfg 'feature="sifive_e"' -C metadata=332af80c5eb5cf4e -C extra-filename=-332af80c5eb5cf4e --out-dir /home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -C ar=riscv32-elf-ar -C linker=riscv32-elf-ld -L dependency=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/home/liam/repos/diosix/target/release/deps --extern riscv=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/deps/libriscv-9f27c1cf8cae7478.rlib -C link-arg=-Tsrc/platform/riscv32/sifive_e/link.ld -L native=/home/liam/repos/diosix/target/riscv32imac-unknown-none-elf/release/build/diosix-8a0e4656ce8eac69/out -l static=entry` (signal: 11, SIGSEGV: invalid memory reference)
make: *** [Makefile:2: all] Error 101

It is totally unclear to me what registers are allowed to be used where(this is because I have no idea what I am doing).

btw im on nightly: rustc 1.30.0-nightly (2ab3eba30 2018-09-14)
btw here is the code this is all based off of: "https://github.com/diodesign/diosix"
I really love rust-lang and I would love to hear back :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)O-riscvTarget: RISC-V architecturerequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions