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


##########
sched/module/mod_insmod.c:
##########
@@ -237,11 +239,37 @@ FAR void *insmod(FAR const char *filename, FAR const char 
*modname)
 
   /* Call the module initializer */
 
-  ret = initializer(&modp->modinfo);
-  if (ret < 0)
+  switch (loadinfo.ehdr.e_type)
     {
-      binfo("Failed to initialize the module: %d\n", ret);
-      goto errout_with_load;
+      case ET_REL :
+          ret = initializer(&modp->modinfo);
+          if (ret < 0)
+            {
+              binfo("Failed to initialize the module: %d\n", ret);
+              goto errout_with_load;
+            }
+          break;
+      case ET_DYN :
+
+          /* Process any preinit_array entries */
+
+          array = (void (**)(void)) loadinfo.preiarr;

Review Comment:
   add FAR for ALL pointers and remove the space after ALL cast.



##########
tools/build-globals.sh:
##########
@@ -1,65 +1,28 @@
-#!/bin/bash
+#!/usr/bin/env bash
+############################################################################
+# tools/copydir.sh

Review Comment:
   tools/build-globals.sh



##########
sched/module/mod_insmod.c:
##########
@@ -155,7 +155,9 @@ FAR void *insmod(FAR const char *filename, FAR const char 
*modname)
   struct mod_loadinfo_s loadinfo;
   FAR struct module_s *modp;
   mod_initializer_t initializer;
+  void (**array)(void);

Review Comment:
   ditto



##########
libs/libc/modlib/modlib_bind.c:
##########
@@ -726,12 +765,15 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
 
               addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart;
 
-              if ((*(FAR uint32_t *)addr) < loadinfo->datasec)
-                  dynsym.st_value = *(FAR uint32_t *)addr +
-                                    loadinfo->textalloc;
+              if (reldata.relrela[idx_rel] == 1)
+                  addr += rela->r_addend;

Review Comment:
   add {}



##########
libs/libc/modlib/modlib_bind.c:
##########
@@ -717,7 +752,11 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
                       }
 
                     addr = rel->r_offset + loadinfo->textalloc;
-                    *(FAR uintptr_t *)addr = (uintptr_t)ep;
+
+                    if (reldata.relrela[idx_rel] == 1)
+                        addr += rela->r_addend;
+
+                    *(uintptr_t *)addr = (uintptr_t)ep;

Review Comment:
   add FAR and space



##########
sched/module/mod_insmod.c:
##########
@@ -237,11 +239,37 @@ FAR void *insmod(FAR const char *filename, FAR const char 
*modname)
 
   /* Call the module initializer */
 
-  ret = initializer(&modp->modinfo);
-  if (ret < 0)
+  switch (loadinfo.ehdr.e_type)
     {
-      binfo("Failed to initialize the module: %d\n", ret);
-      goto errout_with_load;
+      case ET_REL :
+          ret = initializer(&modp->modinfo);
+          if (ret < 0)
+            {
+              binfo("Failed to initialize the module: %d\n", ret);
+              goto errout_with_load;
+            }
+          break;
+      case ET_DYN :
+
+          /* Process any preinit_array entries */
+
+          array = (void (**)(void)) loadinfo.preiarr;
+          for (i = 0; i < loadinfo.nprei; i++)
+            {
+              array[i]();
+            }
+
+          /* Process any init_array entries */
+
+          array = (void (**)(void)) loadinfo.initarr;

Review Comment:
   ditto



##########
libs/libc/modlib/modlib_bind.c:
##########
@@ -717,7 +752,11 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
                       }
 
                     addr = rel->r_offset + loadinfo->textalloc;
-                    *(FAR uintptr_t *)addr = (uintptr_t)ep;
+
+                    if (reldata.relrela[idx_rel] == 1)
+                        addr += rela->r_addend;

Review Comment:
   {}



##########
libs/libc/modlib/modlib_bind.c:
##########
@@ -726,12 +765,15 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
 
               addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart;
 
-              if ((*(FAR uint32_t *)addr) < loadinfo->datasec)
-                  dynsym.st_value = *(FAR uint32_t *)addr +
-                                    loadinfo->textalloc;
+              if (reldata.relrela[idx_rel] == 1)
+                  addr += rela->r_addend;
+
+              if ((*(uint32_t *) addr) < loadinfo->datasec)
+                  dynsym.st_value = *(uint32_t *) addr + loadinfo->textalloc;

Review Comment:
   add FAR and space



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