[PATCH v2 3/8] module: Fix adding module to list after layout

David Dgien dgienda125 at gmail.com
Mon Jun 29 20:38:33 EDT 2020


During load_module(), the 'this_module' section is relocated, but the
pointer to the module struct isn't updated to account account for the
move. Do so before adding the module to the module_list.

As a side effect of properly pointing to the relocated module struct, we
no longer need to manually search for and fixup the init_module symbol,
so remove that code.

Signed-off-by: David Dgien <dgienda125 at gmail.com>
---
 common/module.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/common/module.c b/common/module.c
index 829c12000..5ace544e0 100644
--- a/common/module.c
+++ b/common/module.c
@@ -297,13 +297,8 @@ struct module * load_module(void *mod_image, unsigned long len)
 		}
 	}
 
-	for (i = 0; i < numsyms; i++) {
-		if (!strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "init_module")) {
-			printf("found init_module() at 0x%08x\n", sym[i].st_value);
-			module->init = (void *)sym[i].st_value;
-		}
-	}
-
+	/* Module has been moved */
+	module = (void *)sechdrs[modindex].sh_addr;
 	list_add_tail(&module->list, &module_list);
 
 	return module;
@@ -311,8 +306,6 @@ struct module * load_module(void *mod_image, unsigned long len)
 cleanup:
 	if (ptr)
 		free(ptr);
-	if (module)
-		free(module);
 
 	return NULL;
 }
-- 
2.27.0




More information about the barebox mailing list