History

lib/libtcc1.c: cleanup

- remove #include dependencies from libtcc1.c for easier cross compilation - clear_cache only on ARM - error-message for mprotect failure

grischka committed 10 years ago

Commit 02642bc1 parent bfd1c085 files · +25 −62Browse files

Unified · Split

5 files
  1. i386-gen.c +3 −16
  2. lib/libtcc1.c +15 −35
  3. tcc.h +1 −1
  4. tccrun.c +6 −7
  5. tcctok.h +0 −3
i386-gen.c+3−16
@@ -1025,8 +1025,7 @@ ST_FUNC void gen_cvt_itof(int t) · 1024 unmodified lines
10251025 /* convert fp to int 't' type */
10261026 ST_FUNC void gen_cvt_ftoi(int t)
10271027 {
1028− #ifndef COMMIT_4ad186c5ef61_IS_FIXED
1029− /* a good version but it takes a more time to execute */
1028+#if 1
10301029 gv(RC_FLOAT);
10311030 save_reg(TREG_EAX);
10321031 save_reg(TREG_EDX);
@@ -1034,19 +1033,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 1 unmodified line
10341033 vtop->r = TREG_EAX; /* mark reg as used */
10351034 if (t == VT_LLONG)
10361035 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
10501037 int bt = vtop->type.t & VT_BTYPE;
10511038 if (bt == VT_FLOAT)
10521039 vpush_global_sym(&func_old_type, TOK___fixsfdi);
@@ -1059,7 +1046,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 6 unmodified lines
10591046 vpushi(0);
10601047 vtop->r = REG_IRET;
10611048 vtop->r2 = REG_LRET;
1062− #endif
1049+#endif
10631050 }
10641051
10651052 /* convert from one floating point type to another */
lib/libtcc1.c+15−35
@@ -28,8 +28,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, · 27 unmodified lines
2828 Boston, MA 02111-1307, USA.
2929 */
3030
31−#include <stdint.h>
32−
3331 #define W_TYPE_SIZE 32
3432 #define BITS_PER_UNIT 8
3533
@@ -480,7 +478,6 @@ long long __ashldi3(long long a, int b) · 444 unmodified lines
480478 #endif
481479 }
482480
483−#ifndef COMMIT_4ad186c5ef61_IS_FIXED
484481 long long __tcc_cvt_ftol(long double x)
485482 {
486483 unsigned c0, c1;
@@ -492,7 +489,6 @@ long long __tcc_cvt_ftol(long double x) · 5 unmodified lines
492489 __asm__ __volatile__ ("fldcw %0" : : "m" (c0));
493490 return ret;
494491 }
495−#endif
496492
497493 #endif /* !__x86_64__ */
498494
@@ -638,24 +634,24 @@ long long __fixxfdi (long double a1) · 139 unmodified lines
638634 #if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
639635
640636 #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
644644 #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);
651647 extern void abort(void);
652648 #endif
653649
650+/* This should be in sync with our include/stdarg.h */
654651 enum __va_arg_type {
655652 __va_gen_reg, __va_float_reg, __va_stack
656653 };
657654
658−//This should be in sync with the declaration on our include/stdarg.h
659655 /* GCC compatible definition of va_list. */
660656 typedef struct {
661657 unsigned int gp_offset;
@@ -667,11 +663,6 @@ typedef struct { · 5 unmodified lines
667663 char *reg_save_area;
668664 } __va_list_struct;
669665
670−#undef __va_start
671−#undef __va_arg
672−#undef __va_copy
673−#undef __va_end
674−
675666 void __va_start(__va_list_struct *ap, void *fp)
676667 {
677668 memset(ap, 0, sizeof(__va_list_struct));
@@ -705,33 +696,25 @@ void *__va_arg(__va_list_struct *ap, · 27 unmodified lines
705696 case __va_stack:
706697 use_overflow_area:
707698 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);
709700 return ap->overflow_arg_area - size;
710701
711− default:
702+ default: /* should never happen */
712703 #ifndef __TINYC__
713704 fprintf(stderr, "unknown ABI type for __va_arg\n");
714705 #endif
715706 abort();
716707 }
717708 }
718−
719709 #endif /* __x86_64__ */
720710
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
730712 #define _GNU_SOURCE
731713 #include <unistd.h>
732714 #include <sys/syscall.h>
733715 #include <stdio.h>
734716
717+/* Flushing for tccrun */
735718 void __clear_cache(void *beginning, void *end)
736719 {
737720 /* __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
747730 "ret");
748731 #endif
749732 }
750−
751−#else
752−#warning __clear_cache not defined for this architecture, avoid using tcc -run
753−#endif
733+#endif /* arm */
tcc.h+1−1
@@ -1312,6 +1312,7 @@ ST_DATA Section *last_text_section; /* to handle .previous asm directive */ · 1311 unmodified lines
13121312 /* bound check related sections */
13131313 ST_DATA Section *bounds_section; /* contains global data bound description */
13141314 ST_DATA Section *lbounds_section; /* contains local data bound description */
1315+ST_FUNC void tccelf_bounds_new(TCCState *s);
13151316 #endif
13161317 /* symbol sections */
13171318 ST_DATA Section *symtab_section, *strtab_section;
@@ -1320,7 +1321,6 @@ ST_DATA Section *stab_section, *stabstr_section; · 2 unmodified lines
13201321
13211322 ST_FUNC void tccelf_new(TCCState *s);
13221323 ST_FUNC void tccelf_delete(TCCState *s);
1323−ST_FUNC void tccelf_bounds_new(TCCState *s);
13241324 ST_FUNC void tccelf_stab_new(TCCState *s);
13251325
13261326 ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
tccrun.c+6−7
@@ -255,7 +255,6 @@ static void set_pages_executable(void *ptr, unsigned long length) · 254 unmodified lines
255255 unsigned long old_protect;
256256 VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
257257 #else
258− extern void __clear_cache(void *beginning, void *end);
259258 #ifndef PAGESIZE
260259 # define PAGESIZE 4096
261260 #endif
@@ -263,12 +262,12 @@ static void set_pages_executable(void *ptr, unsigned long length) · 1 unmodified line
263262 start = (addr_t)ptr & ~(PAGESIZE - 1);
264263 end = (addr_t)ptr + length;
265264 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
272271 #endif
273272 }
274273
tcctok.h+0−3
@@ -242,10 +242,7 @@ · 241 unmodified lines
242242 DEF(TOK___fixsfdi, "__fixsfdi")
243243 DEF(TOK___fixdfdi, "__fixdfdi")
244244 DEF(TOK___fixxfdi, "__fixxfdi")
245−
246− #ifndef COMMIT_4ad186c5ef61_IS_FIXED
247245 DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
248− #endif
249246 #endif
250247
251248 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t