kumquat-buildroot/package/modutils/modutils-cross.patch
2006-03-22 18:25:51 +00:00

528 lines
20 KiB
Diff

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);
}
}
--- 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.