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