Ver Fonte

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>
kenneth.liu há 1 semana atrás
pai
commit
cffaa514e2
1 ficheiros alterados com 3 adições e 0 exclusões
  1. 3 0
      components/libc/posix/libdl/dlelf.c

+ 3 - 0
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 */