libcpu: riscv: declare external symbols inside#10181
Merged
Rbb666 merged 1 commit intoRT-Thread:masterfrom Apr 11, 2025
Merged
Conversation
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>
Rbb666
approved these changes
Apr 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up