From 73faaea227a53e365dd75f1dba7a5071c7b5e541 Mon Sep 17 00:00:00 2001 From: grischka Date: Wed, 28 Aug 2013 22:55:05 +0200 Subject: i386-gen: preserve fp control word in gen_cvt_ftoi - Use runtime function for conversion - Also initialize fp with tcc -run on windows This fixes a bug where double x = 1.0; double y = 1.0000000000000001; double z = x < y ? 0 : sqrt (x*x - y*y); caused a bad sqrt because rounding precision for the x < y comparison was different to the one used within the sqrt function. This also fixes a bug where printf("%d, %d", (int)pow(10, 2), (int)pow(10, 2)); would print 100, 99 Unrelated: win32: document relative include & lib lookup win32: normalize_slashes: do not mirror silly gcc behavior This reverts part of commit 8a81f9e1036637e21a47e14fb56bf64133546890 winapi: add missing WINAPI decl. for some functions --- lib/libtcc1.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 53dbec4..a94a82d 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -478,13 +478,24 @@ long long __ashldi3(long long a, int b) #endif } -#if defined(__i386__) -/* FPU control word for rounding to nearest mode */ -unsigned short __tcc_fpu_control = 0x137f; -/* FPU control word for round to zero mode for int conversion */ -unsigned short __tcc_int_fpu_control = 0x137f | 0x0c00; +#ifndef _WIN32 +void __tcc_fpinit(void) +{ + unsigned c = 0x137F; + __asm__ __volatile__ ("fldcw %0" : "=m" (c)); +} #endif - +long long __tcc_cvt_ftol(long double x) +{ + unsigned c0, c1; + long long ret; + __asm__ __volatile__ ("fnstcw %0" : "=m" (c0)); + c1 = c0 | 0x0C00; + __asm__ __volatile__ ("fldcw %0" : "=m" (c1)); + __asm__ __volatile__ ("fistpll %0" : "=m" (ret)); + __asm__ __volatile__ ("fldcw %0" : "=m" (c0)); + return ret; +} #endif /* !__x86_64__ */ /* XXX: fix tcc's code generator to do this instead */ -- cgit v1.3.1 From 235a65033f287a6207079875bf7f8bffb458daa1 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 7 Sep 2013 22:48:02 +0100 Subject: libtcc1.c: Fix __asm__() in __tcc_fpinit and __tcc_cvt_ftol Signed-off-by: Ramsay Jones --- lib/libtcc1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index a94a82d..a717701 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -482,7 +482,7 @@ long long __ashldi3(long long a, int b) void __tcc_fpinit(void) { unsigned c = 0x137F; - __asm__ __volatile__ ("fldcw %0" : "=m" (c)); + __asm__ __volatile__ ("fldcw %0" : : "m" (c)); } #endif long long __tcc_cvt_ftol(long double x) @@ -491,9 +491,9 @@ long long __tcc_cvt_ftol(long double x) long long ret; __asm__ __volatile__ ("fnstcw %0" : "=m" (c0)); c1 = c0 | 0x0C00; - __asm__ __volatile__ ("fldcw %0" : "=m" (c1)); + __asm__ __volatile__ ("fldcw %0" : : "m" (c1)); __asm__ __volatile__ ("fistpll %0" : "=m" (ret)); - __asm__ __volatile__ ("fldcw %0" : "=m" (c0)); + __asm__ __volatile__ ("fldcw %0" : : "m" (c0)); return ret; } #endif /* !__x86_64__ */ -- cgit v1.3.1 From fbb4841606b555311048229cf26de22ea5cf0682 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Thu, 28 Feb 2013 16:55:10 +0100 Subject: Add __clear_cache implementation in libtcc1 Add __clear_cache function for flushing caches to libtcc1. --- Makefile | 3 ++- lib/Makefile | 11 +++++++++++ lib/libtcc1.c | 24 +++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'lib/libtcc1.c') diff --git a/Makefile b/Makefile index 4a27364..ce151e1 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC -NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM -DWITHOUT_LIBTCC +NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP @@ -122,6 +122,7 @@ LIBTCC1=libtcc1.a else ifeq ($(ARCH),arm) NATIVE_FILES=$(ARM_FILES) PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS) +LIBTCC1=libtcc1.a endif ifeq ($(TARGETOS),Darwin) diff --git a/lib/Makefile b/lib/Makefile index 300fa46..dfd01c3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -24,6 +24,10 @@ ifndef TARGET ifneq ($(TARGETOS),Darwin) XCC = $(CC) endif + else + ifeq ($(ARCH),arm) + TARGET = arm + endif endif endif endif @@ -41,6 +45,7 @@ cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF) I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) X86_64_O = libtcc1.o alloca86_64.o +ARM_O = libtcc1.o WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o @@ -65,12 +70,18 @@ ifeq "$(TARGET)" "x86_64" OBJ = $(addprefix $(DIR)/,$(X86_64_O)) TGT = -DTCC_TARGET_X86_64 XCC ?= $(TCC) -B$(TOP) +else +ifeq "$(TARGET)" "arm" + OBJ = $(addprefix $(DIR)/,$(ARM_O)) + TGT = -DTCC_TARGET_ARM + XCC ?= $(TCC) -B$(TOP) else $(error libtcc1.a not supported on target '$(TARGET)') endif endif endif endif +endif XFLAGS = $(CPPFLAGS) $(CFLAGS) $(TGT) diff --git a/lib/libtcc1.c b/lib/libtcc1.c index a717701..3103691 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -107,7 +107,7 @@ union float_long { }; /* XXX: we don't support several builtin supports for now */ -#ifndef __x86_64__ +#if !defined(__x86_64__) && !defined(__arm__) /* XXX: use gcc/tcc intrinsic ? */ #if defined(__i386__) @@ -713,6 +713,28 @@ void __clear_cache(char *beginning, char *end) { } +#elif defined(__arm__) + +#define _GNU_SOURCE +#include +#include + +void __clear_cache(char *beginning, char *end) +{ +/* __ARM_NR_cacheflush is kernel private and should not be used in user space. + * However, there is no ARM asm parser in tcc so we use it for now */ +#if 1 + syscall(__ARM_NR_cacheflush); +#else + __asm__ ("push {r7}\n\t" + "mov r7, #0xf0002\n\t" + "mov r2, #0\n\t" + "swi 0\n\t" + "pop {r7}\n\t" + "ret"); +#endif +} + #else #warning __clear_cache not defined for this architecture, avoid using tcc -run #endif -- cgit v1.3.1 From 4ad186c5ef61477030ca37372f9d6c6d03681015 Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 6 Jan 2014 19:07:08 +0100 Subject: i386: use __fixdfdi instead of __tcc_cvt_ftol Variants __fixsfdi/__fixxfdi are not needed for now because the value is converted to double always. Also: - remove __tcc_fpinit for unix as it seems redundant by the __setfpucw call in the startup code - avoid reference to s->runtime_main in cross compilers - configure: fix --with-libgcc help - tcctok.h: cleanup --- configure | 2 +- i386-gen.c | 28 ++++++++----------- lib/libtcc1.c | 39 ++++++++++++++------------ tccelf.c | 4 +-- tccpe.c | 2 ++ tcctok.h | 89 ++++++++++++++++++++++++++++++----------------------------- 6 files changed, 84 insertions(+), 80 deletions(-) mode change 100755 => 100644 configure (limited to 'lib/libtcc1.c') diff --git a/configure b/configure old mode 100755 new mode 100644 index cc8ca5a..8c44e5c --- a/configure +++ b/configure @@ -273,7 +273,7 @@ Advanced options (experts only): --strip-binaries strip symbol tables from resulting binaries --disable-static make libtcc.so instead of libtcc.a --disable-rpath disable use of -rpath with the above - --with-libgcc use libgcc_s.so.1 instead of libtcc.a in dynamic link + --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link --enable-mingw32 build windows version on linux with mingw32 --enable-cygwin build windows version on windows with cygwin --enable-cross build cross compilers diff --git a/i386-gen.c b/i386-gen.c index 2eb6922..4c4a54b 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -581,14 +581,6 @@ ST_FUNC void gfunc_prolog(CType *func_type) func_bound_offset = lbounds_section->data_offset; } #endif - -#ifndef CONFIG_USE_LIBGCC -#ifndef TCC_TARGET_PE - if (0 == strcmp(funcname, "main")) - gen_static_call(TOK___tcc_fpinit); -#endif -#endif - } /* generate function epilog */ @@ -988,16 +980,20 @@ ST_FUNC void gen_cvt_itof(int t) } /* convert fp to int 't' type */ -/* XXX: handle long long case */ ST_FUNC void gen_cvt_ftoi(int t) { - gv(RC_FLOAT); - save_reg(TREG_EAX); - save_reg(TREG_EDX); - gen_static_call(TOK___tcc_cvt_ftol); - vtop->r = TREG_EAX; /* mark reg as used */ - if (t == VT_LLONG) - vtop->r2 = TREG_EDX; + int bt = vtop->type.t & VT_BTYPE; + if (bt == VT_FLOAT) + vpush_global_sym(&func_old_type, TOK___fixsfdi); + else if (bt == VT_LDOUBLE) + vpush_global_sym(&func_old_type, TOK___fixxfdi); + else + vpush_global_sym(&func_old_type, TOK___fixdfdi); + vswap(); + gfunc_call(1); + vpushi(0); + vtop->r = REG_IRET; + vtop->r2 = REG_LRET; } /* convert from one floating point type to another */ diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 3103691..44208cd 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -478,24 +478,6 @@ long long __ashldi3(long long a, int b) #endif } -#ifndef _WIN32 -void __tcc_fpinit(void) -{ - unsigned c = 0x137F; - __asm__ __volatile__ ("fldcw %0" : : "m" (c)); -} -#endif -long long __tcc_cvt_ftol(long double x) -{ - unsigned c0, c1; - long long ret; - __asm__ __volatile__ ("fnstcw %0" : "=m" (c0)); - c1 = c0 | 0x0C00; - __asm__ __volatile__ ("fldcw %0" : : "m" (c1)); - __asm__ __volatile__ ("fistpll %0" : "=m" (ret)); - __asm__ __volatile__ ("fldcw %0" : : "m" (c0)); - return ret; -} #endif /* !__x86_64__ */ /* XXX: fix tcc's code generator to do this instead */ @@ -616,6 +598,27 @@ unsigned long long __fixunsxfdi (long double a1) return 0; } +long long __fixsfdi (float a1) +{ + long long ret; int s; + ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1); + return s ? ret : -ret; +} + +long long __fixdfdi (double a1) +{ + long long ret; int s; + ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1); + return s ? ret : -ret; +} + +long long __fixxfdi (long double a1) +{ + long long ret; int s; + ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1); + return s ? ret : -ret; +} + #if defined(__x86_64__) && !defined(_WIN64) #ifndef __TINYC__ diff --git a/tccelf.c b/tccelf.c index caa8281..aa3daac 100644 --- a/tccelf.c +++ b/tccelf.c @@ -178,11 +178,11 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name) return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0); } -#ifdef TCC_IS_NATIVE +#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE /* return elf symbol value or error */ ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name) { - return (void*)get_elf_sym_addr(s, name, 1); + return (void*)(uintptr_t)get_elf_sym_addr(s, name, 1); } #endif diff --git a/tccpe.c b/tccpe.c index bc1545e..62df865 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1800,7 +1800,9 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) if (TCC_OUTPUT_MEMORY == s1->output_type) { pe_type = PE_RUN; +#ifdef TCC_IS_NATIVE s1->runtime_main = start_symbol; +#endif } else { pe->start_addr = (DWORD)tcc_get_symbol_err(s1, start_symbol); } diff --git a/tcctok.h b/tcctok.h index 9b47a60..73b0cf9 100644 --- a/tcctok.h +++ b/tcctok.h @@ -143,23 +143,34 @@ #endif /* builtin functions or variables */ -#ifdef TCC_ARM_EABI - DEF(TOK_memcpy, "__aeabi_memcpy") - DEF(TOK_memcpy4, "__aeabi_memcpy4") - DEF(TOK_memcpy8, "__aeabi_memcpy8") - DEF(TOK_memset, "__aeabi_memset") - DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod") - DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod") -#else +#ifndef TCC_ARM_EABI DEF(TOK_memcpy, "memcpy") DEF(TOK_memset, "memset") DEF(TOK___divdi3, "__divdi3") DEF(TOK___moddi3, "__moddi3") DEF(TOK___udivdi3, "__udivdi3") DEF(TOK___umoddi3, "__umoddi3") + DEF(TOK___ashrdi3, "__ashrdi3") + DEF(TOK___lshrdi3, "__lshrdi3") + DEF(TOK___ashldi3, "__ashldi3") + DEF(TOK___floatundisf, "__floatundisf") + DEF(TOK___floatundidf, "__floatundidf") +# ifndef TCC_ARM_VFP + DEF(TOK___floatundixf, "__floatundixf") + DEF(TOK___fixunsxfdi, "__fixunsxfdi") +# endif + DEF(TOK___fixunssfdi, "__fixunssfdi") + DEF(TOK___fixunsdfdi, "__fixunsdfdi") #endif -#if defined(TCC_TARGET_ARM) -#ifdef TCC_ARM_EABI + +#if defined TCC_TARGET_ARM +# ifdef TCC_ARM_EABI + DEF(TOK_memcpy, "__aeabi_memcpy") + DEF(TOK_memcpy4, "__aeabi_memcpy4") + DEF(TOK_memcpy8, "__aeabi_memcpy8") + DEF(TOK_memset, "__aeabi_memset") + DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod") + DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod") DEF(TOK___aeabi_idivmod, "__aeabi_idivmod") DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod") DEF(TOK___divsi3, "__aeabi_idiv") @@ -168,24 +179,33 @@ DEF(TOK___floatdidf, "__aeabi_l2d") DEF(TOK___fixsfdi, "__aeabi_f2lz") DEF(TOK___fixdfdi, "__aeabi_d2lz") -#else + DEF(TOK___ashrdi3, "__aeabi_lasr") + DEF(TOK___lshrdi3, "__aeabi_llsr") + DEF(TOK___ashldi3, "__aeabi_llsl") + DEF(TOK___floatundisf, "__aeabi_ul2f") + DEF(TOK___floatundidf, "__aeabi_ul2d") + DEF(TOK___fixunssfdi, "__aeabi_f2ulz") + DEF(TOK___fixunsdfdi, "__aeabi_d2ulz") +# else DEF(TOK___modsi3, "__modsi3") DEF(TOK___umodsi3, "__umodsi3") DEF(TOK___divsi3, "__divsi3") DEF(TOK___udivsi3, "__udivsi3") DEF(TOK___floatdisf, "__floatdisf") DEF(TOK___floatdidf, "__floatdidf") -#ifndef TCC_ARM_VFP +# ifndef TCC_ARM_VFP DEF(TOK___floatdixf, "__floatdixf") DEF(TOK___fixunssfsi, "__fixunssfsi") DEF(TOK___fixunsdfsi, "__fixunsdfsi") DEF(TOK___fixunsxfsi, "__fixunsxfsi") DEF(TOK___fixxfdi, "__fixxfdi") -#endif +# endif DEF(TOK___fixsfdi, "__fixsfdi") DEF(TOK___fixdfdi, "__fixdfdi") +# endif #endif -#elif defined(TCC_TARGET_C67) + +#if defined TCC_TARGET_C67 DEF(TOK__divi, "_divi") DEF(TOK__divu, "_divu") DEF(TOK__divf, "_divf") @@ -193,32 +213,18 @@ DEF(TOK__remi, "_remi") DEF(TOK__remu, "_remu") #endif -#ifdef TCC_TARGET_I386 - DEF(TOK___tcc_fpinit, "__tcc_fpinit") - DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol") -#endif -#ifdef TCC_ARM_EABI - DEF(TOK___ashrdi3, "__aeabi_lasr") - DEF(TOK___lshrdi3, "__aeabi_llsr") - DEF(TOK___ashldi3, "__aeabi_llsl") - DEF(TOK___floatundisf, "__aeabi_ul2f") - DEF(TOK___floatundidf, "__aeabi_ul2d") - DEF(TOK___fixunssfdi, "__aeabi_f2ulz") - DEF(TOK___fixunsdfdi, "__aeabi_d2ulz") -#else - DEF(TOK___ashrdi3, "__ashrdi3") - DEF(TOK___lshrdi3, "__lshrdi3") - DEF(TOK___ashldi3, "__ashldi3") - DEF(TOK___floatundisf, "__floatundisf") - DEF(TOK___floatundidf, "__floatundidf") -#ifndef TCC_ARM_VFP - DEF(TOK___floatundixf, "__floatundixf") - DEF(TOK___fixunsxfdi, "__fixunsxfdi") + +#if defined TCC_TARGET_I386 + DEF(TOK___fixsfdi, "__fixsfdi") + DEF(TOK___fixdfdi, "__fixdfdi") + DEF(TOK___fixxfdi, "__fixxfdi") #endif - DEF(TOK___fixunssfdi, "__fixunssfdi") - DEF(TOK___fixunsdfdi, "__fixunsdfdi") + +#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 + DEF(TOK_alloca, "alloca") #endif -#ifdef TCC_TARGET_PE + +#if defined TCC_TARGET_PE DEF(TOK___chkstk, "__chkstk") #endif @@ -233,20 +239,17 @@ DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16") DEF(TOK___bound_local_new, "__bound_local_new") DEF(TOK___bound_local_delete, "__bound_local_delete") -#ifdef TCC_TARGET_PE +# ifdef TCC_TARGET_PE DEF(TOK_malloc, "malloc") DEF(TOK_free, "free") DEF(TOK_realloc, "realloc") DEF(TOK_memalign, "memalign") DEF(TOK_calloc, "calloc") -#endif +# endif DEF(TOK_memmove, "memmove") DEF(TOK_strlen, "strlen") DEF(TOK_strcpy, "strcpy") #endif -#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 - DEF(TOK_alloca, "alloca") -#endif /* Tiny Assembler */ DEF_ASM(byte) -- cgit v1.3.1 From e50f08faa19d66f2d2fd0e3bab4dda3852100d72 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 9 Mar 2014 22:15:01 +0800 Subject: Make condition in libtcc1 based on target Prior to this commit runtime library was compiled according to the host because of the macro used to detec what architecture to choose. This commit fixes this by using the TARGET_* macro instead. --- lib/libtcc1.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 44208cd..cf9babf 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -107,10 +107,10 @@ union float_long { }; /* XXX: we don't support several builtin supports for now */ -#if !defined(__x86_64__) && !defined(__arm__) +#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM) /* XXX: use gcc/tcc intrinsic ? */ -#if defined(__i386__) +#if defined(TCC_TARGET_I386) #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ : "=r" ((USItype) (sh)), \ @@ -619,7 +619,7 @@ long long __fixxfdi (long double a1) return s ? ret : -ret; } -#if defined(__x86_64__) && !defined(_WIN64) +#if defined(TCC_TARGET_X86_64) && !defined(_WIN64) #ifndef __TINYC__ #include @@ -710,13 +710,13 @@ void __va_end(struct __va_list_struct *ap) #endif /* __x86_64__ */ /* Flushing for tccrun */ -#if defined(__x86_64__) || defined(__i386__) +#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386) void __clear_cache(char *beginning, char *end) { } -#elif defined(__arm__) +#elif defined(TCC_TARGET_ARM) #define _GNU_SOURCE #include -- cgit v1.3.1 From 73ac39c317a20accaf3b25ba833deee0c2e2849f Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 9 Mar 2014 22:21:27 +0800 Subject: Undefine __va* in libtcc1 to avoid errors w/ clang --- lib/libtcc1.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index cf9babf..b46fb5d 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -647,6 +647,11 @@ struct __va_list_struct { char *reg_save_area; }; +#undef __va_start +#undef __va_arg +#undef __va_copy +#undef __va_end + void *__va_start(void *fp) { struct __va_list_struct *ap = -- cgit v1.3.1 From 98afe11c85ad4834c05fffb226d6b9e7926f4f88 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 9 Mar 2014 22:22:43 +0800 Subject: Use intptr_t to cast pointer --- lib/libtcc1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index b46fb5d..067592c 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -28,6 +28,8 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #define W_TYPE_SIZE 32 #define BITS_PER_UNIT 8 @@ -688,7 +690,7 @@ void *__va_arg(struct __va_list_struct *ap, case __va_stack: use_overflow_area: ap->overflow_arg_area += size; - ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -(long long)align); + ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align); return ap->overflow_arg_area - size; default: -- cgit v1.3.1 From 40e38597391aa05a61cef1c36e844690665c411a Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 11 Mar 2014 22:57:22 +0800 Subject: Fix __clear_cache implementation Forgot to give the parameters to syscall function, doh! --- lib/libtcc1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/libtcc1.c') diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 067592c..a5896a4 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -728,13 +728,14 @@ void __clear_cache(char *beginning, char *end) #define _GNU_SOURCE #include #include +#include void __clear_cache(char *beginning, char *end) { /* __ARM_NR_cacheflush is kernel private and should not be used in user space. * However, there is no ARM asm parser in tcc so we use it for now */ #if 1 - syscall(__ARM_NR_cacheflush); + syscall(__ARM_NR_cacheflush, beginning, end, 0); #else __asm__ ("push {r7}\n\t" "mov r7, #0xf0002\n\t" -- cgit v1.3.1 From c025478d7c03eb8d32022f1aec4537bd0a75a743 Mon Sep 17 00:00:00 2001 From: mingodad Date: Fri, 28 Mar 2014 20:28:19 +0000 Subject: New implementation of va_list/va_start/var_copy that do not use dynamic memory, with this when compiling fossil-scm with tcc on linux X86_64 it works fine. --- include/stdarg.h | 32 +++++++++++++++++++++----------- lib/libtcc1.c | 30 +++++++++--------------------- 2 files changed, 30 insertions(+), 32 deletions(-) (limited to 'lib/libtcc1.c') diff --git a/include/stdarg.h b/include/stdarg.h index 3c1318e..b6a30f7 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -4,18 +4,28 @@ #ifdef __x86_64__ #ifndef _WIN64 -typedef void *va_list; - -va_list __va_start(void *fp); -void *__va_arg(va_list ap, int arg_type, int size, int align); -va_list __va_copy(va_list src); -void __va_end(va_list ap); - -#define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0))) +//This should be in sync with the declaration on our lib/libtcc1.c +/* GCC compatible definition of va_list. */ +typedef struct { + unsigned int gp_offset; + unsigned int fp_offset; + union { + unsigned int overflow_offset; + char *overflow_arg_area; + }; + char *reg_save_area; +} __va_list_struct; + +typedef __va_list_struct va_list; + +void __va_start(__va_list_struct *ap, void *fp); +void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); + +#define va_start(ap, last) __va_start(&ap, __builtin_frame_address(0)) #define va_arg(ap, type) \ - (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) -#define va_copy(dest, src) ((dest) = __va_copy(src)) -#define va_end(ap) __va_end(ap) + (*(type *)(__va_arg(&ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) +#define va_copy(dest, src) ((dest) = (src)) +#define va_end(ap) #else /* _WIN64 */ typedef char *va_list; diff --git a/lib/libtcc1.c b/lib/libtcc1.c index a5896a4..284965e 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -626,10 +626,12 @@ long long __fixxfdi (long double a1) #ifndef __TINYC__ #include #include +#include #else /* Avoid including stdlib.h because it is not easily available when cross compiling */ extern void *malloc(unsigned long long); +void *memset(void *s, int c, size_t n); extern void free(void*); extern void abort(void); #endif @@ -638,8 +640,9 @@ enum __va_arg_type { __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. */ -struct __va_list_struct { +typedef struct { unsigned int gp_offset; unsigned int fp_offset; union { @@ -647,24 +650,22 @@ struct __va_list_struct { char *overflow_arg_area; }; char *reg_save_area; -}; +} __va_list_struct; #undef __va_start #undef __va_arg #undef __va_copy #undef __va_end -void *__va_start(void *fp) +void __va_start(__va_list_struct *ap, void *fp) { - struct __va_list_struct *ap = - (struct __va_list_struct *)malloc(sizeof(struct __va_list_struct)); - *ap = *(struct __va_list_struct *)((char *)fp - 16); + memset(ap, 0, sizeof(__va_list_struct)); + *ap = *(__va_list_struct *)((char *)fp - 16); ap->overflow_arg_area = (char *)fp + ap->overflow_offset; ap->reg_save_area = (char *)fp - 176 - 16; - return ap; } -void *__va_arg(struct __va_list_struct *ap, +void *__va_arg(__va_list_struct *ap, enum __va_arg_type arg_type, int size, int align) { @@ -701,19 +702,6 @@ void *__va_arg(struct __va_list_struct *ap, } } -void *__va_copy(struct __va_list_struct *src) -{ - struct __va_list_struct *dest = - (struct __va_list_struct *)malloc(sizeof(struct __va_list_struct)); - *dest = *src; - return dest; -} - -void __va_end(struct __va_list_struct *ap) -{ - free(ap); -} - #endif /* __x86_64__ */ /* Flushing for tccrun */ -- cgit v1.3.1