source: patches/elftoaout-2.3-64bit_fixes-1.patch@ ad4134f

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since ad4134f was 69cde8d, checked in by Jim Gifford <clfs@…>, 19 years ago

Added: All patches needed for the book.

  • Property mode set to 100644
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  
    2020 */
    2121#include <stdio.h>
    2222#include <stdlib.h>
    23 #ifdef linux
    2423#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
     26static inline u_int16_t swab16(u_int16_t x)
     27{
     28        return (((x << 8)  & 0xFF00) |
     29                ((x >> 8) & 0x00FF));
     30}
     31
     32static 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
     40static 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
    3353
    3454/* We carry a.out header here in order to compile the thing on Solaris */
    3555
     
    3757#define CMAGIC      0x01030108
    3858
    3959typedef struct {
    40         unsigned long   a_magic;        /* magic number */
    41         unsigned long   a_text;         /* size of text segment */
    42         unsigned long   a_data;         /* size of initialized data */
    43         unsigned long   a_bss;          /* size of uninitialized data */
    44         unsigned long   a_syms;         /* size of symbol table || checksum */
    45         unsigned long   a_entry;        /* entry point */
    46         unsigned long   a_trsize;       /* size of text relocation */
    47         unsigned long   a_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 */
    4868} Exec;
    4969
    5070
     
    5676        int swab;
    5777        int sparc64;
    5878        int csum;
    59         /* friend void Usage(void); */
    6079} Application;
    6180
    6281typedef struct {
    6382        Elf32_Phdr *tab;
    64         unsigned len;
     83        unsigned int len;
    6584} ProgTable;
    6685
    6786typedef struct {
    6887        Elf64_Phdr *tab;
    69         unsigned len;
     88        unsigned int len;
    7089} ProgTable64;
    7190
    7291void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h);
     
    7594void print_ptab64(ProgTable64 *t);
    7695
    7796typedef 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 */
    81100} Segment;
    82101
    83102void load_image(Segment *t, const ProgTable *h, FILE *inp);
     
    105124
    106125        parse_args(&prog, argc, argv);
    107126
    108         if (prog.version) Version();
     127        if (prog.version)
     128                Version();
    109129
    110130        if (freopen(prog.iname, "r", stdin) == NULL) {
    111131                fprintf(stderr, "Cannot open \"%s\"\n", prog.iname);
     
    141161        exit(0);
    142162}
    143163
    144 void parse_args( Application *t, unsigned argc, const char **argv ){
     164void parse_args( Application *t, unsigned argc, const char **argv )
     165{
    145166        const char *arg;
    146167        union {
    147168                char c[4];
     
    185206        if (t->csum && t->sun4_mode) Usage ();  /* Checksum lives in header. */
    186207}
    187208
    188 void get_header(Elf32_Ehdr *t, FILE *inp) {
    189 
     209void get_header(Elf32_Ehdr *t, FILE *inp)
     210{
    190211        if (fread((void*) t, sizeof(Elf64_Ehdr), 1, inp) != 1) {
    191212                fprintf(stderr, "Read error on header\n");
    192213                exit(1);
     
    249270        }
    250271}
    251272
    252 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) {
    253         unsigned x;
     273void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h)
     274{
     275        unsigned int x;
    254276
    255277        /** fprintf(stderr, "Program header table off = 0x%x\n",
    256278                (unsigned) h->e_phoff); **/
     
    294316        }
    295317}
    296318
    297 void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) {
    298         unsigned x;
     319void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h)
     320{
     321        unsigned int x;
    299322
    300323        if (h->e_phoff == 0) {
    301324                fprintf(stderr, "No Program Header Table\n");
     
    332355        }
    333356}
    334357
    335 void print_ptab(ProgTable *t) {
    336         unsigned x;
     358void print_ptab(ProgTable *t)
     359{
     360        unsigned int x;
    337361        const Elf32_Phdr *p;
    338362
    339363        for (x = 0; x < t->len; x++) {
     
    374398        }
    375399}
    376400
    377 void print_ptab64(ProgTable64 *t) {
    378         unsigned x;
     401void print_ptab64(ProgTable64 *t)
     402{
     403        unsigned int x;
    379404        const Elf64_Phdr *p;
    380405
    381406        for (x = 0; x < t->len; x++) {
     
    387412                        break;
    388413                case PT_LOAD:
    389414                        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);
    392420                        break;
    393421                case PT_DYNAMIC:
    394422                        printf("Dynamic");
     
    416444        }
    417445}
    418446
    419 void load_image(Segment *t, const ProgTable *tp, FILE *inp) {
     447void load_image(Segment *t, const ProgTable *tp, FILE *inp)
     448{
    420449        Elf32_Phdr *p, *q;
    421         unsigned x;
     450        unsigned int x;
    422451        unsigned long off, len;
    423452
    424453        p = 0;
     
    484513        }
    485514}
    486515
    487 void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) {
     516void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp)
     517{
    488518        Elf64_Phdr *p, *q;
    489         unsigned x;
     519        unsigned int x;
    490520        unsigned long long off, len;
    491521
    492522        p = 0;
     
    547577        }
    548578}
    549579
    550 void store_image(Segment *t, FILE *out) {
     580void store_image(Segment *t, FILE *out)
     581{
    551582        Exec ohdb;
    552583
    553584        if (prog.swab) {
     
    585616        return;
    586617}
    587618
    588 void Usage(){
     619void Usage()
     620{
    589621        if (prog.version) Version();
    590622        fprintf(stderr, "Usage: elftoaout [-o output] [-c|-b] [-V] input\n");
    591623        exit(1);
    592624}
    593625
    594 void Version(){
     626void Version()
     627{
    595628        printf("elftoaout 2.3: ELF to a.out convertor for SPARC and SPARC64 bootstraps\n");
    596629}
    597630
Note: See TracBrowser for help on using the repository browser.