[syslinux:elflink] elflink: Fix build warnings

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Apr 17 11:24:11 PDT 2012


Commit-ID:  fdb708671b70182c597bed2fb0ed8d404e9f9b37
Gitweb:     http://www.syslinux.org/commit/fdb708671b70182c597bed2fb0ed8d404e9f9b37
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Mon, 2 Apr 2012 11:07:56 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Tue, 17 Apr 2012 10:58:33 +0100

elflink: Fix build warnings

There's a lot of void * arithmetic going on in the ELF code that the
compiler warns about, i.e.

sys/module/common.c: In function ‘check_symbols’:
sys/module/common.c:325:44: warning: pointer of type ‘void *’ used in arithmetic

Cast the void * pointers to char * so that we can do byte arithmetic
on them.

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

---
 com32/lib/sys/module/common.c         |    9 ++++-----
 com32/lib/sys/module/common.h         |    8 ++++++++
 com32/lib/sys/module/elf_module.c     |   13 ++++++-------
 com32/lib/sys/module/elfutils.c       |    4 ++--
 com32/lib/sys/module/elfutils.h       |    2 +-
 com32/lib/sys/module/shallow_module.c |    8 ++++----
 6 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index e26163f..eeb2607 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -322,7 +322,7 @@ int check_symbols(struct elf_module *module)
 
 	for(i = 1; i < module->symtable_size; i++)
 	{
-		crt_sym = (Elf32_Sym*)(module->sym_table + i * module->syment_size);
+		crt_sym = symbol_get_entry(module, i);
 		crt_name = module->str_table + crt_sym->st_name;
 
 		strong_count = 0;
@@ -434,7 +434,7 @@ static Elf32_Sym *module_find_symbol_sysv(const char *name, struct elf_module *m
 
 
 	while (crt_index != STN_UNDEF) {
-		crt_sym = (Elf32_Sym*)(module->sym_table + crt_index*module->syment_size);
+		crt_sym = symbol_get_entry(module, crt_index);
 
 		if (strcmp(name, module->str_table + crt_sym->st_name) == 0)
 			return crt_sym;
@@ -489,8 +489,7 @@ static Elf32_Sym *module_find_symbol_gnu(const char *name, struct elf_module *mo
 
 			do {
 				if (((*hasharr ^ h ) >> 1) == 0) {
-					Elf32_Sym *crt_sym = (Elf32_Sym*)(module->sym_table +
-							(hasharr - gnu_chain_zero) * module->syment_size);
+					Elf32_Sym *crt_sym = symbol_get_entry(module, (hasharr - gnu_chain_zero));
 
 					if (strcmp(name, module->str_table + crt_sym->st_name) == 0) {
 						return crt_sym;
@@ -511,7 +510,7 @@ static Elf32_Sym *module_find_symbol_iterate(const char *name,struct elf_module
 
 	for (i=1; i < module->symtable_size; i++)
 	{
-		crt_sym = (Elf32_Sym*)(module->sym_table + i*module->syment_size);
+		crt_sym = symbol_get_entry(module, i);
 		if (strcmp(name, module->str_table + crt_sym->st_name) == 0)
 		{
 			return crt_sym;
diff --git a/com32/lib/sys/module/common.h b/com32/lib/sys/module/common.h
index 6259df5..54f0ec4 100644
--- a/com32/lib/sys/module/common.h
+++ b/com32/lib/sys/module/common.h
@@ -27,6 +27,14 @@
 #define MIN(x,y)	(((x) < (y)) ? (x) : (y))
 #define MAX(x,y)	(((x) > (y)) ? (x) : (y))
 
+static inline Elf32_Sym *symbol_get_entry(struct elf_module *module, int entry)
+{
+	char *sym_table = (char *)module->sym_table;
+	int index = entry * module->syment_size;
+
+	return (Elf32_Sym *)(sym_table + index);
+}
+
 //#define ELF_DEBUG
 
 #ifdef ELF_DEBUG
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index b2ebbde..581529b 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -50,7 +50,7 @@ static int check_header(Elf32_Ehdr *elf_hdr) {
 static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 	int i;
 	int res = 0;
-	void *pht = NULL;
+	char *pht = NULL;
 	Elf32_Phdr *cr_pht;
 
 	Elf32_Addr min_addr  = 0x00000000; // Min. ELF vaddr
@@ -136,8 +136,8 @@ static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 				// headers
 				Elf32_Off aux_off = module->u.l._cr_offset - cr_pht->p_offset;
 
-				if (image_read(module_get_absolute(cr_pht->p_vaddr, module) + aux_off,
-						cr_pht->p_filesz - aux_off, module) < 0) {
+				if (image_read((char *)module_get_absolute(cr_pht->p_vaddr, module) + aux_off,
+					       cr_pht->p_filesz - aux_off, module) < 0) {
 					res = -1;
 					goto out;
 				}
@@ -259,8 +259,7 @@ static int perform_relocation(struct elf_module *module, Elf32_Rel *rel) {
 		// Find out details about the symbol
 
 		// The symbol reference
-		Elf32_Sym *sym_ref =
-			(Elf32_Sym*)(module->sym_table + sym * module->syment_size);
+		Elf32_Sym *sym_ref = symbol_get_entry(module, sym);
 
 		// The symbol definition
 		sym_def =
@@ -321,9 +320,9 @@ static int resolve_symbols(struct elf_module *module) {
 	int res;
 
 	Elf32_Word plt_rel_size = 0;
-	void *plt_rel = NULL;
+	char *plt_rel = NULL;
 
-	void *rel = NULL;
+	char *rel = NULL;
 	Elf32_Word rel_size = 0;
 	Elf32_Word rel_entry = 0;
 
diff --git a/com32/lib/sys/module/elfutils.c b/com32/lib/sys/module/elfutils.c
index 64be077..b7d760b 100644
--- a/com32/lib/sys/module/elfutils.c
+++ b/com32/lib/sys/module/elfutils.c
@@ -37,7 +37,7 @@ struct memalign_info {
 };
 
 int elf_malloc(void **memptr, size_t alignment, size_t size) {
-	void *start_addr = NULL;
+	char *start_addr = NULL;
 	struct memalign_info *info;
 
 	if ((alignment & (alignment - 1)) != 0)
@@ -63,7 +63,7 @@ int elf_malloc(void **memptr, size_t alignment, size_t size) {
 	return 0;
 }
 
-void elf_free(void *memptr) {
+void elf_free(char *memptr) {
 	struct memalign_info *info = (struct memalign_info*)(memptr -
 			sizeof(struct memalign_info));
 
diff --git a/com32/lib/sys/module/elfutils.h b/com32/lib/sys/module/elfutils.h
index b18968f..a901ff4 100644
--- a/com32/lib/sys/module/elfutils.h
+++ b/com32/lib/sys/module/elfutils.h
@@ -59,6 +59,6 @@ extern int elf_malloc(void **memptr, size_t alignment, size_t size);
  * elf_free - Releases memory previously allocated by elf_malloc.
  * @memptr: the address of the allocated block
  */
-extern void elf_free(void *memptr);
+extern void elf_free(char *memptr);
 
 #endif /*ELF_UTILS_H_*/
diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c
index fbcf781..8a88e40 100644
--- a/com32/lib/sys/module/shallow_module.c
+++ b/com32/lib/sys/module/shallow_module.c
@@ -32,8 +32,8 @@ static int check_header_shallow(Elf32_Ehdr *elf_hdr) {
 static int load_shallow_sections(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 	int i;
 	int res = 0;
-	void *sht = NULL;
-	void *buffer = NULL;
+	char *sht = NULL;
+	char *buffer = NULL;
 	Elf32_Shdr *crt_sht;
 	Elf32_Off buff_offset;
 
@@ -100,8 +100,8 @@ static int load_shallow_sections(struct elf_module *module, Elf32_Ehdr *elf_hdr)
 
 	// Setup module information
 	module->module_size = max_offset - min_offset;
-	module->str_table = (char*)(module->module_addr + (str_offset - min_offset));
-	module->sym_table = module->module_addr + (sym_offset - min_offset);
+	module->str_table = (char *)module->module_addr + (str_offset - min_offset);
+	module->sym_table = (char *)module->module_addr + (sym_offset - min_offset);
 
 out:
 	// Release the SHT


More information about the Syslinux-commits mailing list