Commit 0c3bf184 authored by Thomas Bogendoerfer's avatar Thomas Bogendoerfer Committed by Paul Burton

MIPS: Make elf2ecoff work on 64bit host machines

Use fixed width integer types for ecoff structs to make elf2ecoff work
on 64bit host machines.
Signed-off-by: default avatarThomas Bogendoerfer <tbogendoerfer@suse.de>
Reviewed-by: default avatarPaul Burton <paul.burton@mips.com>
Patchwork: https://patchwork.linux-mips.org/patch/19483/Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
parent 7daf201d
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
/* /*
* Some ECOFF definitions. * Some ECOFF definitions.
*/ */
#include <stdint.h>
typedef struct filehdr { typedef struct filehdr {
unsigned short f_magic; /* magic number */ uint16_t f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */ uint16_t f_nscns; /* number of sections */
long f_timdat; /* time & date stamp */ int32_t f_timdat; /* time & date stamp */
long f_symptr; /* file pointer to symbolic header */ int32_t f_symptr; /* file pointer to symbolic header */
long f_nsyms; /* sizeof(symbolic hdr) */ int32_t f_nsyms; /* sizeof(symbolic hdr) */
unsigned short f_opthdr; /* sizeof(optional hdr) */ uint16_t f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */ uint16_t f_flags; /* flags */
} FILHDR; } FILHDR;
#define FILHSZ sizeof(FILHDR) #define FILHSZ sizeof(FILHDR)
...@@ -18,32 +21,32 @@ typedef struct filehdr { ...@@ -18,32 +21,32 @@ typedef struct filehdr {
typedef struct scnhdr { typedef struct scnhdr {
char s_name[8]; /* section name */ char s_name[8]; /* section name */
long s_paddr; /* physical address, aliased s_nlib */ int32_t s_paddr; /* physical address, aliased s_nlib */
long s_vaddr; /* virtual address */ int32_t s_vaddr; /* virtual address */
long s_size; /* section size */ int32_t s_size; /* section size */
long s_scnptr; /* file ptr to raw data for section */ int32_t s_scnptr; /* file ptr to raw data for section */
long s_relptr; /* file ptr to relocation */ int32_t s_relptr; /* file ptr to relocation */
long s_lnnoptr; /* file ptr to gp histogram */ int32_t s_lnnoptr; /* file ptr to gp histogram */
unsigned short s_nreloc; /* number of relocation entries */ uint16_t s_nreloc; /* number of relocation entries */
unsigned short s_nlnno; /* number of gp histogram entries */ uint16_t s_nlnno; /* number of gp histogram entries */
long s_flags; /* flags */ int32_t s_flags; /* flags */
} SCNHDR; } SCNHDR;
#define SCNHSZ sizeof(SCNHDR) #define SCNHSZ sizeof(SCNHDR)
#define SCNROUND ((long)16) #define SCNROUND ((int32_t)16)
typedef struct aouthdr { typedef struct aouthdr {
short magic; /* see above */ int16_t magic; /* see above */
short vstamp; /* version stamp */ int16_t vstamp; /* version stamp */
long tsize; /* text size in bytes, padded to DW bdry*/ int32_t tsize; /* text size in bytes, padded to DW bdry*/
long dsize; /* initialized data " " */ int32_t dsize; /* initialized data " " */
long bsize; /* uninitialized data " " */ int32_t bsize; /* uninitialized data " " */
long entry; /* entry pt. */ int32_t entry; /* entry pt. */
long text_start; /* base of text used for this file */ int32_t text_start; /* base of text used for this file */
long data_start; /* base of data used for this file */ int32_t data_start; /* base of data used for this file */
long bss_start; /* base of bss used for this file */ int32_t bss_start; /* base of bss used for this file */
long gprmask; /* general purpose register mask */ int32_t gprmask; /* general purpose register mask */
long cprmask[4]; /* co-processor register masks */ int32_t cprmask[4]; /* co-processor register masks */
long gp_value; /* the gp value used for this object */ int32_t gp_value; /* the gp value used for this object */
} AOUTHDR; } AOUTHDR;
#define AOUTHSZ sizeof(AOUTHDR) #define AOUTHSZ sizeof(AOUTHDR)
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include <limits.h> #include <limits.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include "ecoff.h" #include "ecoff.h"
...@@ -55,8 +57,8 @@ ...@@ -55,8 +57,8 @@
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
struct sect { struct sect {
unsigned long vaddr; uint32_t vaddr;
unsigned long len; uint32_t len;
}; };
int *symTypeTable; int *symTypeTable;
...@@ -153,16 +155,16 @@ static char *saveRead(int file, off_t offset, off_t len, char *name) ...@@ -153,16 +155,16 @@ static char *saveRead(int file, off_t offset, off_t len, char *name)
} }
#define swab16(x) \ #define swab16(x) \
((unsigned short)( \ ((uint16_t)( \
(((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \ (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
(((unsigned short)(x) & (unsigned short)0xff00U) >> 8) )) (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) ))
#define swab32(x) \ #define swab32(x) \
((unsigned int)( \ ((unsigned int)( \
(((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \ (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
(((unsigned int)(x) & (unsigned int)0x0000ff00UL) << 8) | \ (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
(((unsigned int)(x) & (unsigned int)0x00ff0000UL) >> 8) | \ (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) )) (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) ))
static void convert_elf_hdr(Elf32_Ehdr * e) static void convert_elf_hdr(Elf32_Ehdr * e)
{ {
...@@ -274,7 +276,7 @@ int main(int argc, char *argv[]) ...@@ -274,7 +276,7 @@ int main(int argc, char *argv[])
struct aouthdr eah; struct aouthdr eah;
struct scnhdr esecs[6]; struct scnhdr esecs[6];
int infile, outfile; int infile, outfile;
unsigned long cur_vma = ULONG_MAX; uint32_t cur_vma = UINT32_MAX;
int addflag = 0; int addflag = 0;
int nosecs; int nosecs;
...@@ -518,7 +520,7 @@ int main(int argc, char *argv[]) ...@@ -518,7 +520,7 @@ int main(int argc, char *argv[])
for (i = 0; i < nosecs; i++) { for (i = 0; i < nosecs; i++) {
printf printf
("Section %d: %s phys %lx size %lx file offset %lx\n", ("Section %d: %s phys %"PRIx32" size %"PRIx32"\t file offset %"PRIx32"\n",
i, esecs[i].s_name, esecs[i].s_paddr, i, esecs[i].s_name, esecs[i].s_paddr,
esecs[i].s_size, esecs[i].s_scnptr); esecs[i].s_size, esecs[i].s_scnptr);
} }
...@@ -564,17 +566,16 @@ int main(int argc, char *argv[]) ...@@ -564,17 +566,16 @@ int main(int argc, char *argv[])
the section can be loaded before copying. */ the section can be loaded before copying. */
if (ph[i].p_type == PT_LOAD && ph[i].p_filesz) { if (ph[i].p_type == PT_LOAD && ph[i].p_filesz) {
if (cur_vma != ph[i].p_vaddr) { if (cur_vma != ph[i].p_vaddr) {
unsigned long gap = uint32_t gap = ph[i].p_vaddr - cur_vma;
ph[i].p_vaddr - cur_vma;
char obuf[1024]; char obuf[1024];
if (gap > 65536) { if (gap > 65536) {
fprintf(stderr, fprintf(stderr,
"Intersegment gap (%ld bytes) too large.\n", "Intersegment gap (%"PRId32" bytes) too large.\n",
gap); gap);
exit(1); exit(1);
} }
fprintf(stderr, fprintf(stderr,
"Warning: %ld byte intersegment gap.\n", "Warning: %d byte intersegment gap.\n",
gap); gap);
memset(obuf, 0, sizeof obuf); memset(obuf, 0, sizeof obuf);
while (gap) { while (gap) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment