- remove #include dependencies from libtcc1.c for easier cross compilation - clear_cache only on ARM - error-message for mprotect failure
Unified · Split
| @@ -1025,8 +1025,7 @@ ST_FUNC void gen_cvt_itof(int t) · 1024 unmodified lines | ||
| 1025 | 1025 | /* convert fp to int 't' type */ |
| 1026 | 1026 | ST_FUNC void gen_cvt_ftoi(int t) |
| 1027 | 1027 | { |
| 1028 | − #ifndef COMMIT_4ad186c5ef61_IS_FIXED | |
| 1029 | − /* a good version but it takes a more time to execute */ | |
| 1028 | +#if 1 | |
| 1030 | 1029 | gv(RC_FLOAT); |
| 1031 | 1030 | save_reg(TREG_EAX); |
| 1032 | 1031 | save_reg(TREG_EDX); |
| @@ -1034,19 +1033,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 1 unmodified line | ||
| 1034 | 1033 | vtop->r = TREG_EAX; /* mark reg as used */ |
| 1035 | 1034 | if (t == VT_LLONG) |
| 1036 | 1035 | vtop->r2 = TREG_EDX; |
| 1037 | − #else | |
| 1038 | − /* a new version with a bug: t2a = 44100312 */ | |
| 1039 | − /* | |
| 1040 | − #include<stdio.h> | |
| 1041 | − int main() { | |
| 1042 | − int t1 = 176401255; | |
| 1043 | − float f = 0.25f; | |
| 1044 | − int t2a = (int)(t1 * f); // must be 44100313 | |
| 1045 | − int t2b = (int)(t1 * (float)0.25f); | |
| 1046 | − printf("t2a=%d t2b=%d \n",t2a,t2b); | |
| 1047 | − return 0; | |
| 1048 | − } | |
| 1049 | − */ | |
| 1036 | +#else | |
| 1050 | 1037 | int bt = vtop->type.t & VT_BTYPE; |
| 1051 | 1038 | if (bt == VT_FLOAT) |
| 1052 | 1039 | vpush_global_sym(&func_old_type, TOK___fixsfdi); |
| @@ -1059,7 +1046,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 6 unmodified lines | ||
| 1059 | 1046 | vpushi(0); |
| 1060 | 1047 | vtop->r = REG_IRET; |
| 1061 | 1048 | vtop->r2 = REG_LRET; |
| 1062 | − #endif | |
| 1049 | +#endif | |
| 1063 | 1050 | } |
| 1064 | 1051 | |
| 1065 | 1052 | /* convert from one floating point type to another */ |
| @@ -28,8 +28,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, · 27 unmodified lines | ||
| 28 | 28 | Boston, MA 02111-1307, USA. |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | −#include <stdint.h> | |
| 32 | − | |
| 33 | 31 | #define W_TYPE_SIZE 32 |
| 34 | 32 | #define BITS_PER_UNIT 8 |
| 35 | 33 | |
| @@ -480,7 +478,6 @@ long long __ashldi3(long long a, int b) · 444 unmodified lines | ||
| 480 | 478 | #endif |
| 481 | 479 | } |
| 482 | 480 | |
| 483 | −#ifndef COMMIT_4ad186c5ef61_IS_FIXED | |
| 484 | 481 | long long __tcc_cvt_ftol(long double x) |
| 485 | 482 | { |
| 486 | 483 | unsigned c0, c1; |
| @@ -492,7 +489,6 @@ long long __tcc_cvt_ftol(long double x) · 5 unmodified lines | ||
| 492 | 489 | __asm__ __volatile__ ("fldcw %0" : : "m" (c0)); |
| 493 | 490 | return ret; |
| 494 | 491 | } |
| 495 | −#endif | |
| 496 | 492 | |
| 497 | 493 | #endif /* !__x86_64__ */ |
| 498 | 494 | |
| @@ -638,24 +634,24 @@ long long __fixxfdi (long double a1) · 139 unmodified lines | ||
| 638 | 634 | #if defined(TCC_TARGET_X86_64) && !defined(_WIN64) |
| 639 | 635 | |
| 640 | 636 | #ifndef __TINYC__ |
| 641 | −#include <stdlib.h> | |
| 642 | −#include <stdio.h> | |
| 643 | −#include <string.h> | |
| 637 | +# include <stdlib.h> | |
| 638 | +# include <stdio.h> | |
| 639 | +# include <string.h> | |
| 640 | +# undef __va_start | |
| 641 | +# undef __va_arg | |
| 642 | +# undef __va_copy | |
| 643 | +# undef __va_end | |
| 644 | 644 | #else |
| 645 | −/* Avoid including stdlib.h because it is not easily available when | |
| 646 | − cross compiling */ | |
| 647 | −#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */ | |
| 648 | −extern void *malloc(unsigned long long); | |
| 649 | −extern void *memset(void *s, int c, size_t n); | |
| 650 | −extern void free(void*); | |
| 645 | +/* Avoid include files, they may not be available when cross compiling */ | |
| 646 | +extern void *memset(void *s, int c, __SIZE_TYPE__ n); | |
| 651 | 647 | extern void abort(void); |
| 652 | 648 | #endif |
| 653 | 649 | |
| 650 | +/* This should be in sync with our include/stdarg.h */ | |
| 654 | 651 | enum __va_arg_type { |
| 655 | 652 | __va_gen_reg, __va_float_reg, __va_stack |
| 656 | 653 | }; |
| 657 | 654 | |
| 658 | −//This should be in sync with the declaration on our include/stdarg.h | |
| 659 | 655 | /* GCC compatible definition of va_list. */ |
| 660 | 656 | typedef struct { |
| 661 | 657 | unsigned int gp_offset; |
| @@ -667,11 +663,6 @@ typedef struct { · 5 unmodified lines | ||
| 667 | 663 | char *reg_save_area; |
| 668 | 664 | } __va_list_struct; |
| 669 | 665 | |
| 670 | −#undef __va_start | |
| 671 | −#undef __va_arg | |
| 672 | −#undef __va_copy | |
| 673 | −#undef __va_end | |
| 674 | − | |
| 675 | 666 | void __va_start(__va_list_struct *ap, void *fp) |
| 676 | 667 | { |
| 677 | 668 | memset(ap, 0, sizeof(__va_list_struct)); |
| @@ -705,33 +696,25 @@ void *__va_arg(__va_list_struct *ap, · 27 unmodified lines | ||
| 705 | 696 | case __va_stack: |
| 706 | 697 | use_overflow_area: |
| 707 | 698 | ap->overflow_arg_area += size; |
| 708 | − ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align); | |
| 699 | + ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); | |
| 709 | 700 | return ap->overflow_arg_area - size; |
| 710 | 701 | |
| 711 | − default: | |
| 702 | + default: /* should never happen */ | |
| 712 | 703 | #ifndef __TINYC__ |
| 713 | 704 | fprintf(stderr, "unknown ABI type for __va_arg\n"); |
| 714 | 705 | #endif |
| 715 | 706 | abort(); |
| 716 | 707 | } |
| 717 | 708 | } |
| 718 | − | |
| 719 | 709 | #endif /* __x86_64__ */ |
| 720 | 710 | |
| 721 | −/* Flushing for tccrun */ | |
| 722 | −#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386) | |
| 723 | − | |
| 724 | −void __clear_cache(void *beginning, void *end) | |
| 725 | −{ | |
| 726 | −} | |
| 727 | − | |
| 728 | −#elif defined(TCC_TARGET_ARM) | |
| 729 | − | |
| 711 | +#ifdef TCC_TARGET_ARM | |
| 730 | 712 | #define _GNU_SOURCE |
| 731 | 713 | #include <unistd.h> |
| 732 | 714 | #include <sys/syscall.h> |
| 733 | 715 | #include <stdio.h> |
| 734 | 716 | |
| 717 | +/* Flushing for tccrun */ | |
| 735 | 718 | void __clear_cache(void *beginning, void *end) |
| 736 | 719 | { |
| 737 | 720 | /* __ARM_NR_cacheflush is kernel private and should not be used in user space. |
| @@ -747,7 +730,4 @@ void __clear_cache(void *beginning, void *end) · 9 unmodified lines | ||
| 747 | 730 | "ret"); |
| 748 | 731 | #endif |
| 749 | 732 | } |
| 750 | − | |
| 751 | −#else | |
| 752 | −#warning __clear_cache not defined for this architecture, avoid using tcc -run | |
| 753 | −#endif | |
| 733 | +#endif /* arm */ | |
| @@ -1312,6 +1312,7 @@ ST_DATA Section *last_text_section; /* to handle .previous asm directive */ · 1311 unmodified lines | ||
| 1312 | 1312 | /* bound check related sections */ |
| 1313 | 1313 | ST_DATA Section *bounds_section; /* contains global data bound description */ |
| 1314 | 1314 | ST_DATA Section *lbounds_section; /* contains local data bound description */ |
| 1315 | +ST_FUNC void tccelf_bounds_new(TCCState *s); | |
| 1315 | 1316 | #endif |
| 1316 | 1317 | /* symbol sections */ |
| 1317 | 1318 | ST_DATA Section *symtab_section, *strtab_section; |
| @@ -1320,7 +1321,6 @@ ST_DATA Section *stab_section, *stabstr_section; · 2 unmodified lines | ||
| 1320 | 1321 | |
| 1321 | 1322 | ST_FUNC void tccelf_new(TCCState *s); |
| 1322 | 1323 | ST_FUNC void tccelf_delete(TCCState *s); |
| 1323 | −ST_FUNC void tccelf_bounds_new(TCCState *s); | |
| 1324 | 1324 | ST_FUNC void tccelf_stab_new(TCCState *s); |
| 1325 | 1325 | |
| 1326 | 1326 | ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags); |
| @@ -255,7 +255,6 @@ static void set_pages_executable(void *ptr, unsigned long length) · 254 unmodified lines | ||
| 255 | 255 | unsigned long old_protect; |
| 256 | 256 | VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect); |
| 257 | 257 | #else |
| 258 | − extern void __clear_cache(void *beginning, void *end); | |
| 259 | 258 | #ifndef PAGESIZE |
| 260 | 259 | # define PAGESIZE 4096 |
| 261 | 260 | #endif |
| @@ -263,12 +262,12 @@ static void set_pages_executable(void *ptr, unsigned long length) · 1 unmodified line | ||
| 263 | 262 | start = (addr_t)ptr & ~(PAGESIZE - 1); |
| 264 | 263 | end = (addr_t)ptr + length; |
| 265 | 264 | end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1); |
| 266 | − mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC); | |
| 267 | − #ifndef __PCC__ | |
| 268 | − __clear_cache(ptr, (char *)ptr + length); | |
| 269 | − #else | |
| 270 | − /* pcc 1.2.0.DEVEL 20141206 don't have such proc */ | |
| 271 | − #endif | |
| 265 | + if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC)) | |
| 266 | + tcc_error("mprotect failed: did you mean to configure --with-selinux?"); | |
| 267 | +#if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 | |
| 268 | + { extern void __clear_cache(void *beginning, void *end); | |
| 269 | + __clear_cache(ptr, (char *)ptr + length); } | |
| 270 | +#endif | |
| 272 | 271 | #endif |
| 273 | 272 | } |
| 274 | 273 | |
| @@ -242,10 +242,7 @@ · 241 unmodified lines | ||
| 242 | 242 | DEF(TOK___fixsfdi, "__fixsfdi") |
| 243 | 243 | DEF(TOK___fixdfdi, "__fixdfdi") |
| 244 | 244 | DEF(TOK___fixxfdi, "__fixxfdi") |
| 245 | − | |
| 246 | − #ifndef COMMIT_4ad186c5ef61_IS_FIXED | |
| 247 | 245 | DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol") |
| 248 | − #endif | |
| 249 | 246 | #endif |
| 250 | 247 | |
| 251 | 248 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |