Giter Site home page Giter Site logo

Comments (31)

DylanYang00 avatar DylanYang00 commented on May 22, 2024 15

明白了,前面没有说要加入 mod lang_items

from rcore-tutorial-book-v3.

wei-huan avatar wei-huan commented on May 22, 2024 5

如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句
mod lang_items;

main.rs:

#![no_std]

mod lang_items;

fn main() {
// println!("Hello, world!");
}

然后就可以继续执行了

from rcore-tutorial-book-v3.

yilozt avatar yilozt commented on May 22, 2024 4

@pluveto ,将 rust-analyzer.checkOnSave.target 设置为 riscv64gc-unknown-none-elf 就可以了:

{
    "rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
    "rust-analyzer.checkOnSave.allTargets": false,
    "rust-analyzer.checkOnSave.target": "riscv64gc-unknown-none-elf"
}

之后 vscode 就没有报错了。

from rcore-tutorial-book-v3.

wyfcyx avatar wyfcyx commented on May 22, 2024 3

@leonhxx 请先输入以下命令安装一下相关软件:

rustup target add riscv64gc-unknown-none-elf
cargo install cargo-binutils --vers ~0.2
rustup component add llvm-tools-preview
rustup component add rust-src

from rcore-tutorial-book-v3.

LimingFang avatar LimingFang commented on May 22, 2024 3

补充:vscode上如果加上#[no_std]提示cann't find crate for test
refer

rust-lang/rust-analyzer#3801

from rcore-tutorial-book-v3.

Dyqer avatar Dyqer commented on May 22, 2024 1

通过下面命令添加rust-std
rustup target add riscv64gc-unknown-none-elf

from rcore-tutorial-book-v3.

DylanYang00 avatar DylanYang00 commented on May 22, 2024 1

请问为何写了lang_items.rs后仍然提示
error: #[panic_handler] function required, but not found呢?
(用的是前面配好的docker环境)

from rcore-tutorial-book-v3.

wyfcyx avatar wyfcyx commented on May 22, 2024 1

@wei-huan 差不多吧。

from rcore-tutorial-book-v3.

SnowWarri0r avatar SnowWarri0r commented on May 22, 2024 1

补充:vscode上如果加上#[no_std]提示cann't find crate for test refer

rust-analyzer/rust-analyzer#3801

不起作用。我的配置:

{
    "rust.target": "riscv64gc-unknown-none-elf",
    "rust.all_targets": false,
    "rust-analyzer.cargo-watch.allTargets": false,
    "rust-analyzer.cargo-watch.arguments": [
        "--target",
        "riscv64gc-unknown-none-elf"
    ]
}

使用的插件:两个都试过,都不行。

错误信息:

can't find crate for `test`

对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在 settings.json 加入以下配置

{
  "cargo.automaticCheck": false
}

对于此错误的猜想,我也是从这里获取的灵感:rust-lang/rust-analyzer#3801 (comment)

from rcore-tutorial-book-v3.

leonhxx avatar leonhxx commented on May 22, 2024

使用清华网盘镜像里的Ubuntu时,加上#![no_std] 来告诉 Rust 编译器不使用 Rust 标准库 std后,报的错误和书里的有点不一样,我这儿的异常信息如下,请问还需要安装软件么?
error[E0463]: can't find crate for core
|
= note: the riscv64gc-unknown-none-elf target may not be installed

error: aborting due to previous error

For more information about this error, try rustc --explain E0463.
error: could not compile os

from rcore-tutorial-book-v3.

leonhxx avatar leonhxx commented on May 22, 2024

@wyfcyx 多谢呀!!

from rcore-tutorial-book-v3.

storage-db avatar storage-db commented on May 22, 2024

error: language item required, but not found: eh_personality

error: aborting due to previous error

error: could not compile Os
你好我照着做以后出现这个报错是为什么呢?

from rcore-tutorial-book-v3.

wyfcyx avatar wyfcyx commented on May 22, 2024

@eulerf 请按照这里所提到的:

我们首先在 os 目录下新建 .cargo 目录,并在这个目录下创建 config 文件,并在里面输入如下内容:

# os/.cargo/config
[build]
target = "riscv64gc-unknown-none-elf"

进行交叉编译,避免编译到x86目标。

from rcore-tutorial-book-v3.

storage-db avatar storage-db commented on May 22, 2024

from rcore-tutorial-book-v3.

storage-db avatar storage-db commented on May 22, 2024

from rcore-tutorial-book-v3.

wei-huan avatar wei-huan commented on May 22, 2024

Rust的mod是不是相当于C语言的include

from rcore-tutorial-book-v3.

Joeyscat avatar Joeyscat commented on May 22, 2024

Entry入口不等于0,反汇编也是有对应代码的,跟教程不一致,请问是什么原因呢

➜  os git:(master) ✗ cat src/main.rs
#![no_std]
#![no_main]

mod lang_items;
➜  os git:(master) ✗ cat src/lang_items.rs
use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}
➜  os git:(master) ✗ rust-readobj -h target/riscv64gc-unknown-none-elf/debug/os

File: target/riscv64gc-unknown-none-elf/debug/os
Format: elf64-littleriscv
Arch: riscv64
AddressSize: 64bit
LoadName: <Not found>
ElfHeader {
  Ident {
    Magic: (7F 45 4C 46)
    Class: 64-bit (0x2)
    DataEncoding: LittleEndian (0x1)
    FileVersion: 1
    OS/ABI: SystemV (0x0)
    ABIVersion: 0
    Unused: (00 00 00 00 00 00 00)
  }
  Type: Executable (0x2)
  Machine: EM_RISCV (0xF3)
  Version: 1
  Entry: 0x11120
  ProgramHeaderOffset: 0x40
  SectionHeaderOffset: 0x11C0
  Flags [ (0x5)
    EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
    EF_RISCV_RVC (0x1)
  ]
  HeaderSize: 64
  ProgramHeaderEntrySize: 56
  ProgramHeaderCount: 4
  SectionHeaderEntrySize: 64
  SectionHeaderCount: 15
  StringTableSectionIndex: 13
}
➜  os git:(master) ✗ rust-objdump -S target/riscv64gc-unknown-none-elf/debug/os

target/riscv64gc-unknown-none-elf/debug/os:     file format elf64-littleriscv


Disassembly of section .text:

0000000000011120 <rust_begin_unwind>:
; fn panic(_info: &PanicInfo) -> ! {
   11120: 41 11         addi    sp, sp, -16
   11122: 2a e4         sd      a0, 8(sp)
   11124: 09 a0         j       0x11126 <rust_begin_unwind+0x6>
;     loop {}
   11126: 01 a0         j       0x11126 <rust_begin_unwind+0x6>

from rcore-tutorial-book-v3.

chyyuu avatar chyyuu commented on May 22, 2024

Q:为何在 main.rs中要加入 mod lang_items; 这条语句?
A: 由于os是 no_std程序,所以没法调用panic!等属于rust std库中的宏。从ch1开始,我们就写了 lang_items.rs , 实现了自己的panic!宏,这就是你指出的 mod lang_items; 表示 main.rs 要调用的panic!,将是自己在写的lang_items.rs中的panic!宏。

from rcore-tutorial-book-v3.

iruhh avatar iruhh commented on May 22, 2024

希望能在“我们创建一个新的子模块 lang_items.rs 实现panic函数......编译器用panic函数来对接 panic! 宏:”的位置添上“并在main.rs #![no_std]的下方加上mod lang_items;来声明模块”

然后把下面的Rust Tips:Rust 模块化编程的链接贴一个在附近。

from rcore-tutorial-book-v3.

wyfcyx avatar wyfcyx commented on May 22, 2024

@iruhh 好主意。

from rcore-tutorial-book-v3.

pluveto avatar pluveto commented on May 22, 2024

补充:vscode上如果加上#[no_std]提示cann't find crate for test refer

rust-analyzer/rust-analyzer#3801

不起作用。我的配置:

{
    "rust.target": "riscv64gc-unknown-none-elf",
    "rust.all_targets": false,
    "rust-analyzer.cargo-watch.allTargets": false,
    "rust-analyzer.cargo-watch.arguments": [
        "--target",
        "riscv64gc-unknown-none-elf"
    ]
}

使用的插件:两个都试过,都不行。

错误信息:

can't find crate for `test`

from rcore-tutorial-book-v3.

MrZLeo avatar MrZLeo commented on May 22, 2024

补充:vscode上如果加上#[no_std]提示cann't find crate for test refer

rust-analyzer/rust-analyzer#3801

不起作用。我的配置:

{
    "rust.target": "riscv64gc-unknown-none-elf",
    "rust.all_targets": false,
    "rust-analyzer.cargo-watch.allTargets": false,
    "rust-analyzer.cargo-watch.arguments": [
        "--target",
        "riscv64gc-unknown-none-elf"
    ]
}

使用的插件:两个都试过,都不行。
错误信息:

can't find crate for `test`

对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在 settings.json 加入以下配置

{
  "cargo.automaticCheck": false
}

对于此错误的猜想,我也是从这里获取的灵感:rust-analyzer/rust-analyzer#3801 (comment)

nvim.coc 中使用 rust-analyzer 时,在CoC配置中写入:

"rust-analyzer.checkOnSave.allTargets": false,

可避免问题。

from rcore-tutorial-book-v3.

An-n-ya avatar An-n-ya commented on May 22, 2024

噗哈哈哈哈, 写了个寂寞, 全删掉了🤣

from rcore-tutorial-book-v3.

lemon5227 avatar lemon5227 commented on May 22, 2024

依照在本章最后,换回之前默认的 x86_64-unknown-linux-gnu,cargo build 以后,有一个报错始终出现

error: language item required, but not found: `eh_personality`
  |
  = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
  = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

error: `#[panic_handler]` function required, but not found

from rcore-tutorial-book-v3.

DrYaling avatar DrYaling commented on May 22, 2024

楼主文档写得很详细也比较容易看懂,但是代码能不能加点注释

from rcore-tutorial-book-v3.

zhuiYeah avatar zhuiYeah commented on May 22, 2024

he@ubuntu:/C_TEST/os$ rust-objdump -S target/riscv64gc-unknown-none-elf/debug/os
Failed to execute tool: objdump
No such file or directory (os error 2)
he@ubuntu:
/C_TEST/os$ rust-readobj -h target/riscv64gc-unknown-none-elf/debug/os
Failed to execute tool: readobj
No such file or directory (os error 2)

那个反汇编工具用不了啊

from rcore-tutorial-book-v3.

Wonderland2333 avatar Wonderland2333 commented on May 22, 2024

如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句
mod lang_items;

main.rs:

#![no_std]

mod lang_items;

fn main() {
// println!("Hello, world!");
}

然后就可以继续执行了

这里的main.rs:的冒号报错了

from rcore-tutorial-book-v3.

Unik-lif avatar Unik-lif commented on May 22, 2024

依照在本章最后,换回之前默认的 x86_64-unknown-linux-gnu,cargo build 以后,有一个报错始终出现

error: language item required, but not found: `eh_personality`
  |
  = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
  = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

error: `#[panic_handler]` function required, but not found

对照博客做吧,三元组不一样,不是改一个参数就能解决掉的。(虽然改动确实也不大)

from rcore-tutorial-book-v3.

jklincn avatar jklincn commented on May 22, 2024

对于 error[E0463]: can't find crate for test 问题,可以将 rust-analyzer.check.allTargets 设置为 false。在设置界面修改或写入 setting.json 文件都可以。

另外,这是在 os 目录下有 .cargo/config 文件注明了 target,如果没有此文件,可能还需加入 target。
比如,"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",

from rcore-tutorial-book-v3.

lwb-2021 avatar lwb-2021 commented on May 22, 2024

补充:vscode上如果加上#[no_std]提示cann't find crate for test refer

rust-analyzer/rust-analyzer#3801

不起作用。我的配置:

{
    "rust.target": "riscv64gc-unknown-none-elf",
    "rust.all_targets": false,
    "rust-analyzer.cargo-watch.allTargets": false,
    "rust-analyzer.cargo-watch.arguments": [
        "--target",
        "riscv64gc-unknown-none-elf"
    ]
}

使用的插件:两个都试过,都不行。
错误信息:

can't find crate for `test`

对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在 settings.json 加入以下配置

{
  "cargo.automaticCheck": false
}

对于此错误的猜想,我也是从这里获取的灵感:rust-lang/rust-analyzer#3801 (comment)

确实是cargo插件的问题,一个巨坑

{
   "cargo.automaticCheck": false
}

这行东西最新版本好像没有用,我的选择是直接删除cargo插件

from rcore-tutorial-book-v3.

KeriaDaring avatar KeriaDaring commented on May 22, 2024

我取消了config中的[build]设置,也就是切换到了x86_64-unknown-linux-gnu,按照blogOS的教程在cargo.toml中添加了如下代码,禁用多处 panic! 栈展开

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

在这之后遇到了linker cc error
原因大概是在这样的三元组链接条件下,linux上的c库需要找到入口函数
但是我们没有:(
因此使用如下命令 成功完成build

cargo rustc -- -C link-arg=-nostartfiles

Done!

from rcore-tutorial-book-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.