David S. Miller | 3 Jan 22:38 2006
Picon

Re: SILO 1.4.10

From: Jim Gifford <maillist <at> jg555.com>
Date: Tue, 03 Jan 2006 09:39:19 -0800

> 1 - elftoaout is not creating proper files when it's compiled as 64bit

I actually did the investigation and elftoaout cannot work
ever when built 64-bit.  It defines the member types of the
A.OUT header structure as "unsigned long" which is 64-bit
when compiled 64-bit, it needs to be 32-bits in size.

Please try this patch:

--- elftoaout.c.~1~	2000-06-03 13:20:12.000000000 -0700
+++ elftoaout.c	2006-01-03 13:36:06.000000000 -0800
 <at>  <at>  -20,16 +20,36  <at>  <at> 
  */
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef linux
 #include <linux/elf.h>
-#define ELFDATA2MSB   2
-#else
-#include <sys/elf.h>
-#endif
-
-#define swab16(x)  (((x)<<8&0xFF00)|((x)>>8&0x00FF))
-#define swab32(x)  (((x)<<24&0xFF000000)|((x)<<8&0x00FF0000)|((x)>>24&0x000000FF)|((x)>>8&0x0000FF00))
-#define swab64(x)  ((((unsigned long long)(swab32((unsigned int)x))) << 32) | (swab32(((unsigned
long long)x)>>32)))
+#include <sys/types.h>
+
+static inline u_int16_t swab16(u_int16_t x)
+{
+	return (((x << 8)  & 0xFF00) |
+		((x >> 8) & 0x00FF));
+}
+
+static inline u_int32_t swab32(u_int32_t x)
+{
+	return (((x << 24) & 0xFF000000) |
+		((x <<  8) & 0x00FF0000) |
+		((x >> 24) & 0x000000FF) |
+		((x >>  8) & 0x0000FF00));
+}
+
+static inline u_int64_t swab64(u_int64_t x)
+{
+	return ((u_int64_t)
+	((u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000000000ffULL) << 56) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000000000ff00ULL) << 40) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000000000ff0000ULL) << 24) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000ff000000ULL) <<  8) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000ff00000000ULL) >>  8) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000ff0000000000ULL) >> 24) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00ff000000000000ULL) >> 40) |
+	 (u_int64_t)(((u_int64_t)x & (u_int64_t)0xff00000000000000ULL) >> 56)));
+}
+

 /* We carry a.out header here in order to compile the thing on Solaris */

 <at>  <at>  -37,14 +57,14  <at>  <at> 
 #define	CMAGIC	    0x01030108

 typedef struct {
-	unsigned long	a_magic;	/* magic number */
-	unsigned long	a_text;		/* size of text segment */
-	unsigned long	a_data;		/* size of initialized data */
-	unsigned long	a_bss;		/* size of uninitialized data */
-	unsigned long	a_syms;		/* size of symbol table || checksum */
-	unsigned long	a_entry;	/* entry point */
-	unsigned long	a_trsize;	/* size of text relocation */
-	unsigned long	a_drsize;	/* size of data relocation */
+	u_int32_t	a_magic;	/* magic number */
+	u_int32_t	a_text;		/* size of text segment */
+	u_int32_t	a_data;		/* size of initialized data */
+	u_int32_t	a_bss;		/* size of uninitialized data */
+	u_int32_t	a_syms;		/* size of symbol table || checksum */
+	u_int32_t	a_entry;	/* entry point */
+	u_int32_t	a_trsize;	/* size of text relocation */
+	u_int32_t	a_drsize;	/* size of data relocation */
 } Exec;

 
 <at>  <at>  -56,17 +76,16  <at>  <at> 
 	int swab;
 	int sparc64;
 	int csum;
-	/* friend void Usage(void); */
 } Application;

 typedef struct {
 	Elf32_Phdr *tab;
-	unsigned len;
+	unsigned int len;
 } ProgTable;

 typedef struct {
 	Elf64_Phdr *tab;
-	unsigned len;
+	unsigned int len;
 } ProgTable64;

 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h);
 <at>  <at>  -75,9 +94,9  <at>  <at> 
 void print_ptab64(ProgTable64 *t);

 typedef struct {
-	char *buf;                /* Image data */
-	unsigned len;             /* Length of buffer */
-	unsigned bss;             /* Length of extra data */
+	unsigned char *buf;       /* Image data */
+	unsigned int len;         /* Length of buffer */
+	unsigned int bss;         /* Length of extra data */
 } Segment;

 void load_image(Segment *t, const ProgTable *h, FILE *inp);
 <at>  <at>  -105,7 +124,8  <at>  <at> 

 	parse_args(&prog, argc, argv);

-	if (prog.version) Version();
+	if (prog.version)
+		Version();

 	if (freopen(prog.iname, "r", stdin) == NULL) {
 		fprintf(stderr, "Cannot open \"%s\"\n", prog.iname);
 <at>  <at>  -141,7 +161,8  <at>  <at> 
 	exit(0);
 }

-void parse_args( Application *t, unsigned argc, const char **argv ){
+void parse_args( Application *t, unsigned argc, const char **argv )
+{
 	const char *arg;
 	union {
 		char c[4];
 <at>  <at>  -185,8 +206,8  <at>  <at> 
 	if (t->csum && t->sun4_mode) Usage ();	/* Checksum lives in header. */
 }

-void get_header(Elf32_Ehdr *t, FILE *inp) {
-
+void get_header(Elf32_Ehdr *t, FILE *inp)
+{
         if (fread((void*) t, sizeof(Elf64_Ehdr), 1, inp) != 1) {
 		fprintf(stderr, "Read error on header\n");
 		exit(1);
 <at>  <at>  -249,8 +270,9  <at>  <at> 
 	}
 }

-void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) {
-	unsigned x;
+void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h)
+{
+	unsigned int x;

 	/** fprintf(stderr, "Program header table off = 0x%x\n",
 		(unsigned) h->e_phoff); **/
 <at>  <at>  -294,8 +316,9  <at>  <at> 
 	}
 }

-void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) {
-	unsigned x;
+void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h)
+{
+	unsigned int x;

 	if (h->e_phoff == 0) {
 		fprintf(stderr, "No Program Header Table\n");
 <at>  <at>  -332,8 +355,9  <at>  <at> 
 	}
 }

-void print_ptab(ProgTable *t) {
-	unsigned x;
+void print_ptab(ProgTable *t)
+{
+	unsigned int x;
 	const Elf32_Phdr *p;

 	for (x = 0; x < t->len; x++) {
 <at>  <at>  -374,8 +398,9  <at>  <at> 
 	}
 }

-void print_ptab64(ProgTable64 *t) {
-	unsigned x;
+void print_ptab64(ProgTable64 *t)
+{
+	unsigned int x;
 	const Elf64_Phdr *p;

 	for (x = 0; x < t->len; x++) {
 <at>  <at>  -387,8 +412,11  <at>  <at> 
 			break;
 		case PT_LOAD:
 			printf("Loadable to 0x%Lx[0x%Lx] from 0x%Lx[0x%Lx] align 0x%Lx",
-				p->p_vaddr, p->p_memsz, p->p_offset, p->p_filesz,
-				p->p_align);
+			       (unsigned long long) p->p_vaddr,
+			       (unsigned long long) p->p_memsz,
+			       (unsigned long long) p->p_offset,
+			       (unsigned long long) p->p_filesz,
+			       (unsigned long long) p->p_align);
 			break;
 		case PT_DYNAMIC:
 			printf("Dynamic");
 <at>  <at>  -416,9 +444,10  <at>  <at> 
 	}
 }

-void load_image(Segment *t, const ProgTable *tp, FILE *inp) {
+void load_image(Segment *t, const ProgTable *tp, FILE *inp)
+{
 	Elf32_Phdr *p, *q;
-	unsigned x;
+	unsigned int x;
 	unsigned long off, len;

 	p = 0;
 <at>  <at>  -484,9 +513,10  <at>  <at> 
 	}
 }

-void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) {
+void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp)
+{
 	Elf64_Phdr *p, *q;
-	unsigned x;
+	unsigned int x;
 	unsigned long long off, len;

 	p = 0;
 <at>  <at>  -547,7 +577,8  <at>  <at> 
 	}
 }

-void store_image(Segment *t, FILE *out) {
+void store_image(Segment *t, FILE *out)
+{
 	Exec ohdb;

 	if (prog.swab) {
 <at>  <at>  -585,13 +616,15  <at>  <at> 
 	return;
 }

-void Usage(){
+void Usage()
+{
 	if (prog.version) Version();
 	fprintf(stderr, "Usage: elftoaout [-o output] [-c|-b] [-V] input\n");
 	exit(1);
 }

-void Version(){
+void Version()
+{
 	printf("elftoaout 2.3: ELF to a.out convertor for SPARC and SPARC64 bootstraps\n");
 }

-
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Gmane