aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-06-20 16:17:23 +0100
committerMatt Fleming <matt.fleming@intel.com>2012-06-20 16:35:41 +0100
commitdffee2c45ad45957f791c89e9197e115f9449b40 (patch)
tree5db15b94b2298f5dc248f4e7becfa3911895f9de
parent7fa16f395ab5605c7e3ba414f6ab844095aec5b4 (diff)
downloadsyslinux-dffee2c45ad45957f791c89e9197e115f9449b40.tar.gz
syslinux-dffee2c45ad45957f791c89e9197e115f9449b40.tar.xz
syslinux-dffee2c45ad45957f791c89e9197e115f9449b40.zip
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@intel.com>
-rw-r--r--com32/include/sys/module.h5
-rw-r--r--com32/lib/sys/module/elf_module.c20
2 files changed, 10 insertions, 15 deletions
diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index fb6a1eb3..eabc9e0f 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 7d892aa9..d8009aac 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);