modutils-cross.patch 21 KB

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