casaroli commented on code in PR #20368:
URL: https://github.com/apache/nuttx/pull/20368#discussion_r4130351541
##########
libs/libc/elf/elf_bind.c:
##########
@@ -812,9 +917,91 @@ 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.
+ /* Load whatever the object names in DT_NEEDED. This is what dlopen()
+ * does, through the same libelf_insert(), but the loader is also the
+ * kernel's module loader, which has no dlfcn.
+ */
+
+#ifdef LIBELF_NEEDED
+
+ 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 = libelf_insertneeded((FAR const char *)loadinfo->iobuffer);
+ 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);
+
+ /* The dependency holds the library from now on, in place of the
+ * reference libelf_insert() took, so libelf_undepend() lets it go.
+ */
+
+ libelf_registry_lock();
+ ret = libelf_depend(modp, handle);
+ if (ret >= 0)
+ {
+ ((FAR struct module_s *)handle)->nopen--;
+ }
+
+ libelf_registry_unlock();
+
+ if (ret < 0)
+ {
+ berr("ERROR: Cannot depend on %s: %d\n",
+ (FAR char *)loadinfo->iobuffer, ret);
+ libelf_remove(handle);
+ lib_free(sym);
+ lib_free(rels);
+ lib_free(dyn);
+ return ret;
+ }
+ }
+
+#else
+ if (nlibs > 0)
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]