components: libc: fix pointer-to-integer cast warnings and address tr…#10019
Merged
mysterywolf merged 1 commit intoRT-Thread:masterfrom Feb 22, 2025
Merged
components: libc: fix pointer-to-integer cast warnings and address tr…#10019mysterywolf merged 1 commit intoRT-Thread:masterfrom
mysterywolf merged 1 commit intoRT-Thread:masterfrom
Conversation
…uncation [Problem Description] 1. When enabling RT_USING_MODULE=y, compilation warnings occur: dlelf.c:386:27: warning: cast from pointer to integer of different size dlelf.c:398:25: warning: cast from pointer to integer of different size dlelf.c:408:24: warning: cast from pointer to integer of different size 2. On RV64 architectures (e.g. Sophgo SG2042 with RISC-V Sv39 and 40-bit physical addressing), dlsym may fail when accessing addresses beyond 32-bit range. [Root Cause] In dlmodule_load_relocated_object() and dlmodule_symbol_find(), pointer is cast to rt_uint32_t which truncates: | rt_ubase_t rodata_addr = (rt_uint32_t)ptr; This causes: - Warnings on 64-bit systems (pointer width > 32-bit) - Actual address truncation on RV64 when physical address exceeds 32-bit [Solution] Replace rt_uint32_t with architecture-adaptive rt_ubase_t: | rt_ubase_t rodata_addr = (rt_ubase_t)ptr; The rt_ubase_t is defined in include/rttypes.h as: | #ifdef ARCH_CPU_64BIT | typedef rt_uint64_t rt_ubase_t; | #else | typedef rt_uint32_t rt_ubase_t; | #endif This ensures correct width casting for both 32/64-bit architectures. Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>
BernardXiong
approved these changes
Feb 22, 2025
mysterywolf
approved these changes
Feb 22, 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.
…uncation
[Problem Description]
When enabling RT_USING_MODULE=y, compilation warnings occur: dlelf.c:386:27: warning: cast from pointer to integer of different size dlelf.c:398:25: warning: cast from pointer to integer of different size dlelf.c:408:24: warning: cast from pointer to integer of different size
On RV64 architectures (e.g. Sophgo SG2042 with RISC-V Sv39 and 40-bit physical addressing), dlsym may fail when accessing addresses beyond 32-bit range.
[Root Cause]
In dlmodule_load_relocated_object() and dlmodule_symbol_find(), pointer is cast to rt_uint32_t which truncates:
| rt_ubase_t rodata_addr = (rt_uint32_t)ptr;
This causes:
[Solution]
Replace rt_uint32_t with architecture-adaptive rt_ubase_t: | rt_ubase_t rodata_addr = (rt_ubase_t)ptr;
The rt_ubase_t is defined in include/rttypes.h as: | #ifdef ARCH_CPU_64BIT
| typedef rt_uint64_t rt_ubase_t;
| #else
| typedef rt_uint32_t rt_ubase_t;
| #endif
This ensures correct width casting for both 32/64-bit architectures.
拉取/合并请求描述:(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