aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-04-02 11:07:56 +0100
committerMatt Fleming <matt.fleming@intel.com>2012-04-17 10:58:33 +0100
commitfdb708671b70182c597bed2fb0ed8d404e9f9b37 (patch)
treea6230c71fc65a5adc299e7f51364acb8a1390ff2
parentb5529aac6a38f15084f7710018fd24921cb6be54 (diff)
downloadsyslinux-fdb708671b70182c597bed2fb0ed8d404e9f9b37.tar.gz
syslinux-fdb708671b70182c597bed2fb0ed8d404e9f9b37.tar.xz
syslinux-fdb708671b70182c597bed2fb0ed8d404e9f9b37.zip
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@intel.com>
-rw-r--r--com32/lib/sys/module/common.c9
-rw-r--r--com32/lib/sys/module/common.h8
-rw-r--r--com32/lib/sys/module/elf_module.c13
-rw-r--r--com32/lib/sys/module/elfutils.c4
-rw-r--r--com32/lib/sys/module/elfutils.h2
-rw-r--r--com32/lib/sys/module/shallow_module.c8
6 files changed, 25 insertions, 19 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index e26163f1..eeb26075 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 6259df51..54f0ec4b 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 b2ebbde8..581529be 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 64be0770..b7d760b4 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 b18968f3..a901ff48 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 fbcf781b..8a88e403 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