# HG changeset patch
# User Clint Smullen <[EMAIL PROTECTED]>
# Date 1224015149 14400
# Node ID 4226afe7b6f6dddd11e60c7156abf5c00f0f8f53
# Parent  733318abb7b1a4995cad43f94b5b0f7c7f547189
[mq]: libelf_typing

diff --git a/ext/libelf/SConscript b/ext/libelf/SConscript
--- a/ext/libelf/SConscript
+++ b/ext/libelf/SConscript
@@ -88,8 +88,6 @@
 ElfFile('libelf_msize.c')
 
 m4env = env.Copy()
-del m4env['CCFLAGS']
-del m4env['CPPPATH']
 
 # If we have gm4 use it
 if m4env.Detect('gm4'):
diff --git a/ext/libelf/_libelf.h b/ext/libelf/_libelf.h
--- a/ext/libelf/_libelf.h
+++ b/ext/libelf/_libelf.h
@@ -83,7 +83,7 @@
         unsigned int   e_flags;        /* ELF_F_*, LIBELF_F_* flags */
         Elf_Kind       e_kind;         /* ELF_K_* */
         Elf            *e_parent;      /* non-NULL for archive members */
-        char           *e_rawfile;     /* uninterpreted bytes */
+        unsigned char *e_rawfile;      /* uninterpreted bytes */
         size_t         e_rawsize;      /* size of uninterpreted bytes */
         unsigned int   e_version;      /* file version */
 
@@ -91,9 +91,9 @@
                 struct {               /* ar(1) archives */
                         off_t  e_next; /* set by elf_rand()/elf_next() */
                         int    e_nchildren;
-                        char   *e_rawstrtab;   /* file name strings */
+                        unsigned char  *e_rawstrtab;   /* file name strings */
                         size_t e_rawstrtabsz;
-                        char   *e_rawsymtab;   /* symbol table */
+                        unsigned char  *e_rawsymtab;   /* symbol table */
                         size_t e_rawsymtabsz;
                         Elf_Arsym *e_symtab;
                         size_t e_symtabsz;
@@ -154,6 +154,7 @@
                 (DST)->NAME = (SRC)->NAME;             \
         } while (0)
 
+typedef void (*Elf_Translator)(unsigned char *_dst, unsigned char *_src, 
size_t _cnt, int _byteswap);
 
 /*
  * Prototypes
@@ -171,8 +172,7 @@
 int    _libelf_falign(Elf_Type _t, int _elfclass);
 size_t _libelf_fsize(Elf_Type _t, int _elfclass, unsigned int _version,
     size_t count);
-void   (*_libelf_get_translator(Elf_Type _t, int _direction, int _elfclass))
-            (char *_dst, char *_src, size_t _cnt, int _byteswap);
+Elf_Translator _libelf_get_translator(Elf_Type _t, int _direction, int 
_elfclass);
 void   *_libelf_getphdr(Elf *_e, int _elfclass);
 void   *_libelf_getshdr(Elf_Scn *_scn, int _elfclass);
 void   _libelf_init_elf(Elf *_e, Elf_Kind _kind);
diff --git a/ext/libelf/elf_begin.c b/ext/libelf/elf_begin.c
--- a/ext/libelf/elf_begin.c
+++ b/ext/libelf/elf_begin.c
@@ -33,6 +33,7 @@
 #include <ar.h>
 #include <ctype.h>
 #include "libelf.h"
+#include <unistd.h>
 
 #include "_libelf.h"
 
diff --git a/ext/libelf/elf_data.c b/ext/libelf/elf_data.c
--- a/ext/libelf/elf_data.c
+++ b/ext/libelf/elf_data.c
@@ -42,7 +42,7 @@
         int elfclass, elftype;
         unsigned int sh_type;
         uint64_t sh_align, sh_offset, sh_size;
-        void (*xlate)(char *_d, char *_s, size_t _c, int _swap);
+                 Elf_Translator xlate;
 
         if (s == NULL || (e = s->s_elf) == NULL || e->e_kind != ELF_K_ELF ||
             (d != NULL && s != d->d_scn)) {
diff --git a/ext/libelf/elf_getident.c b/ext/libelf/elf_getident.c
--- a/ext/libelf/elf_getident.c
+++ b/ext/libelf/elf_getident.c
@@ -31,7 +31,7 @@
 
 #include "_libelf.h"
 
-char *
+unsigned char *
 elf_getident(Elf *e, size_t *sz)
 {
 
diff --git a/ext/libelf/elf_hash.c b/ext/libelf/elf_hash.c
--- a/ext/libelf/elf_hash.c
+++ b/ext/libelf/elf_hash.c
@@ -33,12 +33,12 @@
  */
 
 unsigned long
-elf_hash(const char *name)
+elf_hash(const unsigned char *name)
 {
         unsigned long h, t;
         const unsigned char *s;
 
-        s = (const unsigned char *) name;
+        s = name;
         h = t = 0;
 
         for (; *s != '\0'; h = h & ~t) {
diff --git a/ext/libelf/elf_memory.c b/ext/libelf/elf_memory.c
--- a/ext/libelf/elf_memory.c
+++ b/ext/libelf/elf_memory.c
@@ -32,7 +32,7 @@
 #include "_libelf.h"
 
 Elf *
-elf_memory(char *image, size_t sz)
+elf_memory(unsigned char *image, size_t sz)
 {
         Elf *e;
 
@@ -79,7 +79,7 @@
                 }
 
         } else if (sz >= SARMAG &&
-            strncmp(image, ARMAG, (size_t) SARMAG) == 0) {
+            strncmp((char *)image, ARMAG, (size_t) SARMAG) == 0) {
                 _libelf_init_elf(e, ELF_K_AR);
                 e = _libelf_ar_open(e);
         } else
diff --git a/ext/libelf/elf_rawfile.c b/ext/libelf/elf_rawfile.c
--- a/ext/libelf/elf_rawfile.c
+++ b/ext/libelf/elf_rawfile.c
@@ -29,10 +29,10 @@
 
 #include "_libelf.h"
 
-char *
+unsigned char *
 elf_rawfile(Elf *e, size_t *sz)
 {
-        char *ptr;
+        unsigned char *ptr;
         size_t size;
 
         size = e ? e->e_rawsize : 0;
diff --git a/ext/libelf/elf_scn.c b/ext/libelf/elf_scn.c
--- a/ext/libelf/elf_scn.c
+++ b/ext/libelf/elf_scn.c
@@ -43,11 +43,11 @@
         int ec, swapbytes;
         size_t fsz, i, shnum;
         uint64_t shoff;
-        char *src;
+        unsigned char *src;
         Elf32_Ehdr *eh32;
         Elf64_Ehdr *eh64;
         Elf_Scn *scn;
-        void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+        Elf_Translator xlator;
 
         assert(e != NULL);
         assert(ehdr != NULL);
@@ -80,7 +80,7 @@
         xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
 
         swapbytes = e->e_byteorder != LIBELF_PRIVATE(byteorder);
-        src = e->e_rawfile + shoff;
+        src = (unsigned char *)(e->e_rawfile + shoff);
 
         /*
          * If the file is using extended numbering then section #0
@@ -100,7 +100,7 @@
                 if ((scn = _libelf_allocate_scn(e, i)) == NULL)
                         return (0);
 
-                (*xlator)((char *) &scn->s_shdr, src, (size_t) 1, swapbytes);
+                (*xlator)((unsigned char *)&scn->s_shdr, src, (size_t) 1, 
swapbytes);
 
                 if (ec == ELFCLASS32) {
                         scn->s_offset = scn->s_rawoff =
diff --git a/ext/libelf/libelf.h b/ext/libelf/libelf.h
--- a/ext/libelf/libelf.h
+++ b/ext/libelf/libelf.h
@@ -195,14 +195,14 @@
 Elf_Arsym      *elf_getarsym(Elf *_elf, size_t *_ptr);
 off_t          elf_getbase(Elf *_elf);
 Elf_Data       *elf_getdata(Elf_Scn *, Elf_Data *);
-char           *elf_getident(Elf *_elf, size_t *_ptr);
+unsigned char  *elf_getident(Elf *_elf, size_t *_ptr);
 int            elf_getphnum(Elf *_elf, size_t *_dst);
 Elf_Scn                *elf_getscn(Elf *_elf, size_t _index);
 int            elf_getshnum(Elf *_elf, size_t *_dst);
 int            elf_getshstrndx(Elf *_elf, size_t *_dst);
-unsigned long  elf_hash(const char *_name);
+unsigned long  elf_hash(const unsigned char *_name);
 Elf_Kind       elf_kind(Elf *_elf);
-Elf            *elf_memory(char *_image, size_t _size);
+Elf            *elf_memory(unsigned char *_image, size_t _size);
 size_t         elf_ndxscn(Elf_Scn *_scn);
 Elf_Data       *elf_newdata(Elf_Scn *_scn);
 Elf_Scn                *elf_newscn(Elf *_elf);
@@ -210,7 +210,7 @@
 Elf_Cmd                elf_next(Elf *_elf);
 off_t          elf_rand(Elf *_elf, off_t _off);
 Elf_Data       *elf_rawdata(Elf_Scn *_scn, Elf_Data *_data);
-char           *elf_rawfile(Elf *_elf, size_t *_size);
+unsigned char  *elf_rawfile(Elf *_elf, size_t *_size);
 int            elf_setshstrndx(Elf *_elf, size_t _shnum);
 char           *elf_strptr(Elf *_elf, size_t _section, size_t _offset);
 off_t          elf_update(Elf *_elf, Elf_Cmd _cmd);
diff --git a/ext/libelf/libelf_ar.c b/ext/libelf/libelf_ar.c
--- a/ext/libelf/libelf_ar.c
+++ b/ext/libelf/libelf_ar.c
@@ -185,8 +185,8 @@
                         return (NULL);
                 }
 
-                s = q = e->e_u.e_ar.e_rawstrtab + offset;
-                r = e->e_u.e_ar.e_rawstrtab + e->e_u.e_ar.e_rawstrtabsz;
+                s = q = (char *)e->e_u.e_ar.e_rawstrtab + offset;
+                r = (char *)e->e_u.e_ar.e_rawstrtab + 
e->e_u.e_ar.e_rawstrtabsz;
 
                 for (s = q; s < r && *s != '/'; s++)
                         ;
@@ -308,7 +308,7 @@
 
         arh++; /* skip over archive member header */
 
-        if ((e = elf_memory((char *) arh, sz)) == NULL)
+        if ((e = elf_memory((unsigned char *) arh, sz)) == NULL)
                 return (NULL);
 
         e->e_fd = fd;
@@ -324,7 +324,7 @@
 _libelf_ar_open(Elf *e)
 {
         int i;
-        char *s, *end;
+        unsigned char *s, *end;
         size_t sz;
         struct ar_hdr arh;
 
@@ -419,7 +419,7 @@
 {
         size_t n, nentries, off;
         Elf_Arsym *symtab, *sym;
-        char *p, *s, *end;
+        unsigned char *p, *s, *end;
 
         assert(e != NULL);
         assert(count != NULL);
@@ -455,7 +455,7 @@
 
                 sym->as_off = off;
                 sym->as_hash = elf_hash(s);
-                sym->as_name = s;
+                sym->as_name = (char *)s;
 
                 p += INTSZ;
                 sym++;
diff --git a/ext/libelf/libelf_convert.m4 b/ext/libelf/libelf_convert.m4
--- a/ext/libelf/libelf_convert.m4
+++ b/ext/libelf/libelf_convert.m4
@@ -271,7 +271,7 @@
  */
 define(`MAKEPRIM_TO_F',`
 static void
-libelf_cvt_$1$3_tof(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt_$1$3_tof(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        Elf$4_$2 t, *s = (Elf$4_$2 *) (uintptr_t) src;
        size_t c;
@@ -294,7 +294,7 @@
 
 define(`MAKEPRIM_TO_M',`
 static void
-libelf_cvt_$1$3_tom(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt_$1$3_tom(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        Elf$4_$2 t, *d = (Elf$4_$2 *) (uintptr_t) dst;
        size_t c;
@@ -389,7 +389,7 @@
 define(`MAKE_TO_F',
   `ifdef(`IGNORE_'$1$3,`',`
 static void
-libelf_cvt$3_$1_tof(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt$3_$1_tof(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        Elf$3_$2        t, *s;
        size_t c;
@@ -408,7 +408,7 @@
 define(`MAKE_TO_M',
   `ifdef(`IGNORE_'$1$3,`',`
 static void
-libelf_cvt$3_$1_tom(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt$3_$1_tom(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        Elf$3_$2         t, *d;
        unsigned char   *s,*s0;
@@ -470,7 +470,7 @@
  */
 
 static void
-libelf_cvt_BYTE_tox(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt_BYTE_tox(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        (void) byteswap;
        if (dst != src)
@@ -485,7 +485,7 @@
  * Argument `count' denotes the total number of bytes to be converted.
  */
 static void
-libelf_cvt_NOTE_tom(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt_NOTE_tom(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        uint32_t namesz, descsz, type;
        Elf_Note *en;
@@ -535,7 +535,7 @@
 }
 
 static void
-libelf_cvt_NOTE_tof(char *dst, char *src, size_t count, int byteswap)
+libelf_cvt_NOTE_tof(unsigned char *dst, unsigned char *src, size_t count, int 
byteswap)
 {
        uint32_t namesz, descsz, type;
        Elf_Note *en;
@@ -588,10 +588,10 @@
 MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST)
 
 struct converters {
-       void    (*tof32)(char *dst, char *src, size_t cnt, int byteswap);
-       void    (*tom32)(char *dst, char *src, size_t cnt, int byteswap);
-       void    (*tof64)(char *dst, char *src, size_t cnt, int byteswap);
-       void    (*tom64)(char *dst, char *src, size_t cnt, int byteswap);
+       void    (*tof32)(unsigned char *dst, unsigned char *src, size_t cnt, 
int byteswap);
+       void    (*tom32)(unsigned char *dst, unsigned char *src, size_t cnt, 
int byteswap);
+       void    (*tof64)(unsigned char *dst, unsigned char *src, size_t cnt, 
int byteswap);
+       void    (*tom64)(unsigned char *dst, unsigned char *src, size_t cnt, 
int byteswap);
 };
 
 divert(-1)
@@ -641,7 +641,7 @@
 };
 
 void (*_libelf_get_translator(Elf_Type t, int direction, int elfclass))
- (char *_dst, char *_src, size_t _cnt, int _byteswap)
+ (unsigned char *_dst, unsigned char *_src, size_t _cnt, int _byteswap)
 {
        assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
        assert(direction == ELF_TOFILE || direction == ELF_TOMEMORY);
diff --git a/ext/libelf/libelf_ehdr.c b/ext/libelf/libelf_ehdr.c
--- a/ext/libelf/libelf_ehdr.c
+++ b/ext/libelf/libelf_ehdr.c
@@ -43,7 +43,7 @@
 {
         Elf_Scn *scn;
         size_t fsz;
-        void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+        Elf_Translator xlator;
         uint32_t shtype;
 
         assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn));
@@ -60,7 +60,7 @@
                 return (0);
 
         xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
-        (*xlator)((char *) &scn->s_shdr, e->e_rawfile + shoff, (size_t) 1,
+        (*xlator)((unsigned char *) &scn->s_shdr, e->e_rawfile + shoff, 
(size_t) 1,
             e->e_byteorder != LIBELF_PRIVATE(byteorder));
 
 #define        GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M 
: \
@@ -102,7 +102,7 @@
         size_t fsz, msz;
         uint16_t phnum, shnum, strndx;
         uint64_t shoff;
-        void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+        void (*xlator)(unsigned char *_d, unsigned char *_s, size_t _c, int 
_swap);
 
         assert(ec == ELFCLASS32 || ec == ELFCLASS64);
 
@@ -164,7 +164,7 @@
                 return (ehdr);
 
         xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec);
-        (*xlator)(ehdr, e->e_rawfile, (size_t) 1,
+        (*xlator)(ehdr, (unsigned char *)e->e_rawfile, (size_t) 1,
             e->e_byteorder != LIBELF_PRIVATE(byteorder));
 
         /*
diff --git a/ext/libelf/libelf_phdr.c b/ext/libelf/libelf_phdr.c
--- a/ext/libelf/libelf_phdr.c
+++ b/ext/libelf/libelf_phdr.c
@@ -42,7 +42,7 @@
         Elf32_Ehdr *eh32;
         Elf64_Ehdr *eh64;
         void *ehdr, *phdr;
-        void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+        Elf_Translator xlator;
 
         assert(ec == ELFCLASS32 || ec == ELFCLASS64);
 
diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc
--- a/src/base/loader/elf_object.cc
+++ b/src/base/loader/elf_object.cc
@@ -54,7 +54,7 @@
         panic("wrong elf version number!");
 
     // get a pointer to elf structure
-    elf = elf_memory((char*)data,len);
+    elf = elf_memory((unsigned char*)data,len);
     // will only fail if fd is invalid
     assert(elf != NULL);
 
@@ -214,7 +214,7 @@
         panic("wrong elf version number!");
 
     // get a pointer to elf structure
-    elf = elf_memory((char*)fileData,len);
+    elf = elf_memory((unsigned char*)fileData,len);
     // will only fail if fd is invalid
     assert(elf != NULL);
 
@@ -331,7 +331,7 @@
         panic("wrong elf version number!");
 
     // get a pointer to elf structure
-    elf = elf_memory((char*)fileData,len);
+    elf = elf_memory((unsigned char*)fileData,len);
 
     assert(elf != NULL);
 
@@ -411,7 +411,7 @@
         panic("wrong elf version number!");
 
     // get a pointer to elf structure
-    elf = elf_memory((char*)fileData,len);
+    elf = elf_memory((unsigned char*)fileData,len);
     assert(elf != NULL);
 
     // Check that we actually have a elf file
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to