Skip to content

[Bug] RISC-V RT-Smart:使用 Newlib 工具链编译 vDSO 时 CLOCK_* 常量未定义 #12025

Closed

Description

@zijunteng238-dot

RT-Thread Version

RT-Thread 5.4.0,分支 issue_3 Commit: f50c9bf

Affected area

RT-Smart

Hardware/BSP vendor

Not applicable / Other

Architecture

RISC-V

Board and hardware details

BSP:bsp/qemu-virt64-riscv 运行平台:QEMU virt,RV64,S-mode 启用 RT_USING_SMART、RT_USING_CLOCK_TIME 和 RT_USING_VDSO。 问题发生于编译阶段,尚未进入 QEMU 运行阶段。

Develop Toolchain

GCC

Describe the bug

在 qemu-virt64-riscv BSP 中启用 RT-Smart 和 vDSO 后,使用基于 Newlib 的 RISC-V GCC 工具链编译,vDSO 用户态源码因多个 CLOCK_* 常量未定义而编译失败。

开发环境

  • 工具链:SiFive GCC-Metal 10.2.0-2020.12.8
  • 编译器:riscv64-unknown-elf-gcc 10.2.0
  • C 库:Newlib 4.1.0
  • BSP:bsp/qemu-virt64-riscv

复现步骤

  1. 配置 RTT_EXEC_PATH,指向上述工具链的实际 bin 目录。
  2. 设置工具链前缀:
    export RTT_CC_PREFIX=riscv64-unknown-elf-
  3. 在 bsp/qemu-virt64-riscv 目录运行 scons --menuconfig,确保启用:
    CONFIG_RT_USING_SMART=y
    CONFIG_RT_USING_CLOCK_TIME=y
    CONFIG_RT_USING_POSIX_CLOCK=y
    CONFIG_RT_USING_VDSO=y
    
  4. 保存配置并编译:
    scons -j8

实际结果

以下为完整报错:
(base) tengzijun@tengzijun-virtual-machine:~/rt-thread/bsp/qemu-virt64-riscv$ scons -j8
scons: Reading SConscript files ...
scons: Entering directory `/home/tengzijun/rt-thread/components/lwp/vdso/user'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
riscv64-unknown-elf-gcc -o build/risc-v/vdso_clock_gettime.os -c -mcmodel=medany -march=rv64imafdc -mabi=lp64 -Wall -Wextra -Wno-unused-parameter -Wno-cpp -std=gnu99 -O2 -fPIC -ffreestanding -fno-builtin -fvisibility=hidden -nostdlib -nostartfiles -fPIC -I. -Icommon -Iarch/risc-v -I/home/tengzijun/rt-thread/components/lwp/vdso common/vdso_clock_gettime.c
common/vdso_clock_gettime.c: In function 'rt_vdso_resolve_clock_index':
common/vdso_clock_gettime.c:17:10: error: 'CLOCK_REALTIME_COARSE' undeclared (first use in this function); did you mean 'CLOCK_REALTIME'?
17 | case CLOCK_REALTIME_COARSE:
| ^~~~~~~~~~~~~~~~~~~~~
| CLOCK_REALTIME
common/vdso_clock_gettime.c:17:10: note: each undeclared identifier is reported only once for each function it appears in
common/vdso_clock_gettime.c:21:10: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
21 | case CLOCK_MONOTONIC:
| ^~~~~~~~~~~~~~~
common/vdso_clock_gettime.c:22:10: error: 'CLOCK_MONOTONIC_COARSE' undeclared (first use in this function)
22 | case CLOCK_MONOTONIC_COARSE:
| ^~~~~~~~~~~~~~~~~~~~~~
common/vdso_clock_gettime.c:23:10: error: 'CLOCK_MONOTONIC_RAW' undeclared (first use in this function)
23 | case CLOCK_MONOTONIC_RAW:
| ^~~~~~~~~~~~~~~~~~~
common/vdso_clock_gettime.c:24:10: error: 'CLOCK_BOOTTIME' undeclared (first use in this function); did you mean 'CLOCK_REALTIME'?
24 | case CLOCK_BOOTTIME:
| ^~~~~~~~~~~~~~
| CLOCK_REALTIME
scons: *** [build/risc-v/vdso_clock_gettime.os] Error 1
scons: building terminated because of errors.
exec command: "scons -C /home/tengzijun/rt-thread/components/lwp/vdso/user RTT_VDSO_ARCH=risc-v" failed.

Other additional context

初步排查发现:

  • vDSO 用户态代码通过 vdso_user_internal.h 包含工具链的 <time.h>。
  • 当前工具链中,部分 CLOCK_* 定义受 __GNU_VISIBLE 或 _POSIX_MONOTONIC_CLOCK 等条件控制。
  • 按当前 vDSO 编译条件预处理 <time.h>,上述报错涉及的常量没有暴露。
  • 初步怀疑与 vDSO 构建配置和 Newlib 头文件兼容性有关,尚未确认最终修复方式。

Activity

  1. github-actions commented on Nov 10, 2026

    @github-actions

    如需认领并处理此 Issue,请评论 /claim。

    To claim and work on this issue, comment /claim.

  2. BernardXiong commented on Nov 10, 2026

    @BernardXiong
    Member

    已复现:在 master(f50c9bf7fbfcd2cc5eb7990b82464c0331868fb7)上用 xpack riscv-none-elf-gcc 12.3.0 编译 vDSO 用户态代码,报错与报告一致。原因是 newlib 只有在 _GNU_SOURCE / _POSIX_MONOTONIC_CLOCK 下才暴露这些 CLOCK_* 常量,而 freestanding 的 vDSO 构建没有定义它们。

    修复 PR:#12028,在 vdso_user_internal.h 中按 ABI 数值为缺失常量提供兜底定义。已验证 C 源文件可以编译通过;完整 libvdso.so 链接未用该工具链验证,因为 xpack 裸机链接器不支持 -shared(与本次改动无关)。

  3. BernardXiong commented on Nov 10, 2026

    @BernardXiong
    Member

    修正:
    针对rt-smart,工具链必须使用 特殊的 (修改musl libc版本的 gcc)工具链,不支持普通的 newlib 工具链。所以这个问题不应该去处理!

  4. cms19859230182-lang commented on Nov 12, 2026

    @cms19859230182-lang
    Contributor

    已在 master (611d7c07d5dd32757ac6d363576e5f0e8b915c3c) 上确认 vDSO 用户库仍缺这四个 CLOCK_* 常量。修复 PR:#12041。新增 vdso_clockid_compat.h,对缺失常量按 Linux ABI 兜底(RAW=4、REALTIME_COARSE=5、MONOTONIC_COARSE=6、BOOTTIME=7),未改动 vdso_clock_gettime.c 的 clock 到 index 映射,也不同于已关闭的 #12028。

  5. removed
    bugThis PR/issue is a bug in the current code.
    on Nov 12, 2026
  6. BernardXiong commented on Nov 12, 2026

    @BernardXiong
    Member

    这个issue先关闭,后续需要给出一些关系说明。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arch: RISC-VBSP related with risc-vRT-SmartRT-Thread Smart related PR or issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions