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

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 29e72e1 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
RevLine 
[69cde8d]1Submitted By: Jim Gifford (patches at jg555 dot com)
2Date: 2006-01-03
3Initial Package Version: 2.3
4Origin: Dave Miller
5Upstream Status: Unknown
6Description: Fixes 64 Bit Issues with Elftoaout
7
8 http://marc.theaimsgroup.com/?l=linux-sparc&m=113617505627794&w=2
9
10diff -Naur elftoaout-2.3.orig/elftoaout.c elftoaout-2.3/elftoaout.c
11--- elftoaout-2.3.orig/elftoaout.c 2000-06-03 20:20:12.000000000 +0000
12+++ elftoaout-2.3/elftoaout.c 2006-01-03 22:33:28.000000000 +0000
13@@ -20,16 +20,36 @@
14 */
15 #include <stdio.h>
16 #include <stdlib.h>
17-#ifdef linux
18 #include <linux/elf.h>
19-#define ELFDATA2MSB 2
20-#else
21-#include <sys/elf.h>
22-#endif
23-
24-#define swab16(x) (((x)<<8&0xFF00)|((x)>>8&0x00FF))
25-#define swab32(x) (((x)<<24&0xFF000000)|((x)<<8&0x00FF0000)|((x)>>24&0x000000FF)|((x)>>8&0x0000FF00))
26-#define swab64(x) ((((unsigned long long)(swab32((unsigned int)x))) << 32) | (swab32(((unsigned long long)x)>>32)))
27+#include <sys/types.h>
28+
29+static inline u_int16_t swab16(u_int16_t x)
30+{
31+ return (((x << 8) & 0xFF00) |
32+ ((x >> 8) & 0x00FF));
33+}
34+
35+static inline u_int32_t swab32(u_int32_t x)
36+{
37+ return (((x << 24) & 0xFF000000) |
38+ ((x << 8) & 0x00FF0000) |
39+ ((x >> 24) & 0x000000FF) |
40+ ((x >> 8) & 0x0000FF00));
41+}
42+
43+static inline u_int64_t swab64(u_int64_t x)
44+{
45+ return ((u_int64_t)
46+ ((u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000000000ffULL) << 56) |
47+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000000000ff00ULL) << 40) |
48+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000000000ff0000ULL) << 24) |
49+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000ff000000ULL) << 8) |
50+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000ff00000000ULL) >> 8) |
51+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000ff0000000000ULL) >> 24) |
52+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00ff000000000000ULL) >> 40) |
53+ (u_int64_t)(((u_int64_t)x & (u_int64_t)0xff00000000000000ULL) >> 56)));
54+}
55+
56
57 /* We carry a.out header here in order to compile the thing on Solaris */
58
59@@ -37,14 +57,14 @@
60 #define CMAGIC 0x01030108
61
62 typedef struct {
63- unsigned long a_magic; /* magic number */
64- unsigned long a_text; /* size of text segment */
65- unsigned long a_data; /* size of initialized data */
66- unsigned long a_bss; /* size of uninitialized data */
67- unsigned long a_syms; /* size of symbol table || checksum */
68- unsigned long a_entry; /* entry point */
69- unsigned long a_trsize; /* size of text relocation */
70- unsigned long a_drsize; /* size of data relocation */
71+ u_int32_t a_magic; /* magic number */
72+ u_int32_t a_text; /* size of text segment */
73+ u_int32_t a_data; /* size of initialized data */
74+ u_int32_t a_bss; /* size of uninitialized data */
75+ u_int32_t a_syms; /* size of symbol table || checksum */
76+ u_int32_t a_entry; /* entry point */
77+ u_int32_t a_trsize; /* size of text relocation */
78+ u_int32_t a_drsize; /* size of data relocation */
79 } Exec;
80
81
82@@ -56,17 +76,16 @@
83 int swab;
84 int sparc64;
85 int csum;
86- /* friend void Usage(void); */
87 } Application;
88
89 typedef struct {
90 Elf32_Phdr *tab;
91- unsigned len;
92+ unsigned int len;
93 } ProgTable;
94
95 typedef struct {
96 Elf64_Phdr *tab;
97- unsigned len;
98+ unsigned int len;
99 } ProgTable64;
100
101 void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h);
102@@ -75,9 +94,9 @@
103 void print_ptab64(ProgTable64 *t);
104
105 typedef struct {
106- char *buf; /* Image data */
107- unsigned len; /* Length of buffer */
108- unsigned bss; /* Length of extra data */
109+ unsigned char *buf; /* Image data */
110+ unsigned int len; /* Length of buffer */
111+ unsigned int bss; /* Length of extra data */
112 } Segment;
113
114 void load_image(Segment *t, const ProgTable *h, FILE *inp);
115@@ -105,7 +124,8 @@
116
117 parse_args(&prog, argc, argv);
118
119- if (prog.version) Version();
120+ if (prog.version)
121+ Version();
122
123 if (freopen(prog.iname, "r", stdin) == NULL) {
124 fprintf(stderr, "Cannot open \"%s\"\n", prog.iname);
125@@ -141,7 +161,8 @@
126 exit(0);
127 }
128
129-void parse_args( Application *t, unsigned argc, const char **argv ){
130+void parse_args( Application *t, unsigned argc, const char **argv )
131+{
132 const char *arg;
133 union {
134 char c[4];
135@@ -185,8 +206,8 @@
136 if (t->csum && t->sun4_mode) Usage (); /* Checksum lives in header. */
137 }
138
139-void get_header(Elf32_Ehdr *t, FILE *inp) {
140-
141+void get_header(Elf32_Ehdr *t, FILE *inp)
142+{
143 if (fread((void*) t, sizeof(Elf64_Ehdr), 1, inp) != 1) {
144 fprintf(stderr, "Read error on header\n");
145 exit(1);
146@@ -249,8 +270,9 @@
147 }
148 }
149
150-void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) {
151- unsigned x;
152+void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h)
153+{
154+ unsigned int x;
155
156 /** fprintf(stderr, "Program header table off = 0x%x\n",
157 (unsigned) h->e_phoff); **/
158@@ -294,8 +316,9 @@
159 }
160 }
161
162-void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) {
163- unsigned x;
164+void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h)
165+{
166+ unsigned int x;
167
168 if (h->e_phoff == 0) {
169 fprintf(stderr, "No Program Header Table\n");
170@@ -332,8 +355,9 @@
171 }
172 }
173
174-void print_ptab(ProgTable *t) {
175- unsigned x;
176+void print_ptab(ProgTable *t)
177+{
178+ unsigned int x;
179 const Elf32_Phdr *p;
180
181 for (x = 0; x < t->len; x++) {
182@@ -374,8 +398,9 @@
183 }
184 }
185
186-void print_ptab64(ProgTable64 *t) {
187- unsigned x;
188+void print_ptab64(ProgTable64 *t)
189+{
190+ unsigned int x;
191 const Elf64_Phdr *p;
192
193 for (x = 0; x < t->len; x++) {
194@@ -387,8 +412,11 @@
195 break;
196 case PT_LOAD:
197 printf("Loadable to 0x%Lx[0x%Lx] from 0x%Lx[0x%Lx] align 0x%Lx",
198- p->p_vaddr, p->p_memsz, p->p_offset, p->p_filesz,
199- p->p_align);
200+ (unsigned long long) p->p_vaddr,
201+ (unsigned long long) p->p_memsz,
202+ (unsigned long long) p->p_offset,
203+ (unsigned long long) p->p_filesz,
204+ (unsigned long long) p->p_align);
205 break;
206 case PT_DYNAMIC:
207 printf("Dynamic");
208@@ -416,9 +444,10 @@
209 }
210 }
211
212-void load_image(Segment *t, const ProgTable *tp, FILE *inp) {
213+void load_image(Segment *t, const ProgTable *tp, FILE *inp)
214+{
215 Elf32_Phdr *p, *q;
216- unsigned x;
217+ unsigned int x;
218 unsigned long off, len;
219
220 p = 0;
221@@ -484,9 +513,10 @@
222 }
223 }
224
225-void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) {
226+void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp)
227+{
228 Elf64_Phdr *p, *q;
229- unsigned x;
230+ unsigned int x;
231 unsigned long long off, len;
232
233 p = 0;
234@@ -547,7 +577,8 @@
235 }
236 }
237
238-void store_image(Segment *t, FILE *out) {
239+void store_image(Segment *t, FILE *out)
240+{
241 Exec ohdb;
242
243 if (prog.swab) {
244@@ -585,13 +616,15 @@
245 return;
246 }
247
248-void Usage(){
249+void Usage()
250+{
251 if (prog.version) Version();
252 fprintf(stderr, "Usage: elftoaout [-o output] [-c|-b] [-V] input\n");
253 exit(1);
254 }
255
256-void Version(){
257+void Version()
258+{
259 printf("elftoaout 2.3: ELF to a.out convertor for SPARC and SPARC64 bootstraps\n");
260 }
261
Note: See TracBrowser for help on using the repository browser.