source:
patches/elftoaout-2.3-64bit_fixes-1.patch@
e963bf3
Last change on this file since e963bf3 was 69cde8d, checked in by , 19 years ago | |
---|---|
|
|
File size: 6.7 KB |
-
elftoaout-2.3
Submitted By: Jim Gifford (patches at jg555 dot com) Date: 2006-01-03 Initial Package Version: 2.3 Origin: Dave Miller Upstream Status: Unknown Description: Fixes 64 Bit Issues with Elftoaout http://marc.theaimsgroup.com/?l=linux-sparc&m=113617505627794&w=2 diff -Naur elftoaout-2.3.orig/elftoaout.c elftoaout-2.3/elftoaout.c
old new 20 20 */ 21 21 #include <stdio.h> 22 22 #include <stdlib.h> 23 #ifdef linux24 23 #include <linux/elf.h> 25 #define ELFDATA2MSB 2 26 #else 27 #include <sys/elf.h> 28 #endif 29 30 #define swab16(x) (((x)<<8&0xFF00)|((x)>>8&0x00FF)) 31 #define swab32(x) (((x)<<24&0xFF000000)|((x)<<8&0x00FF0000)|((x)>>24&0x000000FF)|((x)>>8&0x0000FF00)) 32 #define swab64(x) ((((unsigned long long)(swab32((unsigned int)x))) << 32) | (swab32(((unsigned long long)x)>>32))) 24 #include <sys/types.h> 25 26 static inline u_int16_t swab16(u_int16_t x) 27 { 28 return (((x << 8) & 0xFF00) | 29 ((x >> 8) & 0x00FF)); 30 } 31 32 static inline u_int32_t swab32(u_int32_t x) 33 { 34 return (((x << 24) & 0xFF000000) | 35 ((x << 8) & 0x00FF0000) | 36 ((x >> 24) & 0x000000FF) | 37 ((x >> 8) & 0x0000FF00)); 38 } 39 40 static inline u_int64_t swab64(u_int64_t x) 41 { 42 return ((u_int64_t) 43 ((u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000000000ffULL) << 56) | 44 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000000000ff00ULL) << 40) | 45 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000000000ff0000ULL) << 24) | 46 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000ff000000ULL) << 8) | 47 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000ff00000000ULL) >> 8) | 48 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000ff0000000000ULL) >> 24) | 49 (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00ff000000000000ULL) >> 40) | 50 (u_int64_t)(((u_int64_t)x & (u_int64_t)0xff00000000000000ULL) >> 56))); 51 } 52 33 53 34 54 /* We carry a.out header here in order to compile the thing on Solaris */ 35 55 … … 37 57 #define CMAGIC 0x01030108 38 58 39 59 typedef struct { 40 u nsigned longa_magic; /* magic number */41 u nsigned longa_text; /* size of text segment */42 u nsigned longa_data; /* size of initialized data */43 u nsigned longa_bss; /* size of uninitialized data */44 u nsigned longa_syms; /* size of symbol table || checksum */45 u nsigned longa_entry; /* entry point */46 u nsigned longa_trsize; /* size of text relocation */47 u nsigned longa_drsize; /* size of data relocation */60 u_int32_t a_magic; /* magic number */ 61 u_int32_t a_text; /* size of text segment */ 62 u_int32_t a_data; /* size of initialized data */ 63 u_int32_t a_bss; /* size of uninitialized data */ 64 u_int32_t a_syms; /* size of symbol table || checksum */ 65 u_int32_t a_entry; /* entry point */ 66 u_int32_t a_trsize; /* size of text relocation */ 67 u_int32_t a_drsize; /* size of data relocation */ 48 68 } Exec; 49 69 50 70 … … 56 76 int swab; 57 77 int sparc64; 58 78 int csum; 59 /* friend void Usage(void); */60 79 } Application; 61 80 62 81 typedef struct { 63 82 Elf32_Phdr *tab; 64 unsigned len;83 unsigned int len; 65 84 } ProgTable; 66 85 67 86 typedef struct { 68 87 Elf64_Phdr *tab; 69 unsigned len;88 unsigned int len; 70 89 } ProgTable64; 71 90 72 91 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h); … … 75 94 void print_ptab64(ProgTable64 *t); 76 95 77 96 typedef struct { 78 char *buf;/* Image data */79 unsigned len;/* Length of buffer */80 unsigned bss;/* Length of extra data */97 unsigned char *buf; /* Image data */ 98 unsigned int len; /* Length of buffer */ 99 unsigned int bss; /* Length of extra data */ 81 100 } Segment; 82 101 83 102 void load_image(Segment *t, const ProgTable *h, FILE *inp); … … 105 124 106 125 parse_args(&prog, argc, argv); 107 126 108 if (prog.version) Version(); 127 if (prog.version) 128 Version(); 109 129 110 130 if (freopen(prog.iname, "r", stdin) == NULL) { 111 131 fprintf(stderr, "Cannot open \"%s\"\n", prog.iname); … … 141 161 exit(0); 142 162 } 143 163 144 void parse_args( Application *t, unsigned argc, const char **argv ){ 164 void parse_args( Application *t, unsigned argc, const char **argv ) 165 { 145 166 const char *arg; 146 167 union { 147 168 char c[4]; … … 185 206 if (t->csum && t->sun4_mode) Usage (); /* Checksum lives in header. */ 186 207 } 187 208 188 void get_header(Elf32_Ehdr *t, FILE *inp) {189 209 void get_header(Elf32_Ehdr *t, FILE *inp) 210 { 190 211 if (fread((void*) t, sizeof(Elf64_Ehdr), 1, inp) != 1) { 191 212 fprintf(stderr, "Read error on header\n"); 192 213 exit(1); … … 249 270 } 250 271 } 251 272 252 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) { 253 unsigned x; 273 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) 274 { 275 unsigned int x; 254 276 255 277 /** fprintf(stderr, "Program header table off = 0x%x\n", 256 278 (unsigned) h->e_phoff); **/ … … 294 316 } 295 317 } 296 318 297 void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) { 298 unsigned x; 319 void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) 320 { 321 unsigned int x; 299 322 300 323 if (h->e_phoff == 0) { 301 324 fprintf(stderr, "No Program Header Table\n"); … … 332 355 } 333 356 } 334 357 335 void print_ptab(ProgTable *t) { 336 unsigned x; 358 void print_ptab(ProgTable *t) 359 { 360 unsigned int x; 337 361 const Elf32_Phdr *p; 338 362 339 363 for (x = 0; x < t->len; x++) { … … 374 398 } 375 399 } 376 400 377 void print_ptab64(ProgTable64 *t) { 378 unsigned x; 401 void print_ptab64(ProgTable64 *t) 402 { 403 unsigned int x; 379 404 const Elf64_Phdr *p; 380 405 381 406 for (x = 0; x < t->len; x++) { … … 387 412 break; 388 413 case PT_LOAD: 389 414 printf("Loadable to 0x%Lx[0x%Lx] from 0x%Lx[0x%Lx] align 0x%Lx", 390 p->p_vaddr, p->p_memsz, p->p_offset, p->p_filesz, 391 p->p_align); 415 (unsigned long long) p->p_vaddr, 416 (unsigned long long) p->p_memsz, 417 (unsigned long long) p->p_offset, 418 (unsigned long long) p->p_filesz, 419 (unsigned long long) p->p_align); 392 420 break; 393 421 case PT_DYNAMIC: 394 422 printf("Dynamic"); … … 416 444 } 417 445 } 418 446 419 void load_image(Segment *t, const ProgTable *tp, FILE *inp) { 447 void load_image(Segment *t, const ProgTable *tp, FILE *inp) 448 { 420 449 Elf32_Phdr *p, *q; 421 unsigned x;450 unsigned int x; 422 451 unsigned long off, len; 423 452 424 453 p = 0; … … 484 513 } 485 514 } 486 515 487 void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) { 516 void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) 517 { 488 518 Elf64_Phdr *p, *q; 489 unsigned x;519 unsigned int x; 490 520 unsigned long long off, len; 491 521 492 522 p = 0; … … 547 577 } 548 578 } 549 579 550 void store_image(Segment *t, FILE *out) { 580 void store_image(Segment *t, FILE *out) 581 { 551 582 Exec ohdb; 552 583 553 584 if (prog.swab) { … … 585 616 return; 586 617 } 587 618 588 void Usage(){ 619 void Usage() 620 { 589 621 if (prog.version) Version(); 590 622 fprintf(stderr, "Usage: elftoaout [-o output] [-c|-b] [-V] input\n"); 591 623 exit(1); 592 624 } 593 625 594 void Version(){ 626 void Version() 627 { 595 628 printf("elftoaout 2.3: ELF to a.out convertor for SPARC and SPARC64 bootstraps\n"); 596 629 } 597 630
Note:
See TracBrowser
for help on using the repository browser.