casaroli commented on code in PR #20368:
URL: https://github.com/apache/nuttx/pull/20368#discussion_r4122167438


##########
libs/libc/elf/elf_bind.c:
##########
@@ -812,9 +853,68 @@ static int libelf_relocatedyn(FAR struct module_s *modp,
             loadinfo->gotbase);
     }
 
-  /* After the loop, because DT_PLTGOT is read there.  Both relocation
-   * tables are walked under this one arch_data, so the pool cursor
-   * survives from one to the next.
+  /* Open whatever the object names in DT_NEEDED.  dlopen() is the loader
+   * for a shared library, so hand the work to it.
+   */
+
+#ifdef CONFIG_LIBC_DLFCN
+
+  symhdr = &loadinfo->shdr[loadinfo->dsymtabidx];
+
+  for (i = 0; i < nlibs; i++)
+    {
+      Elf_Sym namesym;
+      FAR void *handle;
+
+      /* The name is a string table offset, which is what st_name is, so
+       * the existing reader can fetch it.
+       */
+
+      memset(&namesym, 0, sizeof(namesym));
+      namesym.st_name = libs[i];
+
+      ret = libelf_symname(loadinfo, &namesym,
+                           loadinfo->shdr[symhdr->sh_link].sh_offset);
+      if (ret < 0)
+        {
+          berr("ERROR: DT_NEEDED %d has no name\n", i);
+          lib_free(sym);
+          lib_free(rels);
+          lib_free(dyn);
+          return ret;
+        }
+
+      handle = dlopen((FAR const char *)loadinfo->iobuffer, RTLD_NOW);
+      if (handle == NULL)
+        {
+          berr("ERROR: Cannot open needed library %s\n",
+               (FAR char *)loadinfo->iobuffer);
+          lib_free(sym);
+          lib_free(rels);
+          lib_free(dyn);
+          return -ELIBACC;
+        }
+
+      binfo("Opened needed library %s\n", (FAR char *)loadinfo->iobuffer);
+
+      modp->libs[modp->nlibs++] = handle;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to