Skip to content

Conversation

Tang-Haojin
Copy link
Contributor

@Tang-Haojin Tang-Haojin commented Sep 1, 2025

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

[

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

在编译 bsp/qemu-virt64-riscv 时,我尝试打开了 cpp 支持:

diff --git a/bsp/qemu-virt64-riscv/.config b/bsp/qemu-virt64-riscv/.config
index 3a1a2558f1..9db5bc73fa 100644
--- a/bsp/qemu-virt64-riscv/.config
+++ b/bsp/qemu-virt64-riscv/.config
@@ -392,7 +392,7 @@ CONFIG_RT_USING_POSIX_PIPE_SIZE=512
 # end of Interprocess Communication (IPC)
 # end of POSIX (Portable Operating System Interface) layer
 
-# CONFIG_RT_USING_CPLUSPLUS is not set
+CONFIG_RT_USING_CPLUSPLUS=y
 # end of C/C++ and POSIX layer
 
 #

在这一操作过后,编译时遇到了 (1) 一个error 和 (2) 一个warning。这个 PR 是为了解决问题 (1),问题 (2) 将在另一个 PR 中完成解决。

问题现象

开启 CONFIG_RT_USING_CPLUSPLUS 后,编译报错:

/nfs/home/tanghaojin/rt-thread-3/include/rthw.h:197:5: error: conflicting declaration of 'int rt_hw_cpu_id()' with 'C' linkage
  197 | int rt_hw_cpu_id(void);
      |     ^~~~~~~~~~~~
/nfs/home/tanghaojin/rt-thread-3/libcpu/risc-v/common64/cpuport.h:46:5: note: previous declaration with 'C++' linkage
   46 | int rt_hw_cpu_id(void);
      |     ^~~~~~~~~~~~

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

删去 libcpu/risc-v/common64/cpuport.h 中的 int rt_hw_cpu_id(void); 函数声明。

为什么可以直接删掉

简而言之,该函数已经在其他头文件中声明,并且所有调用该函数的相关文件均已包含这些头文件中的至少一个。以下是详细说明:

  1. int rt_hw_cpu_id(void)rthw.h 中已经声明过了;rtthread.h 中包含的 rtatomic.h 中,包含了 rthw.hsmp_call.h 中包含了 rtthread.h
# rthw.h
$ grep -rnw 'int rt_hw_cpu_id(void);' include/rthw.h
197:int rt_hw_cpu_id(void);

# rtthread.h
$ grep -rnw '#include <rtatomic.h>' include/rtthread.h
35:#include <rtatomic.h>
$ grep -rnw '#include <rthw.h>' include/rtatomic.h
14:#include <rthw.h>
62:#include <rthw.h>

# smp_call.h
$ grep -rnw '#include <rtthread.h>' components/drivers/smp_call/smp_call.h
14:#include <rtthread.h>
  1. 找出所有 int rt_hw_cpu_id(void); 的函数调用;
$ find . -type f -exec grep -l 'rt_hw_cpu_id()' {} \;
./components/drivers/nvme/nvme.c
./components/drivers/smp_call/smp_call.c
./components/drivers/ofw/fdt.c
./components/drivers/pic/pic-gicv3-its.c
./components/drivers/pic/pic-gicv3.c
./components/drivers/pic/pic.c
./components/drivers/pic/pic-gicv2.c
./libcpu/arm/cortex-r52/gicv3.c
./libcpu/arm/cortex-a/trap.c
./libcpu/arm/cortex-a/gicv3.c
./libcpu/arm/cortex-a/cpuport.c
./libcpu/aarch64/common/interrupt.c
./libcpu/aarch64/common/trap.c
./libcpu/aarch64/common/gicv3.c
./libcpu/aarch64/common/setup.c
./examples/utest/testcases/smp_call/smp_003_tc.c
./examples/utest/testcases/smp_call/smp_004_tc.c
./examples/utest/testcases/smp_call/smp_002_tc.c
./examples/utest/testcases/smp_call/smp_001_tc.c
./examples/utest/testcases/kernel/smp/smp_bind_affinity_tc.c
./examples/utest/testcases/kernel/smp/smp_affinity_pri2_tc.c
./examples/utest/testcases/kernel/smp/smp_affinity_pri1_tc.c
./examples/utest/testcases/kernel/sched_sem_tc.c
./src/scheduler_mp.c
./src/cpu_mp.c
./ChangeLog.md
./bsp/renesas/libraries/HAL_Drivers/drv_common.c
./bsp/raspberry-pi/raspi4-64/drivers/drv_gtimer.c
./bsp/raspberry-pi/raspi4-64/drivers/board.c
./bsp/raspberry-pi/raspi3-64/driver/board.c
./bsp/raspberry-pi/raspi3-32/applications/test_device.c
./bsp/raspberry-pi/raspi3-32/cpu/interrupt.c
./bsp/raspberry-pi/raspi3-32/cpu/trap.c
./bsp/raspberry-pi/raspi3-32/driver/board.c
./bsp/phytium/libraries/common/phytium_interrupt.c
./bsp/phytium/libraries/drivers/drv_i2c_msg.c
./bsp/phytium/libraries/drivers/drv_i2s.c
./bsp/phytium/libraries/drivers/drv_gpio.c
./bsp/phytium/libraries/drivers/drv_can.c
./bsp/phytium/libraries/drivers/drv_spi.c
./bsp/phytium/libraries/drivers/drv_sdif.c
./bsp/phytium/libraries/drivers/drv_sdif_msg.c
./bsp/phytium/libraries/drivers/drv_spi_msg.c
./bsp/phytium/aarch32/applications/main.c
./bsp/phytium/board/smp_sgi_test.c
./bsp/phytium/board/secondary_cpu.c
./bsp/phytium/board/board.c
./bsp/phytium/aarch64/applications/main.c
./bsp/raspberry-pico/RP2040/libcpu/cpuport.c
./bsp/qemu-vexpress-a9/drivers/secondary_cpu.c
./bsp/nuvoton/libraries/ma35/rtt_port/drv_common_aarch32.c
./bsp/nuvoton/libraries/ma35/rtt_port/drv_hwsem.c
./bsp/nuvoton/libraries/nu_packages/Demo/smp_demo.c
./bsp/nuvoton/libraries/nu_packages/Demo/hwsem_counter.c
./bsp/nuvoton/numaker-hmi-ma35d1/applications/main.c
./bsp/nuvoton/numaker-iot-ma35d1/applications/main.c
./bsp/rockchip/rk3568/driver/board.c
  1. 排除和 libcpu/risc-v/common64 无关的文件(即非代码文件或与 RISC-V 无关的 bsp/libcpu),剩下的文件列表 (file.f) 如下:
./components/drivers/nvme/nvme.c
./components/drivers/smp_call/smp_call.c
./components/drivers/ofw/fdt.c
./components/drivers/pic/pic-gicv3-its.c
./components/drivers/pic/pic-gicv3.c
./components/drivers/pic/pic.c
./components/drivers/pic/pic-gicv2.c
./examples/utest/testcases/smp_call/smp_003_tc.c
./examples/utest/testcases/smp_call/smp_004_tc.c
./examples/utest/testcases/smp_call/smp_002_tc.c
./examples/utest/testcases/smp_call/smp_001_tc.c
./examples/utest/testcases/kernel/smp/smp_bind_affinity_tc.c
./examples/utest/testcases/kernel/smp/smp_affinity_pri2_tc.c
./examples/utest/testcases/kernel/smp/smp_affinity_pri1_tc.c
./examples/utest/testcases/kernel/sched_sem_tc.c
./src/scheduler_mp.c
./src/cpu_mp.c
  1. 在文件中查找 rthw.hrtthread.hsmp_call.h,发现文件列表里的所有文件均包含了上述头文件中的至少一个:
$ grep -rnwE --max-count 1 '(rthw.h|rtthread.h|smp_call.h)' $(cat file.f)
./components/drivers/nvme/nvme.c:11:#include <rthw.h>
./components/drivers/smp_call/smp_call.c:13:#include "smp_call.h"
./components/drivers/ofw/fdt.c:11:#include <rthw.h>
./components/drivers/pic/pic-gicv3-its.c:11:#include <rthw.h>
./components/drivers/pic/pic-gicv3.c:17:#include <rthw.h>
./components/drivers/pic/pic.c:11:#include <rthw.h>
./components/drivers/pic/pic-gicv2.c:16:#include <rthw.h>
./examples/utest/testcases/smp_call/smp_003_tc.c:14:#include <smp_call.h>
./examples/utest/testcases/smp_call/smp_004_tc.c:14:#include <smp_call.h>
./examples/utest/testcases/smp_call/smp_002_tc.c:14:#include <smp_call.h>
./examples/utest/testcases/smp_call/smp_001_tc.c:15:#include <smp_call.h>
./examples/utest/testcases/kernel/smp/smp_bind_affinity_tc.c:11:#include <rtthread.h>
./examples/utest/testcases/kernel/smp/smp_affinity_pri2_tc.c:11:#include <rtthread.h>
./examples/utest/testcases/kernel/smp/smp_affinity_pri1_tc.c:11:#include <rtthread.h>
./examples/utest/testcases/kernel/sched_sem_tc.c:12:#include <rtthread.h>
./src/scheduler_mp.c:39:#include <rtthread.h>
./src/cpu_mp.c:13:#include <rthw.h>

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

  • BSP: bsp/qemu-virt64-riscv
  • .config: CONFIG_RT_USING_CPLUSPLUS=y
  • 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/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@github-actions github-actions bot added Arch: RISC-V BSP related with risc-v libcpu labels Sep 1, 2025
Copy link

github-actions bot commented Sep 1, 2025

📌 Code Review Assignment

🏷️ Tag: libcpu_riscv

Reviewers: @Yaochenger

Changed Files (Click to expand)
  • libcpu/risc-v/common64/cpuport.h

📊 Current Review Status (Last Updated: 2025-09-01 13:55 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@Rbb666
Copy link
Member

Rbb666 commented Sep 1, 2025

感谢PR,这类问题希望作者可以提一个PR,把此类的配置添加到ci.attachconfig.yml中,这样类似的编译问题会被CI编译检测到了:https://github.com/RT-Thread/rt-thread/blob/master/bsp/qemu-vexpress-a9/.ci/attachconfig/ci.attachconfig.yml

@Rbb666 Rbb666 merged commit b27e405 into RT-Thread:master Sep 1, 2025
61 checks passed
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