components: libc: fix reset static variable unsolved in dlmodule_load…#11247
components: libc: fix reset static variable unsolved in dlmodule_load…#11247KennethLiu61 wants to merge 1 commit intoRT-Thread:masterfrom
Conversation
…_shared_object [Problem Description] In the dlmodule_load_shared_object function, if a module loading fails once due to an unresolved symbol, all subsequent attempts to load any module will fail. The system becomes unable to load modules correctly until a reboot. [Problem Analysis] The root cause is that the variable unsolved is defined as static. Static variables retain their value between function calls. If a relocation error occurs, unsolved is set to RT_TRUE. However, when the function returns with an error, the value of unsolved is not reset. Consequently, on the next function call, unsolved remains RT_TRUE from the previous execution. This causes the check if (unsolved) to trigger immediately (or after the loop), forcing the function to return an error regardless of whether the current module is valid or not. [Solution] Reset the unsolved variable to RT_FALSE before returning the error code -RT_ERROR. This ensures the variable is in a clean state for the next function call, preventing state leakage between invocations. Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_libcReviewers: @GorrayLi @mysterywolf Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-03-10 17:16 CST)
📝 Review Instructions
|
…_shared_object
[Problem Description]
In the dlmodule_load_shared_object function,
if a module loading fails once due to an unresolved symbol, all subsequent attempts to load any module will fail. The system becomes unable to load modules correctly until a reboot.
[Problem Analysis]
The root cause is that the variable unsolved is defined as static. Static variables retain their value between function calls. If a relocation error occurs, unsolved is set to RT_TRUE. However, when the function returns with an error, the value of unsolved is not reset. Consequently, on the next function call, unsolved remains RT_TRUE from the previous execution. This causes the check if (unsolved) to trigger immediately (or after the loop), forcing the function to return an error regardless of whether the current module is valid or not.
[Solution]
Reset the unsolved variable to RT_FALSE before returning the error code -RT_ERROR. This ensures the variable is in a clean state for the next function call, preventing state leakage between invocations.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
在 dlmodule_load_shared_object 函数中,如果模块因为符号未解析导致加载失败一次,后续所有的模块加载尝试都会失败。系统在重启前无法再正常加载模块。原因是 unsolved 变量被定义为了 static 类型。
你的解决方案是什么 (what is your solution)
在返回 -RT_ERROR 之前,显式将 unsolved 变量重置为 RT_FALSE。这确保了变量在函数退出时处于初始状态,防止状态残留影响下一次调用。
请提供验证的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