Skip to content

Commit cffaa51

Browse files
KennethLiu61Rbb666
authored andcommitted
components: libc: fix reset static variable unsolved in dlmodule_load_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>
1 parent ec2182e commit cffaa51

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

components/libc/posix/libdl/dlelf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
205205
}
206206

207207
if (unsolved)
208+
{
209+
unsolved = RT_FALSE;
208210
return -RT_ERROR;
211+
}
209212
}
210213

211214
/* construct module symbol table */

0 commit comments

Comments
 (0)