[syslinux:elflink] module: Make list of DT_NEEDED entries per-module

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Jun 26 09:54:09 PDT 2012


Commit-ID:  dffee2c45ad45957f791c89e9197e115f9449b40
Gitweb:     http://www.syslinux.org/commit/dffee2c45ad45957f791c89e9197e115f9449b40
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Wed, 20 Jun 2012 16:17:23 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 20 Jun 2012 16:35:41 +0100

module: Make list of DT_NEEDED entries per-module

We can't store the DT_NEEDED entries in the bss because 'needed[]'
will be overwritten with recursive calls to module_load(). Make the
list part of struct elf_module instead.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/include/sys/module.h        |    5 +++++
 com32/lib/sys/module/elf_module.c |   20 +++++---------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index fb6a1eb..eabc9e0 100644
--- a/com32/include/sys/module.h
+++ b/com32/include/sys/module.h
@@ -27,6 +27,8 @@
 #define EXEC_MODULE			0		
 #define LIB_MODULE			1
 
+#define MAX_NR_DEPS			64
+
 /*
  * Initialization and finalization function signatures
  */
@@ -118,6 +120,9 @@ struct elf_module {
 		} x;
 	} u;
 
+	// ELF DT_NEEDED entries for this module
+	int				nr_needed;
+	Elf32_Word			needed[MAX_NR_DEPS];
 };
 
 /**
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 7d892aa..d8009aa 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -19,8 +19,6 @@
 #include "elfutils.h"
 #include "common.h"
 
-#define MAX_NR_DEPS	64
-
 static int check_header(Elf32_Ehdr *elf_hdr) {
 	int res;
 
@@ -181,9 +179,6 @@ out:
 	return res;
 }
 
-static int nr_needed;
-static Elf32_Word needed[MAX_NR_DEPS];;
-
 static int prepare_dynlinking(struct elf_module *module) {
 	Elf32_Dyn  *dyn_entry = module->dyn_table;
 
@@ -196,8 +191,8 @@ static int prepare_dynlinking(struct elf_module *module) {
 			 * are then inform the user that we ran out of
 			 * space.
 			 */
-			if (nr_needed < MAX_NR_DEPS)
-				needed[nr_needed++] = dyn_entry->d_un.d_ptr;
+			if (module->nr_needed < MAX_NR_DEPS)
+				module->needed[module->nr_needed++] = dyn_entry->d_un.d_ptr;
 			else {
 				printf("Too many dependencies!\n");
 				return -1;
@@ -502,28 +497,23 @@ int module_load(struct elf_module *module) {
 	CHECKED(res, load_segments(module, &elf_hdr), error);
 	//printf("bleah... 3\n");
 	// Obtain dynamic linking information
-	nr_needed = 0;
 	CHECKED(res, prepare_dynlinking(module), error);
 	//printf("check... 4\n");
 
 	/* Find modules we need to load as dependencies */
 	if (module->str_table) {
-		int i, n;
+		int i;
 
 		/*
-		 * nr_needed can be modified by recursive calls to
-		 * module_load() so keep a local copy on the stack.
-		 *
 		 * Note that we have to load the dependencies in
 		 * reverse order.
 		 */
-		n = nr_needed - 1;
-		for (i = n; i >= 0; i--) {
+		for (i = module->nr_needed - 1; i >= 0; i--) {
 			size_t len, j;
 			char *dep, *p;
 			char *argv[2] = { NULL, NULL };
 
-			dep = module->str_table + needed[i];
+			dep = module->str_table + module->needed[i];
 
 			/* strip everything but the last component */
 			j = len = strlen(dep);


More information about the Syslinux-commits mailing list