Unified · Split
| @@ -822,27 +822,33 @@ void gen_cvt_ftof(int t) · 821 unmodified lines | |||
| 822 | /* generate a bounded pointer addition */ | 822 | /* generate a bounded pointer addition */ |
| 823 | void gen_bounded_ptr_add(void) | 823 | void gen_bounded_ptr_add(void) |
| 824 | { | 824 | { |
| 825 | int addr; | 825 | Sym *sym; |
| 826 | |||
| 826 | /* prepare fast i386 function call (args in eax and edx) */ | 827 | /* prepare fast i386 function call (args in eax and edx) */ |
| 827 | gv2(RC_EAX, RC_EDX); | 828 | gv2(RC_EAX, RC_EDX); |
| 828 | /* save all temporary registers */ | 829 | /* save all temporary registers */ |
| 829 | vtop -= 2; | 830 | vtop -= 2; |
| 830 | save_regs(0); | 831 | save_regs(0); |
| 831 | /* do a fast function call */ | 832 | /* do a fast function call */ |
| 832 | addr = ind; | 833 | sym = external_sym(TOK___bound_ptr_add, func_old_type, 0); |
| 833 | oad(0xe8, (int)__bound_ptr_add - ind - 5); | 834 | greloc(cur_text_section, sym, |
| 835 | ind + 1 - (int)cur_text_section->data, R_386_PC32); | ||
| 836 | oad(0xe8, -4); | ||
| 834 | /* returned pointer is in eax */ | 837 | /* returned pointer is in eax */ |
| 835 | vtop++; | 838 | vtop++; |
| 836 | vtop->r = REG_EAX | VT_BOUNDED; | 839 | vtop->r = REG_EAX | VT_BOUNDED; |
| 837 | vtop->c.ul = addr; /* address of bounding function call point */ | 840 | /* address of bounding function call point */ |
| 841 | vtop->c.ptr = (cur_text_section->reloc->data_ptr - sizeof(Elf32_Rel)); | ||
| 838 | } | 842 | } |
| 839 | 843 | ||
| 840 | /* patch pointer addition in vtop so that pointer dereferencing is | 844 | /* patch pointer addition in vtop so that pointer dereferencing is |
| 841 | also tested */ | 845 | also tested */ |
| 842 | void gen_bounded_ptr_deref(void) | 846 | void gen_bounded_ptr_deref(void) |
| 843 | { | 847 | { |
| 844 | void *func; | 848 | int func; |
| 845 | int size, align, addr; | 849 | int size, align; |
| 850 | Elf32_Rel *rel; | ||
| 851 | Sym *sym; | ||
| 846 | 852 | ||
| 847 | size = 0; | 853 | size = 0; |
| 848 | /* XXX: put that code in generic part of tcc */ | 854 | /* XXX: put that code in generic part of tcc */ |
| @@ -855,20 +861,25 @@ void gen_bounded_ptr_deref(void) · 6 unmodified lines | |||
| 855 | if (!size) | 861 | if (!size) |
| 856 | size = type_size(vtop->t, &align); | 862 | size = type_size(vtop->t, &align); |
| 857 | switch(size) { | 863 | switch(size) { |
| 858 | case 1: func = __bound_ptr_indir1; break; | 864 | case 1: func = TOK___bound_ptr_indir1; break; |
| 859 | case 2: func = __bound_ptr_indir2; break; | 865 | case 2: func = TOK___bound_ptr_indir2; break; |
| 860 | case 4: func = __bound_ptr_indir4; break; | 866 | case 4: func = TOK___bound_ptr_indir4; break; |
| 861 | case 8: func = __bound_ptr_indir8; break; | 867 | case 8: func = TOK___bound_ptr_indir8; break; |
| 862 | case 12: func = __bound_ptr_indir12; break; | 868 | case 12: func = TOK___bound_ptr_indir12; break; |
| 863 | case 16: func = __bound_ptr_indir16; break; | 869 | case 16: func = TOK___bound_ptr_indir16; break; |
| 864 | default: | 870 | default: |
| 865 | error("unhandled size when derefencing bounded pointer"); | 871 | error("unhandled size when derefencing bounded pointer"); |
| 866 | func = NULL; | 872 | func = 0; |
| 867 | break; | 873 | break; |
| 868 | } | 874 | } |
| 869 | 875 | ||
| 870 | addr = vtop->c.ul; | 876 | /* patch relocation */ |
| 871 | *(int *)(addr + 1) = (int)func - addr - 5; | 877 | /* XXX: find a better solution ? */ |
| 878 | rel = vtop->c.ptr; | ||
| 879 | sym = external_sym(func, func_old_type, 0); | ||
| 880 | if (!sym->c) | ||
| 881 | put_extern_sym(sym, NULL, 0); | ||
| 882 | rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info)); | ||
| 872 | } | 883 | } |
| 873 | #endif | 884 | #endif |
| 874 | 885 | ||
| @@ -0,0 +1,556 @@ | |||
| 1 | /* TCC runtime library. | ||
| 2 | Parts of this code are (c) 2002 Fabrice Bellard | ||
| 3 | |||
| 4 | Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc. | ||
| 5 | |||
| 6 | This file is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by the | ||
| 8 | Free Software Foundation; either version 2, or (at your option) any | ||
| 9 | later version. | ||
| 10 | |||
| 11 | In addition to the permissions in the GNU General Public License, the | ||
| 12 | Free Software Foundation gives you unlimited permission to link the | ||
| 13 | compiled version of this file into combinations with other programs, | ||
| 14 | and to distribute those combinations without any restriction coming | ||
| 15 | from the use of this file. (The General Public License restrictions | ||
| 16 | do apply in other respects; for example, they cover modification of | ||
| 17 | the file, and distribution when not linked into a combine | ||
| 18 | executable.) | ||
| 19 | |||
| 20 | This file is distributed in the hope that it will be useful, but | ||
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 23 | General Public License for more details. | ||
| 24 | |||
| 25 | You should have received a copy of the GNU General Public License | ||
| 26 | along with this program; see the file COPYING. If not, write to | ||
| 27 | the Free Software Foundation, 59 Temple Place - Suite 330, | ||
| 28 | Boston, MA 02111-1307, USA. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #define W_TYPE_SIZE 32 | ||
| 32 | #define BITS_PER_UNIT 8 | ||
| 33 | |||
| 34 | typedef int Wtype; | ||
| 35 | typedef unsigned int UWtype; | ||
| 36 | typedef unsigned int USItype; | ||
| 37 | typedef long long DWtype; | ||
| 38 | typedef unsigned long long UDWtype; | ||
| 39 | |||
| 40 | struct DWstruct { | ||
| 41 | Wtype low, high; | ||
| 42 | }; | ||
| 43 | |||
| 44 | typedef union | ||
| 45 | { | ||
| 46 | struct DWstruct s; | ||
| 47 | DWtype ll; | ||
| 48 | } DWunion; | ||
| 49 | |||
| 50 | typedef long double XFtype; | ||
| 51 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) | ||
| 52 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | ||
| 53 | |||
| 54 | /* the following deal with IEEE single-precision numbers */ | ||
| 55 | #define EXCESS 126 | ||
| 56 | #define SIGNBIT 0x80000000 | ||
| 57 | #define HIDDEN (1 << 23) | ||
| 58 | #define SIGN(fp) ((fp) & SIGNBIT) | ||
| 59 | #define EXP(fp) (((fp) >> 23) & 0xFF) | ||
| 60 | #define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) | ||
| 61 | #define PACK(s,e,m) ((s) | ((e) << 23) | (m)) | ||
| 62 | |||
| 63 | /* the following deal with IEEE double-precision numbers */ | ||
| 64 | #define EXCESSD 1022 | ||
| 65 | #define HIDDEND (1 << 20) | ||
| 66 | #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) | ||
| 67 | #define SIGND(fp) ((fp.l.upper) & SIGNBIT) | ||
| 68 | #define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ | ||
| 69 | (fp.l.lower >> 22)) | ||
| 70 | #define HIDDEND_LL ((long long)1 << 52) | ||
| 71 | #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) | ||
| 72 | #define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) | ||
| 73 | |||
| 74 | /* the following deal with x86 long double-precision numbers */ | ||
| 75 | #define EXCESSLD 16382 | ||
| 76 | #define EXPLD(fp) (fp.l.upper & 0x7fff) | ||
| 77 | #define SIGNLD(fp) ((fp.l.upper) & 0x8000) | ||
| 78 | |||
| 79 | /* only for x86 */ | ||
| 80 | union ldouble_long { | ||
| 81 | long double ld; | ||
| 82 | struct { | ||
| 83 | unsigned long long lower; | ||
| 84 | unsigned short upper; | ||
| 85 | } l; | ||
| 86 | }; | ||
| 87 | |||
| 88 | union double_long { | ||
| 89 | double d; | ||
| 90 | #if 1 | ||
| 91 | struct { | ||
| 92 | unsigned long lower; | ||
| 93 | long upper; | ||
| 94 | } l; | ||
| 95 | #else | ||
| 96 | struct { | ||
| 97 | long upper; | ||
| 98 | unsigned long lower; | ||
| 99 | } l; | ||
| 100 | #endif | ||
| 101 | long long ll; | ||
| 102 | }; | ||
| 103 | |||
| 104 | union float_long { | ||
| 105 | float f; | ||
| 106 | long l; | ||
| 107 | }; | ||
| 108 | |||
| 109 | /* XXX: use gcc/tcc intrinsic ? */ | ||
| 110 | #if defined(__i386__) | ||
| 111 | #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ | ||
| 112 | __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ | ||
| 113 | : "=r" ((USItype) (sh)), \ | ||
| 114 | "=&r" ((USItype) (sl)) \ | ||
| 115 | : "0" ((USItype) (ah)), \ | ||
| 116 | "g" ((USItype) (bh)), \ | ||
| 117 | "1" ((USItype) (al)), \ | ||
| 118 | "g" ((USItype) (bl))) | ||
| 119 | #define umul_ppmm(w1, w0, u, v) \ | ||
| 120 | __asm__ ("mull %3" \ | ||
| 121 | : "=a" ((USItype) (w0)), \ | ||
| 122 | "=d" ((USItype) (w1)) \ | ||
| 123 | : "%0" ((USItype) (u)), \ | ||
| 124 | "rm" ((USItype) (v))) | ||
| 125 | #define udiv_qrnnd(q, r, n1, n0, dv) \ | ||
| 126 | __asm__ ("divl %4" \ | ||
| 127 | : "=a" ((USItype) (q)), \ | ||
| 128 | "=d" ((USItype) (r)) \ | ||
| 129 | : "0" ((USItype) (n0)), \ | ||
| 130 | "1" ((USItype) (n1)), \ | ||
| 131 | "rm" ((USItype) (dv))) | ||
| 132 | #define count_leading_zeros(count, x) \ | ||
| 133 | do { \ | ||
| 134 | USItype __cbtmp; \ | ||
| 135 | __asm__ ("bsrl %1,%0" \ | ||
| 136 | : "=r" (__cbtmp) : "rm" ((USItype) (x))); \ | ||
| 137 | (count) = __cbtmp ^ 31; \ | ||
| 138 | } while (0) | ||
| 139 | #else | ||
| 140 | #error unsupported CPU type | ||
| 141 | #endif | ||
| 142 | |||
| 143 | /* most of this code is taken from libgcc2.c from gcc */ | ||
| 144 | |||
| 145 | static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) | ||
| 146 | { | ||
| 147 | DWunion ww; | ||
| 148 | DWunion nn, dd; | ||
| 149 | DWunion rr; | ||
| 150 | UWtype d0, d1, n0, n1, n2; | ||
| 151 | UWtype q0, q1; | ||
| 152 | UWtype b, bm; | ||
| 153 | |||
| 154 | nn.ll = n; | ||
| 155 | dd.ll = d; | ||
| 156 | |||
| 157 | d0 = dd.s.low; | ||
| 158 | d1 = dd.s.high; | ||
| 159 | n0 = nn.s.low; | ||
| 160 | n1 = nn.s.high; | ||
| 161 | |||
| 162 | #if !UDIV_NEEDS_NORMALIZATION | ||
| 163 | if (d1 == 0) | ||
| 164 | { | ||
| 165 | if (d0 > n1) | ||
| 166 | { | ||
| 167 | /* 0q = nn / 0D */ | ||
| 168 | |||
| 169 | udiv_qrnnd (q0, n0, n1, n0, d0); | ||
| 170 | q1 = 0; | ||
| 171 | |||
| 172 | /* Remainder in n0. */ | ||
| 173 | } | ||
| 174 | else | ||
| 175 | { | ||
| 176 | /* qq = NN / 0d */ | ||
| 177 | |||
| 178 | if (d0 == 0) | ||
| 179 | d0 = 1 / d0; /* Divide intentionally by zero. */ | ||
| 180 | |||
| 181 | udiv_qrnnd (q1, n1, 0, n1, d0); | ||
| 182 | udiv_qrnnd (q0, n0, n1, n0, d0); | ||
| 183 | |||
| 184 | /* Remainder in n0. */ | ||
| 185 | } | ||
| 186 | |||
| 187 | if (rp != 0) | ||
| 188 | { | ||
| 189 | rr.s.low = n0; | ||
| 190 | rr.s.high = 0; | ||
| 191 | *rp = rr.ll; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | #else /* UDIV_NEEDS_NORMALIZATION */ | ||
| 196 | |||
| 197 | if (d1 == 0) | ||
| 198 | { | ||
| 199 | if (d0 > n1) | ||
| 200 | { | ||
| 201 | /* 0q = nn / 0D */ | ||
| 202 | |||
| 203 | count_leading_zeros (bm, d0); | ||
| 204 | |||
| 205 | if (bm != 0) | ||
| 206 | { | ||
| 207 | /* Normalize, i.e. make the most significant bit of the | ||
| 208 | denominator set. */ | ||
| 209 | |||
| 210 | d0 = d0 << bm; | ||
| 211 | n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); | ||
| 212 | n0 = n0 << bm; | ||
| 213 | } | ||
| 214 | |||
| 215 | udiv_qrnnd (q0, n0, n1, n0, d0); | ||
| 216 | q1 = 0; | ||
| 217 | |||
| 218 | /* Remainder in n0 >> bm. */ | ||
| 219 | } | ||
| 220 | else | ||
| 221 | { | ||
| 222 | /* qq = NN / 0d */ | ||
| 223 | |||
| 224 | if (d0 == 0) | ||
| 225 | d0 = 1 / d0; /* Divide intentionally by zero. */ | ||
| 226 | |||
| 227 | count_leading_zeros (bm, d0); | ||
| 228 | |||
| 229 | if (bm == 0) | ||
| 230 | { | ||
| 231 | /* From (n1 >= d0) /\ (the most significant bit of d0 is set), | ||
| 232 | conclude (the most significant bit of n1 is set) /\ (the | ||
| 233 | leading quotient digit q1 = 1). | ||
| 234 | |||
| 235 | This special case is necessary, not an optimization. | ||
| 236 | (Shifts counts of W_TYPE_SIZE are undefined.) */ | ||
| 237 | |||
| 238 | n1 -= d0; | ||
| 239 | q1 = 1; | ||
| 240 | } | ||
| 241 | else | ||
| 242 | { | ||
| 243 | /* Normalize. */ | ||
| 244 | |||
| 245 | b = W_TYPE_SIZE - bm; | ||
| 246 | |||
| 247 | d0 = d0 << bm; | ||
| 248 | n2 = n1 >> b; | ||
| 249 | n1 = (n1 << bm) | (n0 >> b); | ||
| 250 | n0 = n0 << bm; | ||
| 251 | |||
| 252 | udiv_qrnnd (q1, n1, n2, n1, d0); | ||
| 253 | } | ||
| 254 | |||
| 255 | /* n1 != d0... */ | ||
| 256 | |||
| 257 | udiv_qrnnd (q0, n0, n1, n0, d0); | ||
| 258 | |||
| 259 | /* Remainder in n0 >> bm. */ | ||
| 260 | } | ||
| 261 | |||
| 262 | if (rp != 0) | ||
| 263 | { | ||
| 264 | rr.s.low = n0 >> bm; | ||
| 265 | rr.s.high = 0; | ||
| 266 | *rp = rr.ll; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | #endif /* UDIV_NEEDS_NORMALIZATION */ | ||
| 270 | |||
| 271 | else | ||
| 272 | { | ||
| 273 | if (d1 > n1) | ||
| 274 | { | ||
| 275 | /* 00 = nn / DD */ | ||
| 276 | |||
| 277 | q0 = 0; | ||
| 278 | q1 = 0; | ||
| 279 | |||
| 280 | /* Remainder in n1n0. */ | ||
| 281 | if (rp != 0) | ||
| 282 | { | ||
| 283 | rr.s.low = n0; | ||
| 284 | rr.s.high = n1; | ||
| 285 | *rp = rr.ll; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | else | ||
| 289 | { | ||
| 290 | /* 0q = NN / dd */ | ||
| 291 | |||
| 292 | count_leading_zeros (bm, d1); | ||
| 293 | if (bm == 0) | ||
| 294 | { | ||
| 295 | /* From (n1 >= d1) /\ (the most significant bit of d1 is set), | ||
| 296 | conclude (the most significant bit of n1 is set) /\ (the | ||
| 297 | quotient digit q0 = 0 or 1). | ||
| 298 | |||
| 299 | This special case is necessary, not an optimization. */ | ||
| 300 | |||
| 301 | /* The condition on the next line takes advantage of that | ||
| 302 | n1 >= d1 (true due to program flow). */ | ||
| 303 | if (n1 > d1 || n0 >= d0) | ||
| 304 | { | ||
| 305 | q0 = 1; | ||
| 306 | sub_ddmmss (n1, n0, n1, n0, d1, d0); | ||
| 307 | } | ||
| 308 | else | ||
| 309 | q0 = 0; | ||
| 310 | |||
| 311 | q1 = 0; | ||
| 312 | |||
| 313 | if (rp != 0) | ||
| 314 | { | ||
| 315 | rr.s.low = n0; | ||
| 316 | rr.s.high = n1; | ||
| 317 | *rp = rr.ll; | ||
| 318 | } | ||
| 319 | } | ||
| 320 | else | ||
| 321 | { | ||
| 322 | UWtype m1, m0; | ||
| 323 | /* Normalize. */ | ||
| 324 | |||
| 325 | b = W_TYPE_SIZE - bm; | ||
| 326 | |||
| 327 | d1 = (d1 << bm) | (d0 >> b); | ||
| 328 | d0 = d0 << bm; | ||
| 329 | n2 = n1 >> b; | ||
| 330 | n1 = (n1 << bm) | (n0 >> b); | ||
| 331 | n0 = n0 << bm; | ||
| 332 | |||
| 333 | udiv_qrnnd (q0, n1, n2, n1, d1); | ||
| 334 | umul_ppmm (m1, m0, q0, d0); | ||
| 335 | |||
| 336 | if (m1 > n1 || (m1 == n1 && m0 > n0)) | ||
| 337 | { | ||
| 338 | q0--; | ||
| 339 | sub_ddmmss (m1, m0, m1, m0, d1, d0); | ||
| 340 | } | ||
| 341 | |||
| 342 | q1 = 0; | ||
| 343 | |||
| 344 | /* Remainder in (n1n0 - m1m0) >> bm. */ | ||
| 345 | if (rp != 0) | ||
| 346 | { | ||
| 347 | sub_ddmmss (n1, n0, n1, n0, m1, m0); | ||
| 348 | rr.s.low = (n1 << b) | (n0 >> bm); | ||
| 349 | rr.s.high = n1 >> bm; | ||
| 350 | *rp = rr.ll; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | ww.s.low = q0; | ||
| 357 | ww.s.high = q1; | ||
| 358 | return ww.ll; | ||
| 359 | } | ||
| 360 | |||
| 361 | #define __negdi2(a) (-(a)) | ||
| 362 | |||
| 363 | long long __divdi3(long long u, long long v) | ||
| 364 | { | ||
| 365 | int c = 0; | ||
| 366 | DWunion uu, vv; | ||
| 367 | DWtype w; | ||
| 368 | |||
| 369 | uu.ll = u; | ||
| 370 | vv.ll = v; | ||
| 371 | |||
| 372 | if (uu.s.high < 0) { | ||
| 373 | c = ~c; | ||
| 374 | uu.ll = __negdi2 (uu.ll); | ||
| 375 | } | ||
| 376 | if (vv.s.high < 0) { | ||
| 377 | c = ~c; | ||
| 378 | vv.ll = __negdi2 (vv.ll); | ||
| 379 | } | ||
| 380 | w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); | ||
| 381 | if (c) | ||
| 382 | w = __negdi2 (w); | ||
| 383 | return w; | ||
| 384 | } | ||
| 385 | |||
| 386 | long long __moddi3(long long u, long long v) | ||
| 387 | { | ||
| 388 | int c = 0; | ||
| 389 | DWunion uu, vv; | ||
| 390 | DWtype w; | ||
| 391 | |||
| 392 | uu.ll = u; | ||
| 393 | vv.ll = v; | ||
| 394 | |||
| 395 | if (uu.s.high < 0) { | ||
| 396 | c = ~c; | ||
| 397 | uu.ll = __negdi2 (uu.ll); | ||
| 398 | } | ||
| 399 | if (vv.s.high < 0) | ||
| 400 | vv.ll = __negdi2 (vv.ll); | ||
| 401 | |||
| 402 | __udivmoddi4 (uu.ll, vv.ll, &w); | ||
| 403 | if (c) | ||
| 404 | w = __negdi2 (w); | ||
| 405 | return w; | ||
| 406 | } | ||
| 407 | |||
| 408 | unsigned long long __udivdi3(unsigned long long u, unsigned long long v) | ||
| 409 | { | ||
| 410 | return __udivmoddi4 (u, v, (UDWtype *) 0); | ||
| 411 | } | ||
| 412 | |||
| 413 | unsigned long long __umoddi3(unsigned long long u, unsigned long long v) | ||
| 414 | { | ||
| 415 | UDWtype w; | ||
| 416 | |||
| 417 | __udivmoddi4 (u, v, &w); | ||
| 418 | return w; | ||
| 419 | } | ||
| 420 | |||
| 421 | /* XXX: suppress that and patch tcc to do it */ | ||
| 422 | long long __sardi3(long long a, int b) | ||
| 423 | { | ||
| 424 | return a >> b; | ||
| 425 | } | ||
| 426 | |||
| 427 | /* XXX: suppress that and patch tcc to do it */ | ||
| 428 | unsigned long long __shrdi3(unsigned long long a, int b) | ||
| 429 | { | ||
| 430 | return a >> b; | ||
| 431 | } | ||
| 432 | |||
| 433 | /* XXX: suppress that and patch tcc to do it */ | ||
| 434 | long long __shldi3(long long a, int b) | ||
| 435 | { | ||
| 436 | return a << b; | ||
| 437 | } | ||
| 438 | |||
| 439 | /* XXX: suppress that and patch tcc to do it */ | ||
| 440 | float __ulltof(unsigned long long a) | ||
| 441 | { | ||
| 442 | DWunion uu; | ||
| 443 | XFtype r; | ||
| 444 | |||
| 445 | uu.ll = a; | ||
| 446 | if (uu.s.high >= 0) { | ||
| 447 | return (float)uu.ll; | ||
| 448 | } else { | ||
| 449 | r = (XFtype)uu.ll; | ||
| 450 | r += 18446744073709551616.0; | ||
| 451 | return (float)r; | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | double __ulltod(unsigned long long a) | ||
| 456 | { | ||
| 457 | DWunion uu; | ||
| 458 | XFtype r; | ||
| 459 | |||
| 460 | uu.ll = a; | ||
| 461 | if (uu.s.high >= 0) { | ||
| 462 | return (double)uu.ll; | ||
| 463 | } else { | ||
| 464 | r = (XFtype)uu.ll; | ||
| 465 | r += 18446744073709551616.0; | ||
| 466 | return (double)r; | ||
| 467 | } | ||
| 468 | } | ||
| 469 | |||
| 470 | long double __ulltold(unsigned long long a) | ||
| 471 | { | ||
| 472 | DWunion uu; | ||
| 473 | XFtype r; | ||
| 474 | |||
| 475 | uu.ll = a; | ||
| 476 | if (uu.s.high >= 0) { | ||
| 477 | return (long double)uu.ll; | ||
| 478 | } else { | ||
| 479 | r = (XFtype)uu.ll; | ||
| 480 | r += 18446744073709551616.0; | ||
| 481 | return (long double)r; | ||
| 482 | } | ||
| 483 | } | ||
| 484 | |||
| 485 | unsigned long long __fixunssfdi (float a1) | ||
| 486 | { | ||
| 487 | register union float_long fl1; | ||
| 488 | register int exp; | ||
| 489 | register unsigned long l; | ||
| 490 | |||
| 491 | fl1.f = a1; | ||
| 492 | |||
| 493 | if (fl1.l == 0) | ||
| 494 | return (0); | ||
| 495 | |||
| 496 | exp = EXP (fl1.l) - EXCESS - 24; | ||
| 497 | |||
| 498 | l = MANT(fl1.l); | ||
| 499 | if (exp >= 41) | ||
| 500 | return (unsigned long long)-1; | ||
| 501 | else if (exp >= 0) | ||
| 502 | return (unsigned long long)l << exp; | ||
| 503 | else if (exp >= -23) | ||
| 504 | return l >> -exp; | ||
| 505 | else | ||
| 506 | return 0; | ||
| 507 | } | ||
| 508 | |||
| 509 | unsigned long long __fixunsdfdi (double a1) | ||
| 510 | { | ||
| 511 | register union double_long dl1; | ||
| 512 | register int exp; | ||
| 513 | register unsigned long long l; | ||
| 514 | |||
| 515 | dl1.d = a1; | ||
| 516 | |||
| 517 | if (dl1.ll == 0) | ||
| 518 | return (0); | ||
| 519 | |||
| 520 | exp = EXPD (dl1) - EXCESSD - 53; | ||
| 521 | |||
| 522 | l = MANTD_LL(dl1); | ||
| 523 | |||
| 524 | if (exp >= 12) | ||
| 525 | return (unsigned long long)-1; | ||
| 526 | else if (exp >= 0) | ||
| 527 | return l << exp; | ||
| 528 | else if (exp >= -52) | ||
| 529 | return l >> -exp; | ||
| 530 | else | ||
| 531 | return 0; | ||
| 532 | } | ||
| 533 | |||
| 534 | unsigned long long __fixunsxfdi (long double a1) | ||
| 535 | { | ||
| 536 | register union ldouble_long dl1; | ||
| 537 | register int exp; | ||
| 538 | register unsigned long long l; | ||
| 539 | |||
| 540 | dl1.ld = a1; | ||
| 541 | |||
| 542 | if (dl1.l.lower == 0 && dl1.l.upper == 0) | ||
| 543 | return (0); | ||
| 544 | |||
| 545 | exp = EXPLD (dl1) - EXCESSLD - 64; | ||
| 546 | |||
| 547 | l = dl1.l.lower; | ||
| 548 | |||
| 549 | if (exp > 0) | ||
| 550 | return (unsigned long long)-1; | ||
| 551 | else if (exp >= -63) | ||
| 552 | return l >> -exp; | ||
| 553 | else | ||
| 554 | return 0; | ||
| 555 | } | ||
| 556 | |||
| @@ -100,6 +100,7 @@ typedef union CValue { · 99 unmodified lines | |||
| 100 | unsigned long long ull; | 100 | unsigned long long ull; |
| 101 | struct TokenSym *ts; | 101 | struct TokenSym *ts; |
| 102 | struct Sym *sym; | 102 | struct Sym *sym; |
| 103 | void *ptr; | ||
| 103 | int tab[1]; | 104 | int tab[1]; |
| 104 | } CValue; | 105 | } CValue; |
| 105 | 106 | ||
| @@ -284,6 +285,7 @@ int ifdef_stack[IFDEF_STACK_SIZE], *ifdef_stack_ptr; · 178 unmodified lines | |||
| 284 | char **include_paths; | 285 | char **include_paths; |
| 285 | int nb_include_paths; | 286 | int nb_include_paths; |
| 286 | int char_pointer_type; | 287 | int char_pointer_type; |
| 288 | int func_old_type; | ||
| 287 | 289 | ||
| 288 | /* compile with debug symbol (and use them if error during execution) */ | 290 | /* compile with debug symbol (and use them if error during execution) */ |
| 289 | int do_debug = 0; | 291 | int do_debug = 0; |
| @@ -493,21 +495,9 @@ enum { · 203 unmodified lines | |||
| 493 | /* special identifiers */ | 495 | /* special identifiers */ |
| 494 | TOK___FUNC__, | 496 | TOK___FUNC__, |
| 495 | TOK_MAIN, | 497 | TOK_MAIN, |
| 496 | /* attribute identifiers */ | 498 | #define DEF(id, str) id, |
| 497 | TOK_SECTION, | 499 | #include "tcctok.h" |
| 498 | TOK___SECTION__, | 500 | #undef DEF |
| 499 | TOK_ALIGNED, | ||
| 500 | TOK___ALIGNED__, | ||
| 501 | TOK_UNUSED, | ||
| 502 | TOK___UNUSED__, | ||
| 503 | TOK_CDECL, | ||
| 504 | TOK___CDECL, | ||
| 505 | TOK___CDECL__, | ||
| 506 | TOK_STDCALL, | ||
| 507 | TOK___STDCALL, | ||
| 508 | TOK___STDCALL__, | ||
| 509 | TOK_NORETURN, | ||
| 510 | TOK___NORETURN__, | ||
| 511 | }; | 501 | }; |
| 512 | 502 | ||
| 513 | char *tcc_keywords = | 503 | char *tcc_keywords = |
| @@ -521,10 +511,10 @@ char *tcc_keywords = · 7 unmodified lines | |||
| 521 | "defined\0undef\0error\0line\0" | 511 | "defined\0undef\0error\0line\0" |
| 522 | "__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0" | 512 | "__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0" |
| 523 | "__func__\0main\0" | 513 | "__func__\0main\0" |
| 524 | /* attributes */ | 514 | /* builtin functions */ |
| 525 | "section\0__section__\0aligned\0__aligned__\0unused\0__unused__\0" | 515 | #define DEF(id, str) str "\0" |
| 526 | "cdecl\0__cdecl\0__cdecl__\0stdcall\0__stdcall\0__stdcall__\0" | 516 | #include "tcctok.h" |
| 527 | "noreturn\0__noreturn__\0" | 517 | #undef DEF |
| 528 | ; | 518 | ; |
| 529 | 519 | ||
| 530 | #ifdef WIN32 | 520 | #ifdef WIN32 |
| @@ -595,6 +585,7 @@ void vset(int t, int r, int v); · 64 unmodified lines | |||
| 595 | void type_to_str(char *buf, int buf_size, | 585 | void type_to_str(char *buf, int buf_size, |
| 596 | int t, const char *varstr); | 586 | int t, const char *varstr); |
| 597 | char *get_tok_str(int v, CValue *cv); | 587 | char *get_tok_str(int v, CValue *cv); |
| 588 | Sym *external_sym(int v, int u, int r); | ||
| 598 | 589 | ||
| 599 | /* section generation */ | 590 | /* section generation */ |
| 600 | void put_extern_sym(Sym *sym, Section *section, unsigned long value); | 591 | void put_extern_sym(Sym *sym, Section *section, unsigned long value); |
| @@ -680,77 +671,6 @@ void *dlsym(void *handle, const char *symbol) · 79 unmodified lines | |||
| 680 | 671 | ||
| 681 | #endif | 672 | #endif |
| 682 | 673 | ||
| 683 | /********************************************************/ | ||
| 684 | /* runtime library is there */ | ||
| 685 | /* XXX: we suppose that the host compiler handles 'long long'. It | ||
| 686 | would not be difficult to suppress this assumption */ | ||
| 687 | |||
| 688 | long long __divll(long long a, long long b) | ||
| 689 | { | ||
| 690 | return a / b; | ||
| 691 | } | ||
| 692 | |||
| 693 | long long __modll(long long a, long long b) | ||
| 694 | { | ||
| 695 | return a % b; | ||
| 696 | } | ||
| 697 | |||
| 698 | unsigned long long __divull(unsigned long long a, unsigned long long b) | ||
| 699 | { | ||
| 700 | return a / b; | ||
| 701 | } | ||
| 702 | |||
| 703 | unsigned long long __modull(unsigned long long a, unsigned long long b) | ||
| 704 | { | ||
| 705 | return a % b; | ||
| 706 | } | ||
| 707 | |||
| 708 | long long __sardi3(long long a, int b) | ||
| 709 | { | ||
| 710 | return a >> b; | ||
| 711 | } | ||
| 712 | |||
| 713 | unsigned long long __shrdi3(unsigned long long a, int b) | ||
| 714 | { | ||
| 715 | return a >> b; | ||
| 716 | } | ||
| 717 | |||
| 718 | long long __shldi3(long long a, int b) | ||
| 719 | { | ||
| 720 | return a << b; | ||
| 721 | } | ||
| 722 | |||
| 723 | float __ulltof(unsigned long long a) | ||
| 724 | { | ||
| 725 | return (float)a; | ||
| 726 | } | ||
| 727 | |||
| 728 | double __ulltod(unsigned long long a) | ||
| 729 | { | ||
| 730 | return (double)a; | ||
| 731 | } | ||
| 732 | |||
| 733 | long double __ulltold(unsigned long long a) | ||
| 734 | { | ||
| 735 | return (long double)a; | ||
| 736 | } | ||
| 737 | |||
| 738 | unsigned long long __ftoull(float a) | ||
| 739 | { | ||
| 740 | return (unsigned long long)a; | ||
| 741 | } | ||
| 742 | |||
| 743 | unsigned long long __dtoull(double a) | ||
| 744 | { | ||
| 745 | return (unsigned long long)a; | ||
| 746 | } | ||
| 747 | |||
| 748 | unsigned long long __ldtoull(long double a) | ||
| 749 | { | ||
| 750 | return (unsigned long long)a; | ||
| 751 | } | ||
| 752 | |||
| 753 | |||
| 754 | /********************************************************/ | 674 | /********************************************************/ |
| 755 | 675 | ||
| 756 | /* we use our own 'finite' function to avoid potential problems with | 676 | /* we use our own 'finite' function to avoid potential problems with |
| @@ -2589,6 +2509,17 @@ void vpush_ref(int t, Section *sec, unsigned long offset) · 1832 unmodified lines | |||
| 2589 | vsetc(t, VT_CONST | VT_SYM, &cval); | 2509 | vsetc(t, VT_CONST | VT_SYM, &cval); |
| 2590 | } | 2510 | } |
| 2591 | 2511 | ||
| 2512 | /* push a reference to symbol v */ | ||
| 2513 | void vpush_sym(int t, int v) | ||
| 2514 | { | ||
| 2515 | Sym *sym; | ||
| 2516 | CValue cval; | ||
| 2517 | |||
| 2518 | sym = external_sym(v, t, 0); | ||
| 2519 | cval.sym = sym; | ||
| 2520 | vsetc(t, VT_CONST | VT_SYM, &cval); | ||
| 2521 | } | ||
| 2522 | |||
| 2592 | void vset(int t, int r, int v) | 2523 | void vset(int t, int r, int v) |
| 2593 | { | 2524 | { |
| 2594 | CValue cval; | 2525 | CValue cval; |
| @@ -3019,29 +2950,29 @@ void gv_dup(void) · 424 unmodified lines | |||
| 3019 | void gen_opl(int op) | 2950 | void gen_opl(int op) |
| 3020 | { | 2951 | { |
| 3021 | int t, a, b, op1, c, i; | 2952 | int t, a, b, op1, c, i; |
| 3022 | void *func; | 2953 | int func; |
| 3023 | GFuncContext gf; | 2954 | GFuncContext gf; |
| 3024 | SValue tmp; | 2955 | SValue tmp; |
| 3025 | 2956 | ||
| 3026 | switch(op) { | 2957 | switch(op) { |
| 3027 | case '/': | 2958 | case '/': |
| 3028 | case TOK_PDIV: | 2959 | case TOK_PDIV: |
| 3029 | func = __divll; | 2960 | func = TOK___divdi3; |
| 3030 | goto gen_func; | 2961 | goto gen_func; |
| 3031 | case TOK_UDIV: | 2962 | case TOK_UDIV: |
| 3032 | func = __divull; | 2963 | func = TOK___udivdi3; |
| 3033 | goto gen_func; | 2964 | goto gen_func; |
| 3034 | case '%': | 2965 | case '%': |
| 3035 | func = __modll; | 2966 | func = TOK___moddi3; |
| 3036 | goto gen_func; | 2967 | goto gen_func; |
| 3037 | case TOK_UMOD: | 2968 | case TOK_UMOD: |
| 3038 | func = __modull; | 2969 | func = TOK___umoddi3; |
| 3039 | gen_func: | 2970 | gen_func: |
| 3040 | /* call generic long long function */ | 2971 | /* call generic long long function */ |
| 3041 | gfunc_start(&gf, FUNC_CDECL); | 2972 | gfunc_start(&gf, FUNC_CDECL); |
| 3042 | gfunc_param(&gf); | 2973 | gfunc_param(&gf); |
| 3043 | gfunc_param(&gf); | 2974 | gfunc_param(&gf); |
| 3044 | vpushi((int)func); | 2975 | vpush_sym(func_old_type, func); |
| 3045 | gfunc_call(&gf); | 2976 | gfunc_call(&gf); |
| 3046 | vpushi(0); | 2977 | vpushi(0); |
| 3047 | vtop->r = REG_IRET; | 2978 | vtop->r = REG_IRET; |
| @@ -3166,13 +3097,13 @@ void gen_opl(int op) · 118 unmodified lines | |||
| 3166 | /* XXX: should provide a faster fallback on x86 ? */ | 3097 | /* XXX: should provide a faster fallback on x86 ? */ |
| 3167 | switch(op) { | 3098 | switch(op) { |
| 3168 | case TOK_SAR: | 3099 | case TOK_SAR: |
| 3169 | func = __sardi3; | 3100 | func = TOK___sardi3; |
| 3170 | goto gen_func; | 3101 | goto gen_func; |
| 3171 | case TOK_SHR: | 3102 | case TOK_SHR: |
| 3172 | func = __shrdi3; | 3103 | func = TOK___shrdi3; |
| 3173 | goto gen_func; | 3104 | goto gen_func; |
| 3174 | case TOK_SHL: | 3105 | case TOK_SHL: |
| 3175 | func = __shldi3; | 3106 | func = TOK___shldi3; |
| 3176 | goto gen_func; | 3107 | goto gen_func; |
| 3177 | } | 3108 | } |
| 3178 | } | 3109 | } |
| @@ -3561,11 +3492,11 @@ void gen_cvt_itof1(int t) · 382 unmodified lines | |||
| 3561 | gfunc_start(&gf, FUNC_CDECL); | 3492 | gfunc_start(&gf, FUNC_CDECL); |
| 3562 | gfunc_param(&gf); | 3493 | gfunc_param(&gf); |
| 3563 | if (t == VT_FLOAT) | 3494 | if (t == VT_FLOAT) |
| 3564 | vpushi((int)&__ulltof); | 3495 | vpush_sym(func_old_type, TOK___ulltof); |
| 3565 | else if (t == VT_DOUBLE) | 3496 | else if (t == VT_DOUBLE) |
| 3566 | vpushi((int)&__ulltod); | 3497 | vpush_sym(func_old_type, TOK___ulltod); |
| 3567 | else | 3498 | else |
| 3568 | vpushi((int)&__ulltold); | 3499 | vpush_sym(func_old_type, TOK___ulltold); |
| 3569 | gfunc_call(&gf); | 3500 | gfunc_call(&gf); |
| 3570 | vpushi(0); | 3501 | vpushi(0); |
| 3571 | vtop->r = REG_FRET; | 3502 | vtop->r = REG_FRET; |
| @@ -3586,11 +3517,11 @@ void gen_cvt_ftoi1(int t) · 14 unmodified lines | |||
| 3586 | st = vtop->t & VT_BTYPE; | 3517 | st = vtop->t & VT_BTYPE; |
| 3587 | gfunc_param(&gf); | 3518 | gfunc_param(&gf); |
| 3588 | if (st == VT_FLOAT) | 3519 | if (st == VT_FLOAT) |
| 3589 | vpushi((int)&__ftoull); | 3520 | vpush_sym(func_old_type, TOK___fixunssfdi); |
| 3590 | else if (st == VT_DOUBLE) | 3521 | else if (st == VT_DOUBLE) |
| 3591 | vpushi((int)&__dtoull); | 3522 | vpush_sym(func_old_type, TOK___fixunsdfdi); |
| 3592 | else | 3523 | else |
| 3593 | vpushi((int)&__ldtoull); | 3524 | vpush_sym(func_old_type, TOK___fixunsxfdi); |
| 3594 | gfunc_call(&gf); | 3525 | gfunc_call(&gf); |
| 3595 | vpushi(0); | 3526 | vpushi(0); |
| 3596 | vtop->r = REG_IRET; | 3527 | vtop->r = REG_IRET; |
| @@ -4049,7 +3980,7 @@ void vstore(void) · 452 unmodified lines | |||
| 4049 | gfunc_param(&gf); | 3980 | gfunc_param(&gf); |
| 4050 | 3981 | ||
| 4051 | save_regs(0); | 3982 | save_regs(0); |
| 4052 | vpushi((int)&memcpy); | 3983 | vpush_sym(func_old_type, TOK_memcpy); |
| 4053 | gfunc_call(&gf); | 3984 | gfunc_call(&gf); |
| 4054 | /* leave source on stack */ | 3985 | /* leave source on stack */ |
| 4055 | } else if (ft & VT_BITFIELD) { | 3986 | } else if (ft & VT_BITFIELD) { |
| @@ -4697,7 +4628,7 @@ void gfunc_param_typed(GFuncContext *gf, Sym *func, Sym *arg) · 641 unmodified lines | |||
| 4697 | 4628 | ||
| 4698 | void unary(void) | 4629 | void unary(void) |
| 4699 | { | 4630 | { |
| 4700 | int n, t, ft, fc, p, align, size, r, data_offset; | 4631 | int n, t, ft, fc, align, size, r, data_offset; |
| 4701 | Sym *s; | 4632 | Sym *s; |
| 4702 | GFuncContext gf; | 4633 | GFuncContext gf; |
| 4703 | AttributeDef ad; | 4634 | AttributeDef ad; |
| @@ -4847,11 +4778,8 @@ void unary(void) · 143 unmodified lines | |||
| 4847 | if (tok != '(') | 4778 | if (tok != '(') |
| 4848 | error("'%s' undeclared", get_tok_str(t, NULL)); | 4779 | error("'%s' undeclared", get_tok_str(t, NULL)); |
| 4849 | /* for simple function calls, we tolerate undeclared | 4780 | /* for simple function calls, we tolerate undeclared |
| 4850 | external reference */ | 4781 | external reference to int() function */ |
| 4851 | p = anon_sym++; | 4782 | s = external_sym(t, func_old_type, 0); |
| 4852 | sym_push1(&global_stack, p, 0, FUNC_OLD); | ||
| 4853 | /* int() function */ | ||
| 4854 | s = external_sym(t, VT_FUNC | (p << VT_STRUCT_SHIFT), 0); | ||
| 4855 | } | 4783 | } |
| 4856 | vset(s->t, s->r, s->c); | 4784 | vset(s->t, s->r, s->c); |
| 4857 | /* if forward reference, we must point to s */ | 4785 | /* if forward reference, we must point to s */ |
| @@ -5633,7 +5561,7 @@ void init_putz(int t, Section *sec, unsigned long c, int size) · 775 unmodified lines | |||
| 5633 | gfunc_param(&gf); | 5561 | gfunc_param(&gf); |
| 5634 | vset(VT_INT, VT_LOCAL, c); | 5562 | vset(VT_INT, VT_LOCAL, c); |
| 5635 | gfunc_param(&gf); | 5563 | gfunc_param(&gf); |
| 5636 | vpushi((int)&memset); | 5564 | vpush_sym(func_old_type, TOK_memset); |
| 5637 | gfunc_call(&gf); | 5565 | gfunc_call(&gf); |
| 5638 | } | 5566 | } |
| 5639 | } | 5567 | } |
| @@ -6190,7 +6118,8 @@ static int tcc_compile(TCCState *s) · 550 unmodified lines | |||
| 6190 | { | 6118 | { |
| 6191 | Sym *define_start; | 6119 | Sym *define_start; |
| 6192 | char buf[512]; | 6120 | char buf[512]; |
| 6193 | 6121 | int p; | |
| 6122 | |||
| 6194 | funcname = ""; | 6123 | funcname = ""; |
| 6195 | include_stack_ptr = include_stack; | 6124 | include_stack_ptr = include_stack; |
| 6196 | ifdef_stack_ptr = ifdef_stack; | 6125 | ifdef_stack_ptr = ifdef_stack; |
| @@ -6215,6 +6144,10 @@ static int tcc_compile(TCCState *s) · 18 unmodified lines | |||
| 6215 | /* define common 'char *' type because it is often used internally | 6144 | /* define common 'char *' type because it is often used internally |
| 6216 | for arrays and struct dereference */ | 6145 | for arrays and struct dereference */ |
| 6217 | char_pointer_type = mk_pointer(VT_BYTE); | 6146 | char_pointer_type = mk_pointer(VT_BYTE); |
| 6147 | /* define an old type function 'int func()' */ | ||
| 6148 | p = anon_sym++; | ||
| 6149 | sym_push1(&global_stack, p, 0, FUNC_OLD); | ||
| 6150 | func_old_type = VT_FUNC | (p << VT_STRUCT_SHIFT); | ||
| 6218 | 6151 | ||
| 6219 | define_start = define_stack.top; | 6152 | define_start = define_stack.top; |
| 6220 | inp(); | 6153 | inp(); |
| @@ -6807,8 +6740,6 @@ static void put32(unsigned char *p, unsigned int val) · 586 unmodified lines | |||
| 6807 | static void build_got(void) | 6740 | static void build_got(void) |
| 6808 | { | 6741 | { |
| 6809 | /* if no got, then create it */ | 6742 | /* if no got, then create it */ |
| 6810 | /* a got is needed even if static link for the symbol | ||
| 6811 | _GLOBAL_OFFSET_TABLE_ */ | ||
| 6812 | got = new_section(".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); | 6743 | got = new_section(".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 6813 | got->sh_entsize = 4; | 6744 | got->sh_entsize = 4; |
| 6814 | add_elf_sym(symtab_section, 0, 4, ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), | 6745 | add_elf_sym(symtab_section, 0, 4, ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), |
| @@ -6933,6 +6864,12 @@ static void put_dt(Section *dynamic, int dt, unsigned long val) · 118 unmodified lines | |||
| 6933 | dynamic->data_ptr += sizeof(Elf32_Dyn); | 6864 | dynamic->data_ptr += sizeof(Elf32_Dyn); |
| 6934 | } | 6865 | } |
| 6935 | 6866 | ||
| 6867 | /* add tcc runtime libraries */ | ||
| 6868 | static void tcc_add_runtime(TCCState *s1) | ||
| 6869 | { | ||
| 6870 | tcc_add_file(s1, CONFIG_TCC_PREFIX "/lib/tcc/libtcc1.o"); | ||
| 6871 | } | ||
| 6872 | |||
| 6936 | /* add dynamic sections so that the executable is dynamically linked */ | 6873 | /* add dynamic sections so that the executable is dynamically linked */ |
| 6937 | static char elf_interp[] = "/lib/ld-linux.so.2"; | 6874 | static char elf_interp[] = "/lib/ld-linux.so.2"; |
| 6938 | 6875 | ||
| @@ -6963,8 +6900,9 @@ int tcc_output_file(TCCState *s1, const char *filename) · 24 unmodified lines | |||
| 6963 | 6900 | ||
| 6964 | /* add libc crtn object */ | 6901 | /* add libc crtn object */ |
| 6965 | if (file_type != TCC_OUTPUT_OBJ) { | 6902 | if (file_type != TCC_OUTPUT_OBJ) { |
| 6966 | tcc_add_file(s1, CONFIG_TCC_CRT_PREFIX "/crtn.o"); | 6903 | tcc_add_runtime(s1); |
| 6967 | tcc_add_library(s1, "c"); | 6904 | tcc_add_library(s1, "c"); |
| 6905 | tcc_add_file(s1, CONFIG_TCC_CRT_PREFIX "/crtn.o"); | ||
| 6968 | } | 6906 | } |
| 6969 | 6907 | ||
| 6970 | interp = NULL; | 6908 | interp = NULL; |
| @@ -8076,6 +8014,8 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 1105 unmodified lines | |||
| 8076 | int (*prog_main)(int, char **); | 8014 | int (*prog_main)(int, char **); |
| 8077 | int i; | 8015 | int i; |
| 8078 | 8016 | ||
| 8017 | tcc_add_runtime(s1); | ||
| 8018 | |||
| 8079 | relocate_common_syms(); | 8019 | relocate_common_syms(); |
| 8080 | 8020 | ||
| 8081 | /* compute relocation address : section are relocated in place */ | 8021 | /* compute relocation address : section are relocated in place */ |
| @@ -0,0 +1,39 @@ | |||
| 1 | /* attribute identifiers */ | ||
| 2 | DEF(TOK_SECTION, "section") | ||
| 3 | DEF(TOK___SECTION__, "__section__") | ||
| 4 | DEF(TOK_ALIGNED, "aligned") | ||
| 5 | DEF(TOK___ALIGNED__, "__aligned__") | ||
| 6 | DEF(TOK_UNUSED, "unused") | ||
| 7 | DEF(TOK___UNUSED__, "__unused__") | ||
| 8 | DEF(TOK_CDECL, "cdecl") | ||
| 9 | DEF(TOK___CDECL, "__cdecl") | ||
| 10 | DEF(TOK___CDECL__, "__cdecl__") | ||
| 11 | DEF(TOK_STDCALL, "stdcall") | ||
| 12 | DEF(TOK___STDCALL, "__stdcall") | ||
| 13 | DEF(TOK___STDCALL__, "__stdcall__") | ||
| 14 | DEF(TOK_NORETURN, "noreturn") | ||
| 15 | DEF(TOK___NORETURN__, "__noreturn__") | ||
| 16 | |||
| 17 | /* builtin functions */ | ||
| 18 | DEF(TOK_memcpy, "memcpy") | ||
| 19 | DEF(TOK_memset, "memset") | ||
| 20 | DEF(TOK___divdi3, "__divdi3") | ||
| 21 | DEF(TOK___moddi3, "__moddi3") | ||
| 22 | DEF(TOK___udivdi3, "__udivdi3") | ||
| 23 | DEF(TOK___umoddi3, "__umoddi3") | ||
| 24 | DEF(TOK___sardi3, "__sardi3") | ||
| 25 | DEF(TOK___shrdi3, "__shrdi3") | ||
| 26 | DEF(TOK___shldi3, "__shldi3") | ||
| 27 | DEF(TOK___ulltof, "__ulltof") | ||
| 28 | DEF(TOK___ulltod, "__ulltod") | ||
| 29 | DEF(TOK___ulltold, "__ulltold") | ||
| 30 | DEF(TOK___fixunssfdi, "__fixunssfdi") | ||
| 31 | DEF(TOK___fixunsdfdi, "__fixunsdfdi") | ||
| 32 | DEF(TOK___fixunsxfdi, "__fixunsxfdi") | ||
| 33 | DEF(TOK___bound_ptr_add, "__bound_ptr_add") | ||
| 34 | DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1") | ||
| 35 | DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2") | ||
| 36 | DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4") | ||
| 37 | DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8") | ||
| 38 | DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12") | ||
| 39 | DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16") | ||