lib/libtcc1.c: cleanup
- remove #include dependencies from libtcc1.c for easier cross compilation - clear_cache only on ARM - error-message for mprotect failure
This commit is contained in:
		
							parent
							
								
									bfd1c08d6c
								
							
						
					
					
						commit
						02642bc94c
					
				
					 5 changed files with 25 additions and 62 deletions
				
			
		
							
								
								
									
										15
									
								
								i386-gen.c
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								i386-gen.c
									
										
									
									
									
								
							| 
						 | 
					@ -1025,8 +1025,7 @@ ST_FUNC void gen_cvt_itof(int t)
 | 
				
			||||||
/* convert fp to int 't' type */
 | 
					/* convert fp to int 't' type */
 | 
				
			||||||
ST_FUNC void gen_cvt_ftoi(int t)
 | 
					ST_FUNC void gen_cvt_ftoi(int t)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 #ifndef COMMIT_4ad186c5ef61_IS_FIXED
 | 
					#if 1
 | 
				
			||||||
    /* a good version but it takes a more time to execute */
 | 
					 | 
				
			||||||
    gv(RC_FLOAT);
 | 
					    gv(RC_FLOAT);
 | 
				
			||||||
    save_reg(TREG_EAX);
 | 
					    save_reg(TREG_EAX);
 | 
				
			||||||
    save_reg(TREG_EDX);
 | 
					    save_reg(TREG_EDX);
 | 
				
			||||||
| 
						 | 
					@ -1035,18 +1034,6 @@ ST_FUNC void gen_cvt_ftoi(int t)
 | 
				
			||||||
    if (t == VT_LLONG)
 | 
					    if (t == VT_LLONG)
 | 
				
			||||||
        vtop->r2 = TREG_EDX;
 | 
					        vtop->r2 = TREG_EDX;
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    /* a new version with a bug: t2a = 44100312 */
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    #include<stdio.h>
 | 
					 | 
				
			||||||
    int main() {
 | 
					 | 
				
			||||||
	int t1 = 176401255;
 | 
					 | 
				
			||||||
	float f = 0.25f;
 | 
					 | 
				
			||||||
	int t2a = (int)(t1 * f); // must be 44100313
 | 
					 | 
				
			||||||
	int t2b = (int)(t1 * (float)0.25f);
 | 
					 | 
				
			||||||
	printf("t2a=%d t2b=%d \n",t2a,t2b);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
    int bt = vtop->type.t & VT_BTYPE;
 | 
					    int bt = vtop->type.t & VT_BTYPE;
 | 
				
			||||||
    if (bt == VT_FLOAT)
 | 
					    if (bt == VT_FLOAT)
 | 
				
			||||||
        vpush_global_sym(&func_old_type, TOK___fixsfdi);
 | 
					        vpush_global_sym(&func_old_type, TOK___fixsfdi);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
 | 
				
			||||||
Boston, MA 02111-1307, USA.  
 | 
					Boston, MA 02111-1307, USA.  
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define W_TYPE_SIZE   32
 | 
					#define W_TYPE_SIZE   32
 | 
				
			||||||
#define BITS_PER_UNIT 8
 | 
					#define BITS_PER_UNIT 8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -480,7 +478,6 @@ long long __ashldi3(long long a, int b)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
 | 
					 | 
				
			||||||
long long __tcc_cvt_ftol(long double x)
 | 
					long long __tcc_cvt_ftol(long double x)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned c0, c1;
 | 
					    unsigned c0, c1;
 | 
				
			||||||
| 
						 | 
					@ -492,7 +489,6 @@ long long __tcc_cvt_ftol(long double x)
 | 
				
			||||||
    __asm__ __volatile__ ("fldcw %0" : : "m" (c0));
 | 
					    __asm__ __volatile__ ("fldcw %0" : : "m" (c0));
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* !__x86_64__ */
 | 
					#endif /* !__x86_64__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -641,21 +637,21 @@ long long __fixxfdi (long double a1)
 | 
				
			||||||
# include <stdlib.h>
 | 
					# include <stdlib.h>
 | 
				
			||||||
# include <stdio.h>
 | 
					# include <stdio.h>
 | 
				
			||||||
# include <string.h>
 | 
					# include <string.h>
 | 
				
			||||||
 | 
					# undef __va_start
 | 
				
			||||||
 | 
					# undef __va_arg
 | 
				
			||||||
 | 
					# undef __va_copy
 | 
				
			||||||
 | 
					# undef __va_end
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
/* Avoid including stdlib.h because it is not easily available when
 | 
					/* Avoid include files, they may not be available when cross compiling */
 | 
				
			||||||
   cross compiling */
 | 
					extern void *memset(void *s, int c, __SIZE_TYPE__ n);
 | 
				
			||||||
#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */
 | 
					 | 
				
			||||||
extern void *malloc(unsigned long long);
 | 
					 | 
				
			||||||
extern void *memset(void *s, int c, size_t n);
 | 
					 | 
				
			||||||
extern void free(void*);
 | 
					 | 
				
			||||||
extern void abort(void);
 | 
					extern void abort(void);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* This should be in sync with our include/stdarg.h */
 | 
				
			||||||
enum __va_arg_type {
 | 
					enum __va_arg_type {
 | 
				
			||||||
    __va_gen_reg, __va_float_reg, __va_stack
 | 
					    __va_gen_reg, __va_float_reg, __va_stack
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//This should be in sync with the declaration on our include/stdarg.h
 | 
					 | 
				
			||||||
/* GCC compatible definition of va_list. */
 | 
					/* GCC compatible definition of va_list. */
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    unsigned int gp_offset;
 | 
					    unsigned int gp_offset;
 | 
				
			||||||
| 
						 | 
					@ -667,11 +663,6 @@ typedef struct {
 | 
				
			||||||
    char *reg_save_area;
 | 
					    char *reg_save_area;
 | 
				
			||||||
} __va_list_struct;
 | 
					} __va_list_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef __va_start
 | 
					 | 
				
			||||||
#undef __va_arg
 | 
					 | 
				
			||||||
#undef __va_copy
 | 
					 | 
				
			||||||
#undef __va_end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void __va_start(__va_list_struct *ap, void *fp)
 | 
					void __va_start(__va_list_struct *ap, void *fp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    memset(ap, 0, sizeof(__va_list_struct));
 | 
					    memset(ap, 0, sizeof(__va_list_struct));
 | 
				
			||||||
| 
						 | 
					@ -705,33 +696,25 @@ void *__va_arg(__va_list_struct *ap,
 | 
				
			||||||
    case __va_stack:
 | 
					    case __va_stack:
 | 
				
			||||||
    use_overflow_area:
 | 
					    use_overflow_area:
 | 
				
			||||||
        ap->overflow_arg_area += size;
 | 
					        ap->overflow_arg_area += size;
 | 
				
			||||||
        ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align);
 | 
					        ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
 | 
				
			||||||
        return ap->overflow_arg_area - size;
 | 
					        return ap->overflow_arg_area - size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default:
 | 
					    default: /* should never happen */
 | 
				
			||||||
#ifndef __TINYC__
 | 
					#ifndef __TINYC__
 | 
				
			||||||
        fprintf(stderr, "unknown ABI type for __va_arg\n");
 | 
					        fprintf(stderr, "unknown ABI type for __va_arg\n");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        abort();
 | 
					        abort();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __x86_64__ */
 | 
					#endif /* __x86_64__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Flushing for tccrun */
 | 
					#ifdef TCC_TARGET_ARM
 | 
				
			||||||
#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void __clear_cache(void *beginning, void *end)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#elif defined(TCC_TARGET_ARM)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define _GNU_SOURCE
 | 
					#define _GNU_SOURCE
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
#include <sys/syscall.h>
 | 
					#include <sys/syscall.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Flushing for tccrun */
 | 
				
			||||||
void __clear_cache(void *beginning, void *end)
 | 
					void __clear_cache(void *beginning, void *end)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
 | 
					/* __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)
 | 
				
			||||||
             "ret");
 | 
					             "ret");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif /* arm */
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
#warning __clear_cache not defined for this architecture, avoid using tcc -run
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								tcc.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								tcc.h
									
										
									
									
									
								
							| 
						 | 
					@ -1312,6 +1312,7 @@ ST_DATA Section *last_text_section; /* to handle .previous asm directive */
 | 
				
			||||||
/* bound check related sections */
 | 
					/* bound check related sections */
 | 
				
			||||||
ST_DATA Section *bounds_section; /* contains global data bound description */
 | 
					ST_DATA Section *bounds_section; /* contains global data bound description */
 | 
				
			||||||
ST_DATA Section *lbounds_section; /* contains local data bound description */
 | 
					ST_DATA Section *lbounds_section; /* contains local data bound description */
 | 
				
			||||||
 | 
					ST_FUNC void tccelf_bounds_new(TCCState *s);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
/* symbol sections */
 | 
					/* symbol sections */
 | 
				
			||||||
ST_DATA Section *symtab_section, *strtab_section;
 | 
					ST_DATA Section *symtab_section, *strtab_section;
 | 
				
			||||||
| 
						 | 
					@ -1320,7 +1321,6 @@ ST_DATA Section *stab_section, *stabstr_section;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ST_FUNC void tccelf_new(TCCState *s);
 | 
					ST_FUNC void tccelf_new(TCCState *s);
 | 
				
			||||||
ST_FUNC void tccelf_delete(TCCState *s);
 | 
					ST_FUNC void tccelf_delete(TCCState *s);
 | 
				
			||||||
ST_FUNC void tccelf_bounds_new(TCCState *s);
 | 
					 | 
				
			||||||
ST_FUNC void tccelf_stab_new(TCCState *s);
 | 
					ST_FUNC void tccelf_stab_new(TCCState *s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
 | 
					ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								tccrun.c
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								tccrun.c
									
										
									
									
									
								
							| 
						 | 
					@ -255,7 +255,6 @@ static void set_pages_executable(void *ptr, unsigned long length)
 | 
				
			||||||
    unsigned long old_protect;
 | 
					    unsigned long old_protect;
 | 
				
			||||||
    VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
 | 
					    VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    extern void __clear_cache(void *beginning, void *end);
 | 
					 | 
				
			||||||
#ifndef PAGESIZE
 | 
					#ifndef PAGESIZE
 | 
				
			||||||
# define PAGESIZE 4096
 | 
					# define PAGESIZE 4096
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -263,11 +262,11 @@ static void set_pages_executable(void *ptr, unsigned long length)
 | 
				
			||||||
    start = (addr_t)ptr & ~(PAGESIZE - 1);
 | 
					    start = (addr_t)ptr & ~(PAGESIZE - 1);
 | 
				
			||||||
    end = (addr_t)ptr + length;
 | 
					    end = (addr_t)ptr + length;
 | 
				
			||||||
    end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
 | 
					    end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
 | 
				
			||||||
    mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
 | 
					    if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC))
 | 
				
			||||||
  #ifndef __PCC__
 | 
					        tcc_error("mprotect failed: did you mean to configure --with-selinux?");
 | 
				
			||||||
    __clear_cache(ptr, (char *)ptr + length);
 | 
					#if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64
 | 
				
			||||||
  #else
 | 
					    { extern void __clear_cache(void *beginning, void *end);
 | 
				
			||||||
    /* pcc 1.2.0.DEVEL 20141206 don't have such proc */
 | 
					      __clear_cache(ptr, (char *)ptr + length); }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								tcctok.h
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								tcctok.h
									
										
									
									
									
								
							| 
						 | 
					@ -242,11 +242,8 @@
 | 
				
			||||||
     DEF(TOK___fixsfdi, "__fixsfdi")
 | 
					     DEF(TOK___fixsfdi, "__fixsfdi")
 | 
				
			||||||
     DEF(TOK___fixdfdi, "__fixdfdi")
 | 
					     DEF(TOK___fixdfdi, "__fixdfdi")
 | 
				
			||||||
     DEF(TOK___fixxfdi, "__fixxfdi")
 | 
					     DEF(TOK___fixxfdi, "__fixxfdi")
 | 
				
			||||||
 | 
					 | 
				
			||||||
 #ifndef COMMIT_4ad186c5ef61_IS_FIXED
 | 
					 | 
				
			||||||
     DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
 | 
					     DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
					#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
				
			||||||
     DEF(TOK_alloca, "alloca")
 | 
					     DEF(TOK_alloca, "alloca")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue