xiaoxiang781216 commented on code in PR #20131:
URL: https://github.com/apache/nuttx/pull/20131#discussion_r4107770087


##########
libs/libc/elf/elf_remove.c:
##########
@@ -150,6 +167,24 @@ int libelf_uninit(FAR struct module_s *modp)
 #  endif
 #endif
         }
+      else if (modp->fdpic)
+        {
+          /* An FDPIC object placed its two segments separately.  Free each
+           * one.  If the text stayed on the media, it was never allocated,
+           * thus leave it.
+           */
+
+          if (modp->xipbase == 0)
+            {
+#if defined(CONFIG_ARCH_USE_TEXT_HEAP)

Review Comment:
   `#ifdef CONFIG_ARCH_USE_TEXT_HEAP`



##########
libs/libc/elf/elf_remove.c:
##########
@@ -59,12 +63,17 @@ int libelf_uninit(FAR struct module_s *modp)
     }
 #endif
 
-  /* Is there an uninitializer? */
+  /* Is there an uninitializer?  Like the constructors, an FDPIC object's
+   * destructors reach its globals through its own data base, which the
+   * unloading thread does not carry.
+   */
+
+  gotbase = modp->fdpic ? modp->gotbase : 0;
 
   array = (FAR void (**)(void))modp->finiarr;
   for (i = 0; i < modp->nfini; i++)
     {
-      array[i]();
+      fdpic_call(array[i], gotbase);

Review Comment:
   gotbase->modp->gotbase



##########
include/nuttx/fdpic.h:
##########
@@ -159,6 +159,34 @@ static inline void fdpic_invoke(uintptr_t arg,
     }
 }
 
+/****************************************************************************
+ * Name: fdpic_call
+ *
+ * Description:
+ *   Call a function of a module the caller is not running in, such as a
+ *   constructor of a module being loaded or a destructor of one being
+ *   unloaded, with the data base that function needs.
+ *
+ *   A zero base means the function is not a module's, or the caller already
+ *   carries the right one, and it is called directly.  A non-FDPIC object
+ *   has a GOT too, so the caller decides which base to pass, not this.
+ *
+ * Input Parameters:
+ *   fn  - The function to call.
+ *   got - The data base to enter it with, or zero.
+ *
+ ****************************************************************************/
+
+static inline void fdpic_call(CODE void (*fn)(void), uintptr_t got)

Review Comment:
   should we pass arg like fdpic_invoke



##########
libs/libc/elf/elf_insert.c:
##########
@@ -414,7 +422,13 @@ FAR void *libelf_insert(FAR const char *filename, FAR 
const char *modname)
   modp->datasize  = loadinfo.datasize;
 #endif
 
-  /* Call the module initializer */
+  /* Call the module initializer.  An FDPIC object's constructors reach its
+   * globals through its own data base, which the loading thread does not
+   * carry; a non-FDPIC one runs on the base it is entered with, so it gets
+   * none of its own.
+   */
+
+  gotbase = loadinfo.fdpic ? loadinfo.gotbase : 0;

Review Comment:
   ditto



##########
libs/libc/elf/elf_bind.c:
##########
@@ -733,6 +733,24 @@ static int libelf_relocatedyn(FAR struct module_s *modp,
           case DT_PLTRELSZ:
             reldata.relsz[I_PLT] = dyn[i].d_un.d_val;
             break;
+          case DT_NEEDED:

Review Comment:
   let's move to DT_NEEDED patch



##########
include/nuttx/lib/elf.h:
##########
@@ -190,6 +190,18 @@ struct module_s
   uint16_t nsect;                      /* Number of entries in sectalloc array 
*/
 #endif
   int dynamic;                         /* Module is a dynamic shared object */
+  bool fdpic;                          /* Module is an FDPIC object: its two

Review Comment:
   remove?



##########
libs/libc/elf/elf_remove.c:
##########
@@ -59,12 +63,17 @@ int libelf_uninit(FAR struct module_s *modp)
     }
 #endif
 
-  /* Is there an uninitializer? */
+  /* Is there an uninitializer?  Like the constructors, an FDPIC object's
+   * destructors reach its globals through its own data base, which the
+   * unloading thread does not carry.
+   */
+
+  gotbase = modp->fdpic ? modp->gotbase : 0;

Review Comment:
   why need? gotbase should be zero if fdpic equals false.



-- 
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