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