From 740472e0793ffb6071c78d8e4f7a37e6bf32e82a Mon Sep 17 00:00:00 2001 From: "kenneth.liu" Date: Tue, 10 Mar 2026 17:02:54 +0800 Subject: [PATCH] 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 --- components/libc/posix/libdl/dlelf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/libc/posix/libdl/dlelf.c b/components/libc/posix/libdl/dlelf.c index 24d82d73b4a..6490b326339 100644 --- a/components/libc/posix/libdl/dlelf.c +++ b/components/libc/posix/libdl/dlelf.c @@ -205,7 +205,10 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt } if (unsolved) + { + unsolved = RT_FALSE; return -RT_ERROR; + } } /* construct module symbol table */