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

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

commit ba1ae7947a69067e670ab6ffcf63bdbe39f78525
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 6 19:02:04 2026 +0200

    libs/libc/elf: Find the symbols of a stripped shared object.
    
    libelf_findsymtab() accepted only a SHT_SYMTAB section.  A shared object
    that strip has processed has no SHT_SYMTAB: only its SHT_DYNSYM remains.
    With CONFIG_DEBUG_SYMBOLS the application build strips each module in
    bin/, so every FDPIC module that it builds fails to load with "No symbols
    in ELF file".
    
    Use the dynamic symbol table of a shared object when it has no other
    symbol table.  It holds every symbol that the object imports or exports,
    which is what the loader looks up.  An object with SHT_SYMTAB still uses
    it.
    
    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 84143b68ba3..d5f537e3b0e 100644
--- a/libs/libc/elf/elf_symbols.c
+++ b/libs/libc/elf/elf_symbols.c
@@ -254,7 +254,10 @@ int libelf_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
 {
   int i;
 
-  /* Find the symbol table section header and its associated string table */
+  /* Find the symbol table section header and its associated string table.
+   * A stripped shared object keeps only its dynamic symbol table, which
+   * holds every symbol that it imports or exports.
+   */
 
   for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
     {
@@ -264,6 +267,13 @@ int libelf_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
           loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
           break;
         }
+
+      if (loadinfo->shdr[i].sh_type == SHT_DYNSYM &&
+          loadinfo->ehdr.e_type == ET_DYN)
+        {
+          loadinfo->symtabidx = i;
+          loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
+        }
     }
 
   /* Verify that there is a symbol and string table */

Reply via email to