summaryrefslogtreecommitdiffstats
path: root/package/modutils/modutils-cross.patch
blob: c62f8860ad7c7ce874bcacf2d725d1d584087799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
diff -urN modutils-2.4.27.0.orig/depmod/depmod.c modutils-2.4.27.0/depmod/depmod.c
--- modutils-2.4.27.0.orig/depmod/depmod.c	2005-09-29 18:14:05.000000000 -0600
+++ modutils-2.4.27.0/depmod/depmod.c	2005-09-29 18:12:36.000000000 -0600
@@ -274,7 +274,6 @@
 
 extern int quick;	/* Option -A */
 
-
 /*
  *	Create a symbol definition.
  *	Add defined symbol to the head of the list of defined symbols.
@@ -556,6 +555,13 @@
 		if (!in_range(f, m_size, ref_pci, sizeof(pci_device_size)))
 			return;
 		memcpy(&pci_device_size, (char *)image + ref_pci - f->baseaddr, sizeof(pci_device_size));
+		if (byteswap==1) {
+		    if (sizeof(unsigned tgt_long) == 4) {
+			pci_device_size = bswap_32(pci_device_size);
+		    } else if (sizeof(unsigned tgt_long) == 8) {
+			pci_device_size = bswap_64(pci_device_size);
+		    }
+		}
 	}
 	else
 		pci_device_size = sizeof(pci_device);
@@ -573,6 +579,14 @@
 		memset(&pci_device, 0, sizeof(pci_device));
 		memcpy(&pci_device, (char *)image + ref_pci - f->baseaddr, pci_device_size);
 		ref_pci += pci_device_size;
+		if (byteswap==1) {
+		    pci_device.vendor = bswap_32(pci_device.vendor);
+		    pci_device.device = bswap_32(pci_device.device);
+		    pci_device.subvendor = bswap_32(pci_device.subvendor);
+		    pci_device.subdevice = bswap_32(pci_device.subdevice);
+		    pci_device.class = bswap_32(pci_device.class);
+		    pci_device.class_mask = bswap_32(pci_device.class_mask);
+		}
 		if (!pci_device.vendor)
 			break;
 		mod->pci_device = xrealloc(mod->pci_device, ++(mod->n_pci_device)*sizeof(*(mod->pci_device)));
@@ -594,6 +608,13 @@
 	if (!in_range(f, m_size, ref_isapnp, sizeof(isapnp_device_size)))
 		return;
 	memcpy(&isapnp_device_size, (char *)image + ref_isapnp - f->baseaddr, sizeof(isapnp_device_size));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		isapnp_device_size = bswap_32(isapnp_device_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		isapnp_device_size = bswap_64(isapnp_device_size);
+	    }
+	}
 	ref_ref_isapnp = obj_symbol_final_value(f, obj_find_symbol(f, "__module_isapnp_device_table"));
 	if (!in_range(f, m_size, ref_ref_isapnp, sizeof(ref_isapnp)))
 		return;
@@ -608,6 +629,12 @@
 		memset(&isapnp_device, 0, sizeof(isapnp_device));
 		memcpy(&isapnp_device, (char *)image + ref_isapnp - f->baseaddr, isapnp_device_size);
 		ref_isapnp += isapnp_device_size;
+		if (byteswap==1) {
+		    isapnp_device.card_vendor = bswap_16(isapnp_device.card_vendor);
+		    isapnp_device.card_device = bswap_16(isapnp_device.card_device);
+		    isapnp_device.vendor = bswap_16(isapnp_device.vendor);
+		    isapnp_device.function = bswap_16(isapnp_device.function);
+		}
 		if (!isapnp_device.card_vendor)
 			break;
 		mod->isapnp_device = xrealloc(mod->isapnp_device, ++(mod->n_isapnp_device)*sizeof(*(mod->isapnp_device)));
@@ -629,6 +656,13 @@
 	if (!in_range(f, m_size, ref_isapnp, sizeof(isapnp_card_size)))
 		return;
 	memcpy(&isapnp_card_size, (char *)image + ref_isapnp - f->baseaddr, sizeof(isapnp_card_size));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		isapnp_card_size = bswap_32(isapnp_card_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		isapnp_card_size = bswap_64(isapnp_card_size);
+	    }
+	}
 	ref_ref_isapnp = obj_symbol_final_value(f, obj_find_symbol(f, "__module_isapnp_card_table"));
 	if (!in_range(f, m_size, ref_ref_isapnp, sizeof(ref_isapnp)))
 		return;
@@ -642,6 +676,11 @@
 		memset(&isapnp_card, 0, sizeof(isapnp_card));
 		memcpy(&isapnp_card, (char *)image + ref_isapnp - f->baseaddr, isapnp_card_size);
 		ref_isapnp += isapnp_card_size;
+		if (byteswap==1) {
+		    isapnp_card.card_vendor = bswap_16(isapnp_card.card_vendor);
+		    isapnp_card.card_device = bswap_16(isapnp_card.card_device);
+		    // Fixme -- iterate over all devs fixing up vendor and function
+		}
 		if (!isapnp_card.card_vendor)
 			break;
 		mod->isapnp_card = xrealloc(mod->isapnp_card, ++(mod->n_isapnp_card)*sizeof(*(mod->isapnp_card)));
@@ -659,11 +698,25 @@
 	struct usb_device_id usb_device, *latest;
 	ElfW(Addr) ref_usb, ref_ref_usb;
 	unsigned tgt_long usb_device_size;
-	ref_usb = obj_symbol_final_value(f, obj_find_symbol(f, "__module_usb_device_size"));
+	struct obj_symbol *sym;
+	sym = obj_find_symbol(f, "__module_usb_device_size");
+	if (!sym)
+		return;
+	ref_usb = obj_symbol_final_value(f, sym);
 	if (!in_range(f, m_size, ref_usb, sizeof(usb_device_size)))
 		return;
 	memcpy(&usb_device_size, (char *)image + ref_usb - f->baseaddr, sizeof(usb_device_size));
-	ref_ref_usb = obj_symbol_final_value(f, obj_find_symbol(f, "__module_usb_device_table"));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		usb_device_size = bswap_32(usb_device_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		usb_device_size = bswap_64(usb_device_size);
+	    }
+	}
+	sym = obj_find_symbol(f, "__module_usb_device_table");
+	if (!sym)
+		return;
+	ref_ref_usb = obj_symbol_final_value(f, sym);
 	if (!in_range(f, m_size, ref_ref_usb, sizeof(ref_usb)))
 		return;
 	memcpy(&ref_usb, (char *)image + ref_ref_usb - f->baseaddr, sizeof(ref_usb));
@@ -677,6 +730,13 @@
 		memset(&usb_device, 0, sizeof(usb_device));
 		memcpy(&usb_device, (char *)image + ref_usb - f->baseaddr, usb_device_size);
 		ref_usb += usb_device_size;
+		if (byteswap==1) {
+		    usb_device.match_flags = bswap_16(usb_device.match_flags);
+		    usb_device.idVendor = bswap_16(usb_device.idVendor);
+		    usb_device.idProduct = bswap_16(usb_device.idProduct);
+		    usb_device.bcdDevice_lo = bswap_16(usb_device.bcdDevice_lo);
+		    usb_device.bcdDevice_hi = bswap_16(usb_device.bcdDevice_hi);
+		}
 		if (!usb_device.idVendor && !usb_device.bDeviceClass &&
 		    !usb_device.bInterfaceClass && !usb_device.driver_info)
 		break;
@@ -699,6 +759,13 @@
 	if (!in_range(f, m_size, ref_parport, sizeof(parport_device_size)))
 		return;
 	memcpy(&parport_device_size, (char *)image + ref_parport - f->baseaddr, sizeof(parport_device_size));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		parport_device_size = bswap_32(parport_device_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		parport_device_size = bswap_64(parport_device_size);
+	    }
+	}
 	ref_ref_parport = obj_symbol_final_value(f, obj_find_symbol(f, "__module_parport_device_table"));
 	if (!in_range(f, m_size, ref_ref_parport, sizeof(ref_parport)))
 		return;
@@ -713,6 +780,14 @@
 		memset(&parport_device, 0, sizeof(parport_device));
 		memcpy(&parport_device, (char *)image + ref_parport - f->baseaddr, parport_device_size);
 		ref_parport += parport_device_size;
+		if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+		    parport_device.pattern = bswap_32(parport_device.pattern);
+#endif
+#if ELFCLASSM == ELFCLASS64
+		    parport_device.pattern = bswap_64(parport_device.pattern);
+#endif
+		}
 		if (!parport_device.pattern)
 			break;
 		mod->parport_device = xrealloc(mod->parport_device, ++(mod->n_parport_device)*sizeof(*(mod->parport_device)));
@@ -737,6 +812,13 @@
 	if (!in_range(f, m_size, ref_pnpbios, sizeof(pnpbios_device_size)))
 		return;
 	memcpy(&pnpbios_device_size, (char *)image + ref_pnpbios - f->baseaddr, sizeof(pnpbios_device_size));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		pnpbios_device_size = bswap_32(pnpbios_device_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		pnpbios_device_size = bswap_64(pnpbios_device_size);
+	    }
+	}
 	ref_ref_pnpbios = obj_symbol_final_value(f, obj_find_symbol(f, "__module_pnpbios_device_table"));
 	if (!in_range(f, m_size, ref_ref_pnpbios, sizeof(ref_pnpbios)))
 		return;
@@ -751,6 +833,9 @@
 		memset(&pnpbios_device, 0, sizeof(pnpbios_device));
 		memcpy(&pnpbios_device, (char *)image + ref_pnpbios - f->baseaddr, pnpbios_device_size);
 		ref_pnpbios += pnpbios_device_size;
+		//if (byteswap==1) {
+		    // looks like there is nothing to do here...
+		//}
 		if (!pnpbios_device.id[0])
 			break;
 		mod->pnpbios_device = xrealloc(mod->pnpbios_device, ++(mod->n_pnpbios_device)*sizeof(*(mod->pnpbios_device)));
@@ -772,6 +857,13 @@
 	if (!in_range(f, m_size, ref_ieee1394, sizeof(ieee1394_device_size)))
 		return;
 	memcpy(&ieee1394_device_size, (char *)image + ref_ieee1394 - f->baseaddr, sizeof(ieee1394_device_size));
+	if (byteswap==1) {
+	    if (sizeof(unsigned tgt_long) == 4) {
+		ieee1394_device_size = bswap_32(ieee1394_device_size);
+	    } else if (sizeof(unsigned tgt_long) == 8) {
+		ieee1394_device_size = bswap_64(ieee1394_device_size);
+	    }
+	}
 	ref_ref_ieee1394 = obj_symbol_final_value(f, obj_find_symbol(f, "__module_ieee1394_device_table"));
 	if (!in_range(f, m_size, ref_ref_ieee1394, sizeof(ref_ieee1394)))
 		return;
@@ -786,6 +878,13 @@
 		memset(&ieee1394_device, 0, sizeof(ieee1394_device));
 		memcpy(&ieee1394_device, (char *)image + ref_ieee1394 - f->baseaddr, ieee1394_device_size);
 		ref_ieee1394 += ieee1394_device_size;
+		if (byteswap==1) {
+		    ieee1394_device.match_flags = bswap_32(ieee1394_device.match_flags);
+		    ieee1394_device.vendor_id = bswap_32(ieee1394_device.vendor_id);
+		    ieee1394_device.model_id = bswap_32(ieee1394_device.model_id);
+		    ieee1394_device.specifier_id = bswap_32(ieee1394_device.specifier_id);
+		    ieee1394_device.version = bswap_32(ieee1394_device.version);
+		}
 		if (ieee1394_device.match_flags == 0)
 			break;
 		mod->ieee1394_device = xrealloc(mod->ieee1394_device, ++(mod->n_ieee1394_device)*sizeof(*(mod->ieee1394_device)));
diff -urN modutils-2.4.27.0.orig/include/obj.h modutils-2.4.27.0/include/obj.h
--- modutils-2.4.27.0.orig/include/obj.h	2003-10-26 19:34:46.000000000 -0700
+++ modutils-2.4.27.0/include/obj.h	2005-09-29 17:53:53.000000000 -0600
@@ -28,6 +28,8 @@
 
 #include <stdio.h>
 #include <sys/types.h>
+#include <endian.h>
+#include <byteswap.h>
 #include <elf.h>
 #include ELF_MACHINE_H
 #include "module.h"
@@ -299,4 +301,6 @@
 
 int obj_gpl_license(struct obj_file *, const char **);
 
+extern int byteswap;
+
 #endif /* obj.h */
diff -urN modutils-2.4.27.0.orig/obj/obj_common.c modutils-2.4.27.0/obj/obj_common.c
--- modutils-2.4.27.0.orig/obj/obj_common.c	2002-02-28 17:39:06.000000000 -0700
+++ modutils-2.4.27.0/obj/obj_common.c	2005-09-29 17:53:44.000000000 -0600
@@ -28,6 +28,8 @@
 #include <util.h>
 #include <module.h>
 
+int byteswap;
+
 /*======================================================================*/
 
 /* Standard ELF hash function.  */
diff -urN modutils-2.4.27.0.orig/util/modstat.c modutils-2.4.27.0/util/modstat.c
--- modutils-2.4.27.0.orig/util/modstat.c	2002-11-24 21:01:57.000000000 -0700
+++ modutils-2.4.27.0/util/modstat.c	2005-09-29 14:41:13.000000000 -0600
@@ -408,6 +408,7 @@
 
 int get_kernel_info(int type)
 {
+#if 0
 	k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL);
 
 #ifdef COMPAT_2_0
@@ -416,4 +417,7 @@
 #endif /* COMPAT_2_0 */
 
 	return new_get_kernel_info(type);
+#else
+	return 1;
+#endif
 }
--- modutils-2.4.27/obj/obj_ppc.c.orig	2005-10-24 11:54:44.000000000 -0600
+++ modutils-2.4.27/obj/obj_ppc.c	2005-10-24 11:55:54.000000000 -0600
@@ -20,6 +20,8 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+#include <string.h>
+#include <stdlib.h>
 #include <stddef.h>
 #include <module.h>
 #include <obj.h>
@@ -255,7 +257,9 @@
   archdata_sec->header.sh_size = 0;
   sec = obj_find_section(f, "__ftr_fixup");
   if (sec) {
-    ad = (struct archdata *) (archdata_sec->contents) = xmalloc(sizeof(*ad));
+    struct archdata * ad;
+    archdata_sec->contents = xmalloc(sizeof(*ad));
+    ad = (struct archdata *) (archdata_sec->contents);
     memset(ad, 0, sizeof(*ad));
     archdata_sec->header.sh_size = sizeof(*ad);
     ad->__start___ftr_fixup = sec->header.sh_addr;
--- modutils-2.4.27/obj/obj_load.c.orig	2006-01-10 06:10:37.000000000 -0700
+++ modutils-2.4.27/obj/obj_load.c	2006-01-10 06:10:47.000000000 -0700
@@ -62,13 +62,61 @@
       error("%s is not an ELF file", filename);
       return NULL;
     }
+
+  /* Check if the target endianness matches the host's endianness */
+  byteswap = 0;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  if (f->header.e_ident[5] == ELFDATA2MSB) {
+      /* Ick -- we will have to byte-swap everything */
+      byteswap = 1;
+  }
+#elif __BYTE_ORDER == __BIG_ENDIAN
+  if (f->header.e_ident[5] == ELFDATA2LSB) {
+      byteswap = 1;
+  }
+#else
+#error Unknown host byte order!
+#endif
+  if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+	  f->header.e_type=bswap_16(f->header.e_type);
+	  f->header.e_machine=bswap_16(f->header.e_machine);
+	  f->header.e_version=bswap_32(f->header.e_version);
+	  f->header.e_entry=bswap_32(f->header.e_entry);
+	  f->header.e_phoff=bswap_32(f->header.e_phoff);
+	  f->header.e_shoff=bswap_32(f->header.e_shoff);
+	  f->header.e_flags=bswap_32(f->header.e_flags);
+	  f->header.e_ehsize=bswap_16(f->header.e_ehsize);
+	  f->header.e_phentsize=bswap_16(f->header.e_phentsize);
+	  f->header.e_phnum=bswap_16(f->header.e_phnum);
+	  f->header.e_shentsize=bswap_16(f->header.e_shentsize);
+	  f->header.e_shnum=bswap_16(f->header.e_shnum);
+	  f->header.e_shstrndx=bswap_16(f->header.e_shstrndx);
+#endif
+#if ELFCLASSM == ELFCLASS64
+	  f->header.e_type=bswap_32(f->header.e_type);
+	  f->header.e_machine=bswap_32(f->header.e_machine);
+	  f->header.e_version=bswap_64(f->header.e_version);
+	  f->header.e_entry=bswap_64(f->header.e_entry);
+	  f->header.e_phoff=bswap_64(f->header.e_phoff);
+	  f->header.e_shoff=bswap_64(f->header.e_shoff);
+	  f->header.e_flags=bswap_64(f->header.e_flags);
+	  f->header.e_ehsize=bswap_32(f->header.e_ehsize);
+	  f->header.e_phentsize=bswap_32(f->header.e_phentsize);
+	  f->header.e_phnum=bswap_32(f->header.e_phnum);
+	  f->header.e_shentsize=bswap_32(f->header.e_shentsize);
+	  f->header.e_shnum=bswap_32(f->header.e_shnum);
+	  f->header.e_shstrndx=bswap_32(f->header.e_shstrndx);
+#endif
+  }
+
   if (f->header.e_ident[EI_CLASS] != ELFCLASSM
       || f->header.e_ident[EI_DATA] != ELFDATAM
       || f->header.e_ident[EI_VERSION] != EV_CURRENT
       || !MATCH_MACHINE(f->header.e_machine))
     {
-      error("ELF file %s not for this architecture", filename);
-      return NULL;
+      error("WARNING: ELF file %s not for this architecture", filename);
+      //return NULL;
     }
   if (f->header.e_type != e_type && e_type != ET_NONE)
     {
@@ -116,6 +164,33 @@
     {
       struct obj_section *sec;
 
+      if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+	  section_headers[i].sh_name=bswap_32(section_headers[i].sh_name);
+	  section_headers[i].sh_type=bswap_32(section_headers[i].sh_type);
+	  section_headers[i].sh_flags=bswap_32(section_headers[i].sh_flags);
+	  section_headers[i].sh_addr=bswap_32(section_headers[i].sh_addr);
+	  section_headers[i].sh_offset=bswap_32(section_headers[i].sh_offset);
+	  section_headers[i].sh_size=bswap_32(section_headers[i].sh_size);
+	  section_headers[i].sh_link=bswap_32(section_headers[i].sh_link);
+	  section_headers[i].sh_info=bswap_32(section_headers[i].sh_info);
+	  section_headers[i].sh_addralign=bswap_32(section_headers[i].sh_addralign);
+	  section_headers[i].sh_entsize=bswap_32(section_headers[i].sh_entsize);
+#endif
+#if ELFCLASSM == ELFCLASS64
+	  section_headers[i].sh_name=bswap_64(section_headers[i].sh_name);
+	  section_headers[i].sh_type=bswap_64(section_headers[i].sh_type);
+	  section_headers[i].sh_flags=bswap_64(section_headers[i].sh_flags);
+	  section_headers[i].sh_addr=bswap_64(section_headers[i].sh_addr);
+	  section_headers[i].sh_offset=bswap_64(section_headers[i].sh_offset);
+	  section_headers[i].sh_size=bswap_64(section_headers[i].sh_size);
+	  section_headers[i].sh_link=bswap_64(section_headers[i].sh_link);
+	  section_headers[i].sh_info=bswap_64(section_headers[i].sh_info);
+	  section_headers[i].sh_addralign=bswap_64(section_headers[i].sh_addralign);
+	  section_headers[i].sh_entsize=bswap_64(section_headers[i].sh_entsize);
+#endif
+      }
+
       f->sections[i] = sec = arch_new_section();
       memset(sec, 0, sizeof(*sec));
 
@@ -223,6 +298,20 @@
 	    nsym = sec->header.sh_size / sizeof(ElfW(Sym));
 	    strtab = f->sections[sec->header.sh_link]->contents;
 	    sym = (ElfW(Sym) *) sec->contents;
+	    if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+		sym->st_name = bswap_32(sym->st_name);
+		sym->st_value = bswap_32(sym->st_value);
+		sym->st_size = bswap_32(sym->st_size);
+		sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+#if ELFCLASSM == ELFCLASS64
+		sym->st_name = bswap_64(sym->st_name);
+		sym->st_value = bswap_64(sym->st_value);
+		sym->st_size = bswap_64(sym->st_size);
+		sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+	    }
 
 	    /* Allocate space for a table of local symbols.  */
 	    j = f->local_symtab_size = sec->header.sh_info;
@@ -233,6 +322,22 @@
 	    for (j = 1, ++sym; j < nsym; ++j, ++sym)
 	      {
 		const char *name;
+
+		if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+		    sym->st_name = bswap_32(sym->st_name);
+		    sym->st_value = bswap_32(sym->st_value);
+		    sym->st_size = bswap_32(sym->st_size);
+		    sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+#if ELFCLASSM == ELFCLASS64
+		    sym->st_name = bswap_64(sym->st_name);
+		    sym->st_value = bswap_64(sym->st_value);
+		    sym->st_size = bswap_64(sym->st_size);
+		    sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+		}
+
 		if (sym->st_name)
 		  name = strtab+sym->st_name;
 		else
@@ -298,9 +403,26 @@
 	      {
 		struct obj_symbol *intsym;
 		unsigned long symndx;
+		if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+		    rel->r_offset = bswap_32(rel->r_offset);
+		    rel->r_info = bswap_32(rel->r_info);
+#if Elf32_RelM != Elf32_Rel
+		    rel->r_addend = bswap_32(rel->r_addend);
+#endif
+#endif
+#if ELFCLASSM == ELFCLASS64
+		    rel->r_offset = bswap_64(rel->r_offset);
+		    rel->r_info = bswap_64(rel->r_info);
+#if Elf32_RelM != Elf32_Rel
+		    rel->r_addend = bswap_64(rel->r_addend);
+#endif
+#endif
+		}
 		symndx = ELFW(R_SYM)(rel->r_info);
 		if (symndx)
 		  {
+		    ElfW(Sym) *sym;
 		    if (symndx >= nsyms)
 		      {
 			error("%s: Bad symbol index: %08lx >= %08lx",
@@ -308,7 +430,22 @@
 			continue;
 		      }
 
-		    obj_find_relsym(intsym, f, f, rel, (ElfW(Sym) *)(symtab->contents), strtab);
+		    sym = (ElfW(Sym) *)(symtab->contents);
+		    if (byteswap==1) {
+#if ELFCLASSM == ELFCLASS32
+			sym->st_name = bswap_32(sym->st_name);
+			sym->st_value = bswap_32(sym->st_value);
+			sym->st_size = bswap_32(sym->st_size);
+			sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+#if ELFCLASSM == ELFCLASS64
+			sym->st_name = bswap_64(sym->st_name);
+			sym->st_value = bswap_64(sym->st_value);
+			sym->st_size = bswap_64(sym->st_size);
+			sym->st_shndx = bswap_16(sym->st_shndx);
+#endif
+		    }
+		    obj_find_relsym(intsym, f, f, rel, sym, strtab);
 		    intsym->r_type = ELFW(R_TYPE)(rel->r_info);
 		  }
 	      }
--- modutils-2.4.27/obj/obj_reloc.c.orig	2003-10-26 18:25:08.000000000 -0800
+++ modutils-2.4.27/obj/obj_reloc.c	2006-06-20 17:47:11.000000000 -0700
@@ -331,6 +331,18 @@
 	  value += rel->r_addend;
 #endif
 
+	  /* Byte swap if necessary. For some archs, other adjustments may
+	     need to be done in arch_apply_relocation. */
+	  if (byteswap==1)
+	    {
+	      if (sizeof(unsigned tgt_long) == 4)
+		*(tgt_long *)(targsec->contents + rel->r_offset) =
+		  bswap_32(*(tgt_long *)(targsec->contents + rel->r_offset));
+	      else if (sizeof(unsigned tgt_long) == 8)
+		*(tgt_long *)(targsec->contents + rel->r_offset) =
+		  bswap_64(*(tgt_long *)(targsec->contents + rel->r_offset));
+	    }
+
 	  /* Do it! */
 	  switch (arch_apply_relocation(f,targsec,symsec,intsym,rel,value))
 	    {
--- odutils-2.4.27.0.orig/include/module.h.orig	2006-01-10 08:15:09.000000000 -0700
+++ odutils-2.4.27.0/include/module.h	2006-01-10 08:15:13.000000000 -0700
@@ -88,16 +88,34 @@
 /* For sizeof() which are related to the module platform and not to the
    environment isnmod is running in, use sizeof_xx instead of sizeof(xx).  */
 
-#define tgt_sizeof_char		sizeof(char)
-#define tgt_sizeof_short	sizeof(short)
-#define tgt_sizeof_int		sizeof(int)
-#define tgt_sizeof_long		sizeof(long)
-#define tgt_sizeof_char_p	sizeof(char *)
-#define tgt_sizeof_void_p	sizeof(void *)
-#define tgt_long		long
+#include <stdint.h>
+
+#if ELFCLASSM == ELFCLASS32
+
+#define tgt_sizeof_char		1
+#define tgt_sizeof_short	2
+#define tgt_sizeof_int		4
+#define tgt_sizeof_long		4
+#define tgt_sizeof_char_p	4
+#define tgt_sizeof_void_p	4
+#define tgt_long		int
 #define tgt_long_fmt		"l"
 #define tgt_strtoul		strtoul
 
+#else
+
+#define tgt_sizeof_char		1
+#define tgt_sizeof_short	2
+#define tgt_sizeof_int		4
+#define tgt_sizeof_long		8
+#define tgt_sizeof_char_p	8
+#define tgt_sizeof_void_p	8
+#define tgt_long		long
+#define tgt_long_fmt		"ll"
+#define tgt_strtoul		strtoull
+
+#endif
+
 /* This assumes that long long on a 32 bit system is equivalent to long on the
  * equivalent 64 bit system.  Also that void and char pointers are 8 bytes on
  * all 64 bit systems.  Add per system tweaks if it ever becomes necessary.
OpenPOWER on IntegriCloud