aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Bucur <stefanb@zytor.com>2008-06-10 23:19:39 +0300
committerStefan Bucur <stefan@stefan-ubumac.(none)>2009-03-15 10:02:13 +0200
commitff98982feb408765bf644df3bb848ef0cacc63d2 (patch)
tree79a1928d674b8a58814f4f8e5471eab5b9fc56bd
parentd804c15789ed7cb2a01e675511499d99cf2f7dd9 (diff)
downloadsyslinux-elf-ff98982feb408765bf644df3bb848ef0cacc63d2.tar.gz
syslinux-elf-ff98982feb408765bf644df3bb848ef0cacc63d2.tar.xz
syslinux-elf-ff98982feb408765bf644df3bb848ef0cacc63d2.zip
The dynamic link entries are read from the ELF object.
-rw-r--r--elf/elf_module.c83
1 files changed, 82 insertions, 1 deletions
diff --git a/elf/elf_module.c b/elf/elf_module.c
index c89972e6..037b585e 100644
--- a/elf/elf_module.c
+++ b/elf/elf_module.c
@@ -274,6 +274,84 @@ static int load_segments(struct elf_module *module) {
return 0;
}
+
+static int resolve_symbols(struct elf_module *module) {
+ int i;
+ Elf32_Ehdr *elf_hdr = elf_get_header(module->file_image);
+ Elf32_Phdr *dyn_ph; // The program header for the dynamic section
+
+ Elf32_Dyn *dyn_entry; // The table of dynamic linking information
+
+ for (i=0; i < elf_hdr->e_phnum; i++) {
+ dyn_ph = elf_get_ph(module->file_image, i);
+
+ if (dyn_ph->p_type == PT_DYNAMIC)
+ break;
+ else
+ dyn_ph = NULL;
+ }
+
+ if (dyn_ph == NULL) {
+ fprintf(stderr, "Dynamic relocation information not found\n");
+ return -1;
+ }
+
+ dyn_entry = (Elf32_Dyn*)(module->file_image + dyn_ph->p_offset);
+
+
+ while (dyn_entry->d_tag != DT_NULL) {
+ switch (dyn_entry->d_tag) {
+ case DT_NEEDED:
+ // TODO: Manage dependencies here
+ break;
+ case DT_PLTRELSZ:
+
+ case DT_PLTGOT:
+
+ case DT_HASH:
+ case DT_GNU_HASH: // TODO: Add support for this one, too (50% faster)
+
+ case DT_STRTAB:
+
+ case DT_SYMTAB:
+
+ case DT_RELA:
+
+ case DT_RELASZ:
+
+ case DT_RELAENT:
+
+ case DT_STRSZ:
+
+ case DT_SYMENT:
+
+ case DT_INIT:
+
+ case DT_FINI:
+
+ case DT_REL:
+
+ case DT_RELSZ:
+
+ case DT_RELENT:
+
+ case DT_PLTREL:
+
+ case DT_JMPREL:
+ printf("Recognized DYN tag: %d\n", dyn_entry->d_tag);
+ break;
+ default:
+ printf("Custom DYN tag: 0x%08x\n", dyn_entry->d_tag);
+ break;
+ }
+
+ dyn_entry++;
+ }
+
+
+ return 0;
+}
+
// Loads the module into the system
int module_load(struct elf_module *module) {
int res;
@@ -301,9 +379,12 @@ int module_load(struct elf_module *module) {
CHECKED(res, load_segments(module), error);
- // The file image is no longer neededchar
+ CHECKED(res, resolve_symbols(module), error);
+
+ // The file image is no longer needed
CHECKED(res, unload_image(module), error);
+
return 0;
error: