summaryrefslogtreecommitdiff
path: root/components/libc/posix/libdl/dlmodule.h
diff options
context:
space:
mode:
authorkenneth.liu <[email protected]>2025-02-22 13:20:11 +0800
committerMeco Man <[email protected]>2025-02-22 14:16:00 -0500
commit4940bb10515316791f1940a59bfeaeebee35ec87 (patch)
tree2c72739252ce97892007d59f01d0efb731d52839 /components/libc/posix/libdl/dlmodule.h
parentaa3328f35db993d6ed3984503c155c694433d0a1 (diff)
components: libc: fix pointer-to-integer cast warnings and address truncation
[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 <[email protected]>
Diffstat (limited to 'components/libc/posix/libdl/dlmodule.h')
-rw-r--r--components/libc/posix/libdl/dlmodule.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/components/libc/posix/libdl/dlmodule.h b/components/libc/posix/libdl/dlmodule.h
index 62a0cdd5d3..75ca325800 100644
--- a/components/libc/posix/libdl/dlmodule.h
+++ b/components/libc/posix/libdl/dlmodule.h
@@ -82,6 +82,6 @@ void dlmodule_exit(int ret_code);
struct rt_dlmodule *dlmodule_find(const char *name);
-rt_uint32_t dlmodule_symbol_find(const char *sym_str);
+rt_ubase_t dlmodule_symbol_find(const char *sym_str);
#endif