refactor(someboot): share linker script fragments#1218
Merged
Conversation
Merged
ZR233
marked this pull request as ready for review
June 11, 2026 05:28
Contributor
There was a problem hiding this comment.
审查结论:APPROVE
本 PR 对 someboot 的 linker script 进行了合理的去重重构,同时附带修复了 axbuild host HTTP 端口并发问题。经审查和本地验证,未发现阻塞性问题。
变更概述
- Linker script 片段化 (
components/someboot/src/ld/): 将四架构link.ld中重复的 section 布局拆分为 defaults、text、rodata、data、rela-dyn、bss、debug、discard-exit、discard-dynamic 等公共片段。 - 模板渲染 (
build_support/linker.rs): 新增render_linker_script()函数,通过替换表机制将公共片段 + 架构专属差异渲染为最终someboot.x,保持与somehal的INCLUDE "someboot.x"外部契约不变。 - 架构专属保留: 各架构
link.ld仅保留OUTPUT_ARCH、ENTRY、PHDRS、.head.text、LoongArch exception vectors、RISC-V dynamic sections、AArch64 init_array、x86_64 image header 符号等不可共享内容。 - 测试覆盖 (
tests/linker_templates.rs): 3 个 test 覆盖公共符号契约(__kernel_load_end、__bss_start/stop、__cpu0_stack_top等)、各架构专属内容(OUTPUT_ARCH、_kernel_entry、.init_array等)、以及 cargo rerun 路径完整性。 - axbuild 端口修复 (
scripts/axbuild/src/test/host_http.rs): 当固定端口被AddrInUse时,bind_listener以 50ms 间隔重试最多 180s,避免同一 self-hosted runner 上并发 QEMU 测试因端口复用直接失败。
审查结果
- 格式化与 diff 卫生:
cargo fmt --check通过,git diff --check无空白/冲突标记问题。 - 无 crates.io patch: 全文搜索
[patch.crates-io]在 workspaceCargo.toml中无匹配,不违反 crates.io patch 策略。 - 本地测试:
cargo test -p someboot --test linker_templates→ 3/3 passedcargo test -p axbuild host_http→ 6/6 passed(含新增的same_host_http_port_waits_for_active_guard和generated_body_serves_configured_size_and_byte)
- CI 状态: 整体 workflow
success。实际运行的 job 全部通过:Check formatting / run_host、Run sync-lint / run_container、Run clippy / run_host、ArceOS/Starry/Axvisor 各架构 QEMU 测试(x86_64/aarch64/riscv64/loongarch64)均 success。跳过的 job(Publish base container image、Publish axvisor-lvz container image、Check formatting / run_container、Run sync-lint / run_host)属于互斥 matrix 分支或分支限制的正常行为。 - 重复/重叠分析: 在 dev 分支历史中,最近的 someboot linker 变更为
8c19969ef feat(someboot): boot LoongArch dynamic UEFI with SMP,与本 PR 的 linker 片段化重构不重叠。当前开放的 PR #1217(mmap readahead)和 #1219(release-plz 自动发布,包含此 PR 的版本更新)均与本 PR 无关或为下游。
实现质量
render_linker_script中的替换顺序正确:先替换片段 token,再替换架构专属变量,最后替换kernel_load_vaddr/kernel_load_paddr,避免 token 嵌套问题。source_paths()涵盖所有架构模板和共享片段,加上build_support/linker.rs自身,确保 Cargo 在任意文件变更时正确重新生成 linker script。LinkerConfig直接传递kernel_load_vaddr和kernel_load_paddr,而非通过环境变量或全局状态,保持纯函数特性,便于测试。- RISC-V 架构的
link.ld末尾仍保留了硬编码的/DISCARD/段(.eh_frame、.note、.comment),这是 RISC-V 特有的 discard 需求(不同于其他架构的ld_discard_dynamic+ld_discard_exit模式),保留合理。 host_http.rs的bind_listener在重试循环中包含reported_wait标志,避免日志刷屏,同时BIND_RETRY_TIMEOUT(180s)覆盖了典型 QEMU 测试的超时范围。
未解决问题
无。本 PR 已达到合并标准(实际上已合并),代码质量良好、测试充分、CI 全绿。
Powered by deepseek-v4-pro
Closed
luodeb
pushed a commit
that referenced
this pull request
Jun 30, 2026
* refactor(someboot): share linker script fragments * fix(axbuild): wait for host HTTP port reuse
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.
背景
someboot四个架构的link.ld中存在大量重复的 section 布局、公共符号和 discard 规则。重复维护这些内容时,后续调整容易漏改某个架构,尤其是__kernel_load_end、BSS 范围、percpu 区间和 CPU0 栈等启动契约相关符号。本 PR 首轮 CI 还暴露出 ArceOS rust QEMU 用例在 self-hosted runner 上启动 host HTTP fixture 时,固定端口可能被并发测试临时占用,导致测试在启动 QEMU 前失败。
修改内容
components/someboot/src/ld/,把通用 linker script 片段拆分为 defaults、text、rodata、data、rela、bss、debug、discard 等文件。components/someboot/build_support/linker.rs,由build.rs通过include_str!读取 arch 模板和公共片段,并内联渲染最终的someboot.x。link.ld中的架构专属内容,包括OUTPUT_ARCH、ENTRY、PHDRS、.head.text、LoongArch exception vectors、RISC-V dynamic sections、AArch64 init array、x86_64 image header 符号等。components/someboot/tests/linker_templates.rs,覆盖公共符号、架构专属契约和 Cargo rerun 路径,避免后续调整遗漏模板或片段。axbuild的 host HTTP server 启动逻辑:当固定端口暂时被占用时有限等待并重试,避免同一 runner 上并发 QEMU 测试因端口复用直接失败。实现逻辑
公共 section 布局保留在 ld 片段中,架构差异通过渲染 helper 的替换表显式传入。这样生成产物仍然是单个
someboot.x,不会改变somehal对INCLUDE "someboot.x"的外部链接契约,也避免在最终链接时额外依赖公共片段搜索路径。host HTTP fixture 的端口号仍由各测试配置和 guest 测试代码保持一致;本 PR 只在 host 侧绑定遇到
AddrInUse时等待已有占用释放,不改变 guest 访问地址和 QEMU 配置语义。本地验证
cargo fmt --checkgit diff --checkcargo test -p someboot --test linker_templatescargo test -p axbuild host_httpcargo xtask clippy --package somebootcargo xtask clippy --package axbuild