[syslinux:elflink] module: Correct the size of the module symbol table

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Nov 27 12:30:04 PST 2012


Commit-ID:  b2eadc35e99caa2a6aba2fae99031c1073bc6cf5
Gitweb:     http://www.syslinux.org/commit/b2eadc35e99caa2a6aba2fae99031c1073bc6cf5
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Tue, 27 Nov 2012 11:58:58 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Tue, 27 Nov 2012 11:58:58 +0000

module: Correct the size of the module symbol table

We were incorrectly grovelling around in the GNU hash table for the
size of the symbol table. Instead we need to map the section headers
and search for the SHT_DYNSYM entry.

This bug caused hdt.c32 to refuse to load as some symbols were never
resolved because not all of the SHT_UNDEF symbols in hdt.c32 were
processed.

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

---
 com32/lib/sys/module/elf_module.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index b220e1a..c92fe26 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -51,7 +51,9 @@ static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 	int i;
 	int res = 0;
 	char *pht = NULL;
+	char *sht = NULL;
 	Elf32_Phdr *cr_pht;
+	Elf32_Shdr *cr_sht;
 
 	Elf32_Addr min_addr  = 0x00000000; // Min. ELF vaddr
 	Elf32_Addr max_addr  = 0x00000000; // Max. ELF vaddr
@@ -163,6 +165,25 @@ static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 		}
 	}
 
+	// Get to the SHT
+	image_seek(elf_hdr->e_shoff, module);
+
+	// Load the SHT
+	sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize);
+	image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module);
+
+	// Setup the symtable size
+	for (i = 0; i < elf_hdr->e_shnum; i++) {
+		cr_sht = (Elf32_Shdr*)(sht + i * elf_hdr->e_shentsize);
+
+		if (cr_sht->sh_type == SHT_DYNSYM) {
+			module->symtable_size = cr_sht->sh_size;
+			break;
+		}
+	}
+
+	free(sht);
+
 	// Setup dynamic segment location
 	module->dyn_table = module_get_absolute(dyn_addr, module);
 
@@ -229,13 +250,6 @@ static int prepare_dynlinking(struct elf_module *module) {
 		dyn_entry++;
 	}
 
-	// Now compute the number of symbols in the symbol table
-	if (module->ghash_table != NULL) {
-		module->symtable_size = module->ghash_table[1];
-	} else {
-		module->symtable_size = module->hash_table[1];
-	}
-
 	return 0;
 }
 


More information about the Syslinux-commits mailing list