Commit 3442e8964e7ed6a79cf22e82232e4341a1805d82
1 parent
e89f07d3
64-bit host/cross fixes.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1742 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
58 additions
and
52 deletions
dyngen.c
| @@ -1679,7 +1679,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1679,7 +1679,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1679 | #endif | 1679 | #endif |
| 1680 | if (val >= start_offset && val <= start_offset + copy_size) { | 1680 | if (val >= start_offset && val <= start_offset + copy_size) { |
| 1681 | n = strtol(p, NULL, 10); | 1681 | n = strtol(p, NULL, 10); |
| 1682 | - fprintf(outfile, " label_offsets[%d] = %ld + (gen_code_ptr - gen_code_buf);\n", n, val - start_offset); | 1682 | + fprintf(outfile, " label_offsets[%d] = %ld + (gen_code_ptr - gen_code_buf);\n", n, (long)(val - start_offset)); |
| 1683 | } | 1683 | } |
| 1684 | } | 1684 | } |
| 1685 | } | 1685 | } |
| @@ -1696,12 +1696,14 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1696,12 +1696,14 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1696 | char name[256]; | 1696 | char name[256]; |
| 1697 | int type; | 1697 | int type; |
| 1698 | int addend; | 1698 | int addend; |
| 1699 | + int reloc_offset; | ||
| 1699 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 1700 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 1700 | if (rel->r_offset >= start_offset && | 1701 | if (rel->r_offset >= start_offset && |
| 1701 | rel->r_offset < start_offset + copy_size) { | 1702 | rel->r_offset < start_offset + copy_size) { |
| 1702 | sym_name = get_rel_sym_name(rel); | 1703 | sym_name = get_rel_sym_name(rel); |
| 1703 | if (!sym_name) | 1704 | if (!sym_name) |
| 1704 | continue; | 1705 | continue; |
| 1706 | + reloc_offset = rel->r_offset - start_offset; | ||
| 1705 | if (strstart(sym_name, "__op_jmp", &p)) { | 1707 | if (strstart(sym_name, "__op_jmp", &p)) { |
| 1706 | int n; | 1708 | int n; |
| 1707 | n = strtol(p, NULL, 10); | 1709 | n = strtol(p, NULL, 10); |
| @@ -1710,10 +1712,10 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1710,10 +1712,10 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1710 | chaining: the offset of the instruction | 1712 | chaining: the offset of the instruction |
| 1711 | needs to be stored */ | 1713 | needs to be stored */ |
| 1712 | fprintf(outfile, " jmp_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", | 1714 | fprintf(outfile, " jmp_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", |
| 1713 | - n, rel->r_offset - start_offset); | 1715 | + n, reloc_offset); |
| 1714 | continue; | 1716 | continue; |
| 1715 | } | 1717 | } |
| 1716 | - | 1718 | + |
| 1717 | get_reloc_expr(name, sizeof(name), sym_name); | 1719 | get_reloc_expr(name, sizeof(name), sym_name); |
| 1718 | addend = get32((uint32_t *)(text + rel->r_offset)); | 1720 | addend = get32((uint32_t *)(text + rel->r_offset)); |
| 1719 | #ifdef CONFIG_FORMAT_ELF | 1721 | #ifdef CONFIG_FORMAT_ELF |
| @@ -1721,11 +1723,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1721,11 +1723,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1721 | switch(type) { | 1723 | switch(type) { |
| 1722 | case R_386_32: | 1724 | case R_386_32: |
| 1723 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1725 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1724 | - rel->r_offset - start_offset, name, addend); | 1726 | + reloc_offset, name, addend); |
| 1725 | break; | 1727 | break; |
| 1726 | case R_386_PC32: | 1728 | case R_386_PC32: |
| 1727 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n", | 1729 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n", |
| 1728 | - rel->r_offset - start_offset, name, rel->r_offset - start_offset, addend); | 1730 | + reloc_offset, name, reloc_offset, addend); |
| 1729 | break; | 1731 | break; |
| 1730 | default: | 1732 | default: |
| 1731 | error("unsupported i386 relocation (%d)", type); | 1733 | error("unsupported i386 relocation (%d)", type); |
| @@ -1748,11 +1750,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1748,11 +1750,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1748 | switch(type) { | 1750 | switch(type) { |
| 1749 | case DIR32: | 1751 | case DIR32: |
| 1750 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1752 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1751 | - rel->r_offset - start_offset, name, addend); | 1753 | + reloc_offset, name, addend); |
| 1752 | break; | 1754 | break; |
| 1753 | case DISP32: | 1755 | case DISP32: |
| 1754 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d -4;\n", | 1756 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d -4;\n", |
| 1755 | - rel->r_offset - start_offset, name, rel->r_offset - start_offset, addend); | 1757 | + reloc_offset, name, reloc_offset, addend); |
| 1756 | break; | 1758 | break; |
| 1757 | default: | 1759 | default: |
| 1758 | error("unsupported i386 relocation (%d)", type); | 1760 | error("unsupported i386 relocation (%d)", type); |
| @@ -1768,6 +1770,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1768,6 +1770,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1768 | char name[256]; | 1770 | char name[256]; |
| 1769 | int type; | 1771 | int type; |
| 1770 | int addend; | 1772 | int addend; |
| 1773 | + int reloc_offset; | ||
| 1771 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 1774 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 1772 | if (rel->r_offset >= start_offset && | 1775 | if (rel->r_offset >= start_offset && |
| 1773 | rel->r_offset < start_offset + copy_size) { | 1776 | rel->r_offset < start_offset + copy_size) { |
| @@ -1775,18 +1778,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1775,18 +1778,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1775 | get_reloc_expr(name, sizeof(name), sym_name); | 1778 | get_reloc_expr(name, sizeof(name), sym_name); |
| 1776 | type = ELF32_R_TYPE(rel->r_info); | 1779 | type = ELF32_R_TYPE(rel->r_info); |
| 1777 | addend = rel->r_addend; | 1780 | addend = rel->r_addend; |
| 1781 | + reloc_offset = rel->r_offset - start_offset; | ||
| 1778 | switch(type) { | 1782 | switch(type) { |
| 1779 | case R_X86_64_32: | 1783 | case R_X86_64_32: |
| 1780 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (uint32_t)%s + %d;\n", | 1784 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (uint32_t)%s + %d;\n", |
| 1781 | - rel->r_offset - start_offset, name, addend); | 1785 | + reloc_offset, name, addend); |
| 1782 | break; | 1786 | break; |
| 1783 | case R_X86_64_32S: | 1787 | case R_X86_64_32S: |
| 1784 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (int32_t)%s + %d;\n", | 1788 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (int32_t)%s + %d;\n", |
| 1785 | - rel->r_offset - start_offset, name, addend); | 1789 | + reloc_offset, name, addend); |
| 1786 | break; | 1790 | break; |
| 1787 | case R_X86_64_PC32: | 1791 | case R_X86_64_PC32: |
| 1788 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n", | 1792 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n", |
| 1789 | - rel->r_offset - start_offset, name, rel->r_offset - start_offset, addend); | 1793 | + reloc_offset, name, reloc_offset, addend); |
| 1790 | break; | 1794 | break; |
| 1791 | default: | 1795 | default: |
| 1792 | error("unsupported X86_64 relocation (%d)", type); | 1796 | error("unsupported X86_64 relocation (%d)", type); |
| @@ -1800,10 +1804,12 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1800,10 +1804,12 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1800 | char name[256]; | 1804 | char name[256]; |
| 1801 | int type; | 1805 | int type; |
| 1802 | int addend; | 1806 | int addend; |
| 1807 | + int reloc_offset; | ||
| 1803 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 1808 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 1804 | if (rel->r_offset >= start_offset && | 1809 | if (rel->r_offset >= start_offset && |
| 1805 | rel->r_offset < start_offset + copy_size) { | 1810 | rel->r_offset < start_offset + copy_size) { |
| 1806 | sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | 1811 | sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; |
| 1812 | + reloc_offset = rel->r_offset - start_offset; | ||
| 1807 | if (strstart(sym_name, "__op_jmp", &p)) { | 1813 | if (strstart(sym_name, "__op_jmp", &p)) { |
| 1808 | int n; | 1814 | int n; |
| 1809 | n = strtol(p, NULL, 10); | 1815 | n = strtol(p, NULL, 10); |
| @@ -1812,7 +1818,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1812,7 +1818,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1812 | chaining: the offset of the instruction | 1818 | chaining: the offset of the instruction |
| 1813 | needs to be stored */ | 1819 | needs to be stored */ |
| 1814 | fprintf(outfile, " jmp_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", | 1820 | fprintf(outfile, " jmp_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", |
| 1815 | - n, rel->r_offset - start_offset); | 1821 | + n, reloc_offset); |
| 1816 | continue; | 1822 | continue; |
| 1817 | } | 1823 | } |
| 1818 | 1824 | ||
| @@ -1822,24 +1828,24 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1822,24 +1828,24 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1822 | switch(type) { | 1828 | switch(type) { |
| 1823 | case R_PPC_ADDR32: | 1829 | case R_PPC_ADDR32: |
| 1824 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1830 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1825 | - rel->r_offset - start_offset, name, addend); | 1831 | + reloc_offset, name, addend); |
| 1826 | break; | 1832 | break; |
| 1827 | case R_PPC_ADDR16_LO: | 1833 | case R_PPC_ADDR16_LO: |
| 1828 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d);\n", | 1834 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d);\n", |
| 1829 | - rel->r_offset - start_offset, name, addend); | 1835 | + reloc_offset, name, addend); |
| 1830 | break; | 1836 | break; |
| 1831 | case R_PPC_ADDR16_HI: | 1837 | case R_PPC_ADDR16_HI: |
| 1832 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d) >> 16;\n", | 1838 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d) >> 16;\n", |
| 1833 | - rel->r_offset - start_offset, name, addend); | 1839 | + reloc_offset, name, addend); |
| 1834 | break; | 1840 | break; |
| 1835 | case R_PPC_ADDR16_HA: | 1841 | case R_PPC_ADDR16_HA: |
| 1836 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d + 0x8000) >> 16;\n", | 1842 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d + 0x8000) >> 16;\n", |
| 1837 | - rel->r_offset - start_offset, name, addend); | 1843 | + reloc_offset, name, addend); |
| 1838 | break; | 1844 | break; |
| 1839 | case R_PPC_REL24: | 1845 | case R_PPC_REL24: |
| 1840 | /* warning: must be at 32 MB distancy */ | 1846 | /* warning: must be at 32 MB distancy */ |
| 1841 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((%s - (long)(gen_code_ptr + %d) + %d) & 0x03fffffc);\n", | 1847 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((%s - (long)(gen_code_ptr + %d) + %d) & 0x03fffffc);\n", |
| 1842 | - rel->r_offset - start_offset, rel->r_offset - start_offset, name, rel->r_offset - start_offset, addend); | 1848 | + reloc_offset, reloc_offset, name, reloc_offset, addend); |
| 1843 | break; | 1849 | break; |
| 1844 | default: | 1850 | default: |
| 1845 | error("unsupported powerpc relocation (%d)", type); | 1851 | error("unsupported powerpc relocation (%d)", type); |
| @@ -1941,6 +1947,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1941,6 +1947,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1941 | char name[256]; | 1947 | char name[256]; |
| 1942 | int type; | 1948 | int type; |
| 1943 | int addend; | 1949 | int addend; |
| 1950 | + int reloc_offset; | ||
| 1944 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 1951 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 1945 | if (rel->r_offset >= start_offset && | 1952 | if (rel->r_offset >= start_offset && |
| 1946 | rel->r_offset < start_offset + copy_size) { | 1953 | rel->r_offset < start_offset + copy_size) { |
| @@ -1948,18 +1955,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1948,18 +1955,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1948 | get_reloc_expr(name, sizeof(name), sym_name); | 1955 | get_reloc_expr(name, sizeof(name), sym_name); |
| 1949 | type = ELF32_R_TYPE(rel->r_info); | 1956 | type = ELF32_R_TYPE(rel->r_info); |
| 1950 | addend = rel->r_addend; | 1957 | addend = rel->r_addend; |
| 1958 | + reloc_offset = rel->r_offset - start_offset; | ||
| 1951 | switch(type) { | 1959 | switch(type) { |
| 1952 | case R_390_32: | 1960 | case R_390_32: |
| 1953 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1961 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1954 | - rel->r_offset - start_offset, name, addend); | 1962 | + reloc_offset, name, addend); |
| 1955 | break; | 1963 | break; |
| 1956 | case R_390_16: | 1964 | case R_390_16: |
| 1957 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1965 | fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1958 | - rel->r_offset - start_offset, name, addend); | 1966 | + reloc_offset, name, addend); |
| 1959 | break; | 1967 | break; |
| 1960 | case R_390_8: | 1968 | case R_390_8: |
| 1961 | fprintf(outfile, " *(uint8_t *)(gen_code_ptr + %d) = %s + %d;\n", | 1969 | fprintf(outfile, " *(uint8_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 1962 | - rel->r_offset - start_offset, name, addend); | 1970 | + reloc_offset, name, addend); |
| 1963 | break; | 1971 | break; |
| 1964 | default: | 1972 | default: |
| 1965 | error("unsupported s390 relocation (%d)", type); | 1973 | error("unsupported s390 relocation (%d)", type); |
| @@ -1972,17 +1980,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -1972,17 +1980,19 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 1972 | for (i = 0, rel = relocs; i < nb_relocs; i++, rel++) { | 1980 | for (i = 0, rel = relocs; i < nb_relocs; i++, rel++) { |
| 1973 | if (rel->r_offset >= start_offset && rel->r_offset < start_offset + copy_size) { | 1981 | if (rel->r_offset >= start_offset && rel->r_offset < start_offset + copy_size) { |
| 1974 | int type; | 1982 | int type; |
| 1983 | + long reloc_offset; | ||
| 1975 | 1984 | ||
| 1976 | type = ELF64_R_TYPE(rel->r_info); | 1985 | type = ELF64_R_TYPE(rel->r_info); |
| 1977 | sym_name = strtab + symtab[ELF64_R_SYM(rel->r_info)].st_name; | 1986 | sym_name = strtab + symtab[ELF64_R_SYM(rel->r_info)].st_name; |
| 1987 | + reloc_offset = rel->r_offset - start_offset; | ||
| 1978 | switch (type) { | 1988 | switch (type) { |
| 1979 | case R_ALPHA_GPDISP: | 1989 | case R_ALPHA_GPDISP: |
| 1980 | /* The gp is just 32 bit, and never changes, so it's easiest to emit it | 1990 | /* The gp is just 32 bit, and never changes, so it's easiest to emit it |
| 1981 | as an immediate instead of constructing it from the pv or ra. */ | 1991 | as an immediate instead of constructing it from the pv or ra. */ |
| 1982 | fprintf(outfile, " immediate_ldah(gen_code_ptr + %ld, gp);\n", | 1992 | fprintf(outfile, " immediate_ldah(gen_code_ptr + %ld, gp);\n", |
| 1983 | - rel->r_offset - start_offset); | 1993 | + reloc_offset); |
| 1984 | fprintf(outfile, " immediate_lda(gen_code_ptr + %ld, gp);\n", | 1994 | fprintf(outfile, " immediate_lda(gen_code_ptr + %ld, gp);\n", |
| 1985 | - rel->r_offset - start_offset + rel->r_addend); | 1995 | + reloc_offset + (int)rel->r_addend); |
| 1986 | break; | 1996 | break; |
| 1987 | case R_ALPHA_LITUSE: | 1997 | case R_ALPHA_LITUSE: |
| 1988 | /* jsr to literal hint. Could be used to optimize to bsr. Ignore for | 1998 | /* jsr to literal hint. Could be used to optimize to bsr. Ignore for |
| @@ -2002,18 +2012,18 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2002,18 +2012,18 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2002 | special treatment. */ | 2012 | special treatment. */ |
| 2003 | if (strstart(sym_name, "__op_param", &p)) | 2013 | if (strstart(sym_name, "__op_param", &p)) |
| 2004 | fprintf(outfile, " immediate_ldah(gen_code_ptr + %ld, param%s);\n", | 2014 | fprintf(outfile, " immediate_ldah(gen_code_ptr + %ld, param%s);\n", |
| 2005 | - rel->r_offset - start_offset, p); | 2015 | + reloc_offset, p); |
| 2006 | break; | 2016 | break; |
| 2007 | case R_ALPHA_GPRELLOW: | 2017 | case R_ALPHA_GPRELLOW: |
| 2008 | if (strstart(sym_name, "__op_param", &p)) | 2018 | if (strstart(sym_name, "__op_param", &p)) |
| 2009 | fprintf(outfile, " immediate_lda(gen_code_ptr + %ld, param%s);\n", | 2019 | fprintf(outfile, " immediate_lda(gen_code_ptr + %ld, param%s);\n", |
| 2010 | - rel->r_offset - start_offset, p); | 2020 | + reloc_offset, p); |
| 2011 | break; | 2021 | break; |
| 2012 | case R_ALPHA_BRSGP: | 2022 | case R_ALPHA_BRSGP: |
| 2013 | /* PC-relative jump. Tweak offset to skip the two instructions that try to | 2023 | /* PC-relative jump. Tweak offset to skip the two instructions that try to |
| 2014 | set up the gp from the pv. */ | 2024 | set up the gp from the pv. */ |
| 2015 | fprintf(outfile, " fix_bsr(gen_code_ptr + %ld, (uint8_t *) &%s - (gen_code_ptr + %ld + 4) + 8);\n", | 2025 | fprintf(outfile, " fix_bsr(gen_code_ptr + %ld, (uint8_t *) &%s - (gen_code_ptr + %ld + 4) + 8);\n", |
| 2016 | - rel->r_offset - start_offset, sym_name, rel->r_offset - start_offset); | 2026 | + reloc_offset, sym_name, reloc_offset); |
| 2017 | break; | 2027 | break; |
| 2018 | default: | 2028 | default: |
| 2019 | error("unsupported Alpha relocation (%d)", type); | 2029 | error("unsupported Alpha relocation (%d)", type); |
| @@ -2035,6 +2045,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2035,6 +2045,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2035 | || rel->r_offset >= start_offset + copy_size) | 2045 | || rel->r_offset >= start_offset + copy_size) |
| 2036 | continue; | 2046 | continue; |
| 2037 | sym_name = (strtab + symtab[sym_idx].st_name); | 2047 | sym_name = (strtab + symtab[sym_idx].st_name); |
| 2048 | + code_offset = rel->r_offset - start_offset; | ||
| 2038 | if (strstart(sym_name, "__op_jmp", &p)) { | 2049 | if (strstart(sym_name, "__op_jmp", &p)) { |
| 2039 | int n; | 2050 | int n; |
| 2040 | n = strtol(p, NULL, 10); | 2051 | n = strtol(p, NULL, 10); |
| @@ -2044,13 +2055,12 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2044,13 +2055,12 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2044 | needs to be stored */ | 2055 | needs to be stored */ |
| 2045 | fprintf(outfile, " jmp_offsets[%d] =" | 2056 | fprintf(outfile, " jmp_offsets[%d] =" |
| 2046 | "%ld + (gen_code_ptr - gen_code_buf);\n", | 2057 | "%ld + (gen_code_ptr - gen_code_buf);\n", |
| 2047 | - n, rel->r_offset - start_offset); | 2058 | + n, code_offset); |
| 2048 | continue; | 2059 | continue; |
| 2049 | } | 2060 | } |
| 2050 | get_reloc_expr(name, sizeof(name), sym_name); | 2061 | get_reloc_expr(name, sizeof(name), sym_name); |
| 2051 | type = ELF64_R_TYPE(rel->r_info); | 2062 | type = ELF64_R_TYPE(rel->r_info); |
| 2052 | addend = rel->r_addend; | 2063 | addend = rel->r_addend; |
| 2053 | - code_offset = rel->r_offset - start_offset; | ||
| 2054 | switch(type) { | 2064 | switch(type) { |
| 2055 | case R_IA64_IMM64: | 2065 | case R_IA64_IMM64: |
| 2056 | fprintf(outfile, | 2066 | fprintf(outfile, |
| @@ -2101,6 +2111,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2101,6 +2111,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2101 | char name[256]; | 2111 | char name[256]; |
| 2102 | int type; | 2112 | int type; |
| 2103 | int addend; | 2113 | int addend; |
| 2114 | + int reloc_offset; | ||
| 2104 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 2115 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 2105 | if (rel->r_offset >= start_offset && | 2116 | if (rel->r_offset >= start_offset && |
| 2106 | rel->r_offset < start_offset + copy_size) { | 2117 | rel->r_offset < start_offset + copy_size) { |
| @@ -2108,10 +2119,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2108,10 +2119,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2108 | get_reloc_expr(name, sizeof(name), sym_name); | 2119 | get_reloc_expr(name, sizeof(name), sym_name); |
| 2109 | type = ELF32_R_TYPE(rel->r_info); | 2120 | type = ELF32_R_TYPE(rel->r_info); |
| 2110 | addend = rel->r_addend; | 2121 | addend = rel->r_addend; |
| 2122 | + reloc_offset = rel->r_offset - start_offset; | ||
| 2111 | switch(type) { | 2123 | switch(type) { |
| 2112 | case R_SPARC_32: | 2124 | case R_SPARC_32: |
| 2113 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 2125 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 2114 | - rel->r_offset - start_offset, name, addend); | 2126 | + reloc_offset, name, addend); |
| 2115 | break; | 2127 | break; |
| 2116 | case R_SPARC_HI22: | 2128 | case R_SPARC_HI22: |
| 2117 | fprintf(outfile, | 2129 | fprintf(outfile, |
| @@ -2119,9 +2131,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2119,9 +2131,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2119 | "((*(uint32_t *)(gen_code_ptr + %d)) " | 2131 | "((*(uint32_t *)(gen_code_ptr + %d)) " |
| 2120 | " & ~0x3fffff) " | 2132 | " & ~0x3fffff) " |
| 2121 | " | (((%s + %d) >> 10) & 0x3fffff);\n", | 2133 | " | (((%s + %d) >> 10) & 0x3fffff);\n", |
| 2122 | - rel->r_offset - start_offset, | ||
| 2123 | - rel->r_offset - start_offset, | ||
| 2124 | - name, addend); | 2134 | + reloc_offset, reloc_offset, name, addend); |
| 2125 | break; | 2135 | break; |
| 2126 | case R_SPARC_LO10: | 2136 | case R_SPARC_LO10: |
| 2127 | fprintf(outfile, | 2137 | fprintf(outfile, |
| @@ -2129,9 +2139,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2129,9 +2139,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2129 | "((*(uint32_t *)(gen_code_ptr + %d)) " | 2139 | "((*(uint32_t *)(gen_code_ptr + %d)) " |
| 2130 | " & ~0x3ff) " | 2140 | " & ~0x3ff) " |
| 2131 | " | ((%s + %d) & 0x3ff);\n", | 2141 | " | ((%s + %d) & 0x3ff);\n", |
| 2132 | - rel->r_offset - start_offset, | ||
| 2133 | - rel->r_offset - start_offset, | ||
| 2134 | - name, addend); | 2142 | + reloc_offset, reloc_offset, name, addend); |
| 2135 | break; | 2143 | break; |
| 2136 | case R_SPARC_WDISP30: | 2144 | case R_SPARC_WDISP30: |
| 2137 | fprintf(outfile, | 2145 | fprintf(outfile, |
| @@ -2140,10 +2148,8 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2140,10 +2148,8 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2140 | " & ~0x3fffffff) " | 2148 | " & ~0x3fffffff) " |
| 2141 | " | ((((%s + %d) - (long)(gen_code_ptr + %d))>>2) " | 2149 | " | ((((%s + %d) - (long)(gen_code_ptr + %d))>>2) " |
| 2142 | " & 0x3fffffff);\n", | 2150 | " & 0x3fffffff);\n", |
| 2143 | - rel->r_offset - start_offset, | ||
| 2144 | - rel->r_offset - start_offset, | ||
| 2145 | - name, addend, | ||
| 2146 | - rel->r_offset - start_offset); | 2151 | + reloc_offset, reloc_offset, name, addend, |
| 2152 | + reloc_offset); | ||
| 2147 | break; | 2153 | break; |
| 2148 | default: | 2154 | default: |
| 2149 | error("unsupported sparc relocation (%d)", type); | 2155 | error("unsupported sparc relocation (%d)", type); |
| @@ -2156,6 +2162,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2156,6 +2162,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2156 | char name[256]; | 2162 | char name[256]; |
| 2157 | int type; | 2163 | int type; |
| 2158 | int addend; | 2164 | int addend; |
| 2165 | + int reloc_offset; | ||
| 2159 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 2166 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 2160 | if (rel->r_offset >= start_offset && | 2167 | if (rel->r_offset >= start_offset && |
| 2161 | rel->r_offset < start_offset + copy_size) { | 2168 | rel->r_offset < start_offset + copy_size) { |
| @@ -2163,10 +2170,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2163,10 +2170,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2163 | get_reloc_expr(name, sizeof(name), sym_name); | 2170 | get_reloc_expr(name, sizeof(name), sym_name); |
| 2164 | type = ELF64_R_TYPE(rel->r_info); | 2171 | type = ELF64_R_TYPE(rel->r_info); |
| 2165 | addend = rel->r_addend; | 2172 | addend = rel->r_addend; |
| 2173 | + reloc_offset = rel->r_offset - start_offset; | ||
| 2166 | switch(type) { | 2174 | switch(type) { |
| 2167 | case R_SPARC_32: | 2175 | case R_SPARC_32: |
| 2168 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 2176 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 2169 | - rel->r_offset - start_offset, name, addend); | 2177 | + reloc_offset, name, addend); |
| 2170 | break; | 2178 | break; |
| 2171 | case R_SPARC_HI22: | 2179 | case R_SPARC_HI22: |
| 2172 | fprintf(outfile, | 2180 | fprintf(outfile, |
| @@ -2174,9 +2182,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2174,9 +2182,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2174 | "((*(uint32_t *)(gen_code_ptr + %d)) " | 2182 | "((*(uint32_t *)(gen_code_ptr + %d)) " |
| 2175 | " & ~0x3fffff) " | 2183 | " & ~0x3fffff) " |
| 2176 | " | (((%s + %d) >> 10) & 0x3fffff);\n", | 2184 | " | (((%s + %d) >> 10) & 0x3fffff);\n", |
| 2177 | - rel->r_offset - start_offset, | ||
| 2178 | - rel->r_offset - start_offset, | ||
| 2179 | - name, addend); | 2185 | + reloc_offset, reloc_offset, name, addend); |
| 2180 | break; | 2186 | break; |
| 2181 | case R_SPARC_LO10: | 2187 | case R_SPARC_LO10: |
| 2182 | fprintf(outfile, | 2188 | fprintf(outfile, |
| @@ -2184,9 +2190,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2184,9 +2190,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2184 | "((*(uint32_t *)(gen_code_ptr + %d)) " | 2190 | "((*(uint32_t *)(gen_code_ptr + %d)) " |
| 2185 | " & ~0x3ff) " | 2191 | " & ~0x3ff) " |
| 2186 | " | ((%s + %d) & 0x3ff);\n", | 2192 | " | ((%s + %d) & 0x3ff);\n", |
| 2187 | - rel->r_offset - start_offset, | ||
| 2188 | - rel->r_offset - start_offset, | ||
| 2189 | - name, addend); | 2193 | + reloc_offset, reloc_offset, name, addend); |
| 2190 | break; | 2194 | break; |
| 2191 | case R_SPARC_WDISP30: | 2195 | case R_SPARC_WDISP30: |
| 2192 | fprintf(outfile, | 2196 | fprintf(outfile, |
| @@ -2195,10 +2199,8 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2195,10 +2199,8 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2195 | " & ~0x3fffffff) " | 2199 | " & ~0x3fffffff) " |
| 2196 | " | ((((%s + %d) - (long)(gen_code_ptr + %d))>>2) " | 2200 | " | ((((%s + %d) - (long)(gen_code_ptr + %d))>>2) " |
| 2197 | " & 0x3fffffff);\n", | 2201 | " & 0x3fffffff);\n", |
| 2198 | - rel->r_offset - start_offset, | ||
| 2199 | - rel->r_offset - start_offset, | ||
| 2200 | - name, addend, | ||
| 2201 | - rel->r_offset - start_offset); | 2202 | + reloc_offset, reloc_offset, name, addend, |
| 2203 | + reloc_offset); | ||
| 2202 | break; | 2204 | break; |
| 2203 | default: | 2205 | default: |
| 2204 | error("unsupported sparc64 relocation (%d)", type); | 2206 | error("unsupported sparc64 relocation (%d)", type); |
| @@ -2211,6 +2213,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2211,6 +2213,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2211 | char name[256]; | 2213 | char name[256]; |
| 2212 | int type; | 2214 | int type; |
| 2213 | int addend; | 2215 | int addend; |
| 2216 | + int reloc_offset; | ||
| 2214 | 2217 | ||
| 2215 | arm_emit_ldr_info(name, start_offset, outfile, p_start, p_end, | 2218 | arm_emit_ldr_info(name, start_offset, outfile, p_start, p_end, |
| 2216 | relocs, nb_relocs); | 2219 | relocs, nb_relocs); |
| @@ -2225,14 +2228,15 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2225,14 +2228,15 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2225 | get_reloc_expr(name, sizeof(name), sym_name); | 2228 | get_reloc_expr(name, sizeof(name), sym_name); |
| 2226 | type = ELF32_R_TYPE(rel->r_info); | 2229 | type = ELF32_R_TYPE(rel->r_info); |
| 2227 | addend = get32((uint32_t *)(text + rel->r_offset)); | 2230 | addend = get32((uint32_t *)(text + rel->r_offset)); |
| 2231 | + reloc_offset = rel->r_offset - start_offset; | ||
| 2228 | switch(type) { | 2232 | switch(type) { |
| 2229 | case R_ARM_ABS32: | 2233 | case R_ARM_ABS32: |
| 2230 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | 2234 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
| 2231 | - rel->r_offset - start_offset, name, addend); | 2235 | + reloc_offset, name, addend); |
| 2232 | break; | 2236 | break; |
| 2233 | case R_ARM_PC24: | 2237 | case R_ARM_PC24: |
| 2234 | fprintf(outfile, " arm_reloc_pc24((uint32_t *)(gen_code_ptr + %d), 0x%x, %s);\n", | 2238 | fprintf(outfile, " arm_reloc_pc24((uint32_t *)(gen_code_ptr + %d), 0x%x, %s);\n", |
| 2235 | - rel->r_offset - start_offset, addend, name); | 2239 | + reloc_offset, addend, name); |
| 2236 | break; | 2240 | break; |
| 2237 | default: | 2241 | default: |
| 2238 | error("unsupported arm relocation (%d)", type); | 2242 | error("unsupported arm relocation (%d)", type); |
| @@ -2245,6 +2249,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2245,6 +2249,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2245 | char name[256]; | 2249 | char name[256]; |
| 2246 | int type; | 2250 | int type; |
| 2247 | int addend; | 2251 | int addend; |
| 2252 | + int reloc_offset; | ||
| 2248 | Elf32_Sym *sym; | 2253 | Elf32_Sym *sym; |
| 2249 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { | 2254 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
| 2250 | if (rel->r_offset >= start_offset && | 2255 | if (rel->r_offset >= start_offset && |
| @@ -2254,16 +2259,17 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -2254,16 +2259,17 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
| 2254 | get_reloc_expr(name, sizeof(name), sym_name); | 2259 | get_reloc_expr(name, sizeof(name), sym_name); |
| 2255 | type = ELF32_R_TYPE(rel->r_info); | 2260 | type = ELF32_R_TYPE(rel->r_info); |
| 2256 | addend = get32((uint32_t *)(text + rel->r_offset)) + rel->r_addend; | 2261 | addend = get32((uint32_t *)(text + rel->r_offset)) + rel->r_addend; |
| 2262 | + reloc_offset = rel->r_offset - start_offset; | ||
| 2257 | switch(type) { | 2263 | switch(type) { |
| 2258 | case R_68K_32: | 2264 | case R_68K_32: |
| 2259 | fprintf(outfile, " /* R_68K_32 RELOC, offset %x */\n", rel->r_offset) ; | 2265 | fprintf(outfile, " /* R_68K_32 RELOC, offset %x */\n", rel->r_offset) ; |
| 2260 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %#x;\n", | 2266 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %#x;\n", |
| 2261 | - rel->r_offset - start_offset, name, addend ); | 2267 | + reloc_offset, name, addend ); |
| 2262 | break; | 2268 | break; |
| 2263 | case R_68K_PC32: | 2269 | case R_68K_PC32: |
| 2264 | fprintf(outfile, " /* R_68K_PC32 RELOC, offset %x */\n", rel->r_offset); | 2270 | fprintf(outfile, " /* R_68K_PC32 RELOC, offset %x */\n", rel->r_offset); |
| 2265 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %#x) + %#x;\n", | 2271 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %#x) + %#x;\n", |
| 2266 | - rel->r_offset - start_offset, name, rel->r_offset - start_offset, /*sym->st_value+*/ addend); | 2272 | + reloc_offset, name, reloc_offset, /*sym->st_value+*/ addend); |
| 2267 | break; | 2273 | break; |
| 2268 | default: | 2274 | default: |
| 2269 | error("unsupported m68k relocation (%d)", type); | 2275 | error("unsupported m68k relocation (%d)", type); |