Skip to content

Conversation

@unicornx
Copy link
Contributor

@unicornx unicornx commented Apr 11, 2025

libcpu/risc-v/common64/mmu.c 会使用外部符号 "__bss_end"(这个符号一般定义在链接脚本中),但问题是目前 libcpu 的源文件依赖于 bsp 的 ”board.h“ 中对这个符号的 extern 声明。

这么做本身不会报错,但是不是一个好的编程习惯,对内核的扩展是不利的。这会导致内核的 core(libpcu)对 bsp 的头文件产生依赖。而且这样对 bsp 的 "board.h" 会产生特别的要求,譬如强制要求在 "board.h" 中对这些 "__bss_end" 符号进行 extern 声明, 这个应该避免而且是非必须的。

解决方案:如果是 libcpu 本地使用到了这个 extern 的符号,直接在本地声明就好了。

但这个补丁的改动目前只是在 libcpu 内部显式地 extern 声明 ”__bss_end“。没有删除诸如 ”#include <board.h>" 的操作。因为涉及修改太大,需要涉及的 bsp 自己都清理后才好统一做 libcpu 的清理。所以目前先在 libcpu 中自己加上 extern 声明,确保新的 bsp 中不会发生即使不使用也需要强制声明 “__bss_end" 这些符号的情况。

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

libcpu/risc-v/common64/mmu.c uses the external
symbol "__bss_end" (this symbol generally is
defined in the link script file) and depends
on the extern declaration of this symbol in
the bsp's "board.h". This is not a problem in
implementation, but it is not a good habit.

If this extern symbol is used locally, just
declare it locally should be better.

In this way, there will be no dependency of
the kernel core on the bsp header file. And
there will be no special requirements for the
bsp board code, such as the need to make
extern declarations for these "__bss_end"
symbols in "board.h".

This patch currently only explicitly externly
declares "__bss_end" inside libcpu itself.
The code of "#include <board.h>" is kept, because
the modification involved is too large, it is
necessary to clean up the bsp involved before
cleaning this include code line uniformly.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
@github-actions github-actions bot added Arch: RISC-V BSP related with risc-v libcpu labels Apr 11, 2025
@unicornx unicornx requested a review from Rbb666 April 11, 2025 05:42
@Rbb666 Rbb666 merged commit 312f9db into RT-Thread:master Apr 11, 2025
55 checks passed
@unicornx unicornx deleted the dev-symbol-extern branch April 11, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: RISC-V BSP related with risc-v libcpu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants