This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 67e61b81207 libs/libc/elf: Let a weak undefined symbol stay undefined.
67e61b81207 is described below

commit 67e61b81207f95edd5b17c41141951881d4f6b77
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Oct 9 01:14:59 2026 +0200

    libs/libc/elf: Let a weak undefined symbol stay undefined.
    
    When libelf_symvalue() could not resolve an undefined symbol it failed
    the load with ENOENT, also for a weak reference.  A static link gives an
    unresolved weak symbol the value 0, and code tests it for that, so a
    module that only refers weakly to a symbol (for example the
    __cxa_pure_virtual of a C++ program) could not be loaded.
    
    Give an unresolved weak symbol the value 0, as the dynamic relocation
    path in elf_bind.c already does.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 libs/libc/elf/elf_symbols.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libs/libc/elf/elf_symbols.c b/libs/libc/elf/elf_symbols.c
index d5f537e3b0e..43c74c3a6bf 100644
--- a/libs/libc/elf/elf_symbols.c
+++ b/libs/libc/elf/elf_symbols.c
@@ -428,10 +428,20 @@ int libelf_symvalue(FAR struct module_s *modp,
                                          nexports);
             }
 
-          /* Was the symbol found from any exporter? */
+          /* Was the symbol found from any exporter?  A weak reference may
+           * stay undefined; its value is then 0, as in a static link.
+           */
 
           if (symbol == NULL)
             {
+              if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
+                {
+                  binfo("SHN_UNDEF: weak \"%s\" stays 0\n",
+                        loadinfo->iobuffer);
+                  sym->st_value = 0;
+                  break;
+                }
+
               berr("ERROR: SHN_UNDEF: Exported symbol \"%s\" not found\n",
                    loadinfo->iobuffer);
               return -ENOENT;

Reply via email to