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') 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') 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') 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 f2dbcf7594887ddfdec646ab2a85f4e2358ec209 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 7 Apr 2013 17:02:57 +0200 Subject: Add ARM aeabi functions needed to run tcctest Add implementation for float / integer conversion functions: __aeabi_d2lz, __aeabi_d2ulz, __aeabi_f2lz, __aeabi_f2ulz, __aeabi_l2d, __aeabi_l2f, __aeabi_ul2d, __aeabi_ul2f Add implementation for long long helper functions: __aeabi_ldivmod, __aeabi_uldivmod, __aeabi_llsl, __aeabi_llsr, __aeabi_lasr Add implementation for integer division functions: __aeabi_uidiv, __aeabi_uidivmod, __aeabi_idiv, __aeabi_idivmod, --- lib/Makefile | 2 +- lib/armeabi.c | 441 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/tcctest.c | 67 +++++++++ 3 files changed, 509 insertions(+), 1 deletion(-) create mode 100644 lib/armeabi.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index dfd01c3..a8a2b5d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -45,7 +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 +ARM_O = libtcc1.o armeabi.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 diff --git a/lib/armeabi.c b/lib/armeabi.c new file mode 100644 index 0000000..c00ace6 --- /dev/null +++ b/lib/armeabi.c @@ -0,0 +1,441 @@ +#include + +/* We rely on the little endianness and EABI calling convention for this to + work */ + +typedef struct double_unsigned_struct { + unsigned low; + unsigned high; +} double_unsigned_struct; + +typedef struct unsigned_int_struct { + unsigned low; + int high; +} unsigned_int_struct; + +#define REGS_RETURN(name, type) \ + void name ## _return(type ret) {} + + +/* Float helper functions */ + +#define FLOAT_EXP_BITS 8 +#define FLOAT_FRAC_BITS 23 + +#define DOUBLE_EXP_BITS 11 +#define DOUBLE_FRAC_BITS 52 + +#define ONE_EXP(type) ((1 << (type ## _EXP_BITS - 1)) - 1) + +REGS_RETURN(unsigned_int_struct, unsigned_int_struct) +REGS_RETURN(double_unsigned_struct, double_unsigned_struct) + +/* float -> integer: (sign) 1.fraction x 2^(exponent - exp_for_one) */ + + +/* float to [unsigned] long long conversion */ +#define DEFINE__AEABIT_F2XLZ(name, with_sign) \ +void __aeabi_ ## name(unsigned val) \ +{ \ + int exp, high_shift, sign; \ + double_unsigned_struct ret; \ + \ + /* compute sign */ \ + sign = val >> 31; \ + \ + /* compute real exponent */ \ + exp = val >> FLOAT_FRAC_BITS; \ + exp &= (1 << FLOAT_EXP_BITS) - 1; \ + exp -= ONE_EXP(FLOAT); \ + \ + /* undefined behavior if truncated value cannot be represented */ \ + if (with_sign) { \ + if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ + return; \ + } else { \ + if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ + return; \ + } \ + \ + val &= (1 << FLOAT_FRAC_BITS) - 1; \ + if (exp >= 32) { \ + ret.high = 1 << (exp - 32); \ + if (exp - 32 >= FLOAT_FRAC_BITS) { \ + ret.high |= val << (exp - 32 - FLOAT_FRAC_BITS); \ + ret.low = 0; \ + } else { \ + high_shift = FLOAT_FRAC_BITS - (exp - 32); \ + ret.high |= val >> high_shift; \ + ret.low = val << (32 - high_shift); \ + } \ + } else { \ + ret.high = 0; \ + ret.low = 1 << exp; \ + if (exp > FLOAT_FRAC_BITS) \ + ret.low |= val << (exp - FLOAT_FRAC_BITS); \ + else \ + ret.low = val >> (FLOAT_FRAC_BITS - exp); \ + } \ + \ + /* encode negative integer using 2's complement */ \ + if (with_sign && sign) { \ + ret.low = ~ret.low; \ + ret.high = ~ret.high; \ + if (ret.low == UINT_MAX) { \ + ret.low = 0; \ + ret.high++; \ + } else \ + ret.low++; \ + } \ + \ + double_unsigned_struct_return(ret); \ +} + +/* float to unsigned long long conversion */ +DEFINE__AEABIT_F2XLZ(f2ulz, 0) + +/* float to long long conversion */ +DEFINE__AEABIT_F2XLZ(f2lz, 1) + +/* double to [unsigned] long long conversion */ +#define DEFINE__AEABIT_D2XLZ(name, with_sign) \ +void __aeabi_ ## name(double_unsigned_struct val) \ +{ \ + int exp, high_shift, sign; \ + double_unsigned_struct ret; \ + \ + /* compute sign */ \ + sign = val.high >> 31; \ + \ + /* compute real exponent */ \ + exp = (val.high >> (DOUBLE_FRAC_BITS - 32)); \ + exp &= (1 << DOUBLE_EXP_BITS) - 1; \ + exp -= ONE_EXP(DOUBLE); \ + \ + /* undefined behavior if truncated value cannot be represented */ \ + if (with_sign) { \ + if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ + return; \ + } else { \ + if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ + return; \ + } \ + \ + val.high &= (1 << (DOUBLE_FRAC_BITS - 32)) - 1; \ + if (exp >= 32) { \ + ret.high = 1 << (exp - 32); \ + if (exp >= DOUBLE_FRAC_BITS) { \ + high_shift = exp - DOUBLE_FRAC_BITS; \ + ret.high |= val.high << high_shift; \ + ret.high |= val.low >> (32 - high_shift); \ + ret.low = val.low << high_shift; \ + } else { \ + high_shift = DOUBLE_FRAC_BITS - exp; \ + ret.high |= val.high >> high_shift; \ + ret.low = val.high << (32 - high_shift); \ + ret.low |= val.low >> high_shift; \ + } \ + } else { \ + ret.high = 0; \ + ret.low = 1 << exp; \ + if (exp > DOUBLE_FRAC_BITS - 32) { \ + high_shift = exp - DOUBLE_FRAC_BITS - 32; \ + ret.low |= val.high << high_shift; \ + ret.low |= val.low >> (32 - high_shift); \ + } else \ + ret.low = val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ + } \ + \ + /* encode negative integer using 2's complement */ \ + if (with_sign && sign) { \ + ret.low = ~ret.low; \ + ret.high = ~ret.high; \ + if (ret.low == UINT_MAX) { \ + ret.low = 0; \ + ret.high++; \ + } else \ + ret.low++; \ + } \ + \ + double_unsigned_struct_return(ret); \ +} + +/* double to unsigned long long conversion */ +DEFINE__AEABIT_D2XLZ(d2ulz, 0) + +/* double to long long conversion */ +DEFINE__AEABIT_D2XLZ(d2lz, 1) + +/* long long to float conversion */ +#define DEFINE__AEABI_XL2F(name, with_sign) \ +unsigned __aeabi_ ## name(unsigned long long v) \ +{ \ + int s /* shift */, sign = 0; \ + unsigned p = 0 /* power */, ret; \ + double_unsigned_struct val; \ + \ + /* fraction in negative float is encoded in 1's complement */ \ + if (with_sign && (v & (1 << 63))) { \ + sign = 1; \ + v = ~v + 1; \ + } \ + val.low = v; \ + val.high = v >> 32; \ + /* fill fraction bits */ \ + for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ + if (p) { \ + ret = val.high & (p - 1); \ + if (s < FLOAT_FRAC_BITS) { \ + ret <<= FLOAT_FRAC_BITS - s; \ + ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \ + } else \ + ret >>= s - FLOAT_FRAC_BITS; \ + s += 32; \ + } else { \ + for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ + if (p) { \ + ret = val.low & (p - 1); \ + if (s <= FLOAT_FRAC_BITS) \ + ret <<= FLOAT_FRAC_BITS - s; \ + else \ + ret >>= s - FLOAT_FRAC_BITS; \ + } else \ + return 0; \ + } \ + \ + /* fill exponent bits */ \ + ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \ + \ + /* fill sign bit */ \ + ret |= sign << 31; \ + \ + return ret; \ +} + +/* unsigned long long to float conversion */ +DEFINE__AEABI_XL2F(ul2f, 0) + +/* long long to float conversion */ +DEFINE__AEABI_XL2F(l2f, 0) + +/* long long to double conversion */ +#define __AEABI_XL2D(name, with_sign) \ +void __aeabi_ ## name(unsigned long long v) \ +{ \ + int s, high_shift, sign = 0; \ + unsigned tmp, p = 0; \ + double_unsigned_struct val, ret; \ + \ + /* fraction in negative float is encoded in 1's complement */ \ + if (with_sign && (v & (1ULL << 63))) { \ + sign = 1; \ + v = ~v + 1; \ + } \ + val.low = v; \ + val.high = v >> 32; \ + \ + /* fill fraction bits */ \ + for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ + if (p) { \ + tmp = val.high & (p - 1); \ + if (s < DOUBLE_FRAC_BITS - 32) { \ + high_shift = DOUBLE_FRAC_BITS - 32 - s; \ + ret.high = tmp << high_shift; \ + ret.high |= val.low >> (32 - high_shift); \ + ret.low = val.low << high_shift; \ + } else { \ + high_shift = s - (DOUBLE_FRAC_BITS - 32); \ + ret.high = tmp >> high_shift; \ + ret.low = tmp << (32 - high_shift); \ + ret.low |= val.low >> high_shift; \ + } \ + s += 32; \ + } else { \ + for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ + if (p) { \ + tmp = val.low & (p - 1); \ + if (s <= DOUBLE_FRAC_BITS - 32) { \ + high_shift = DOUBLE_FRAC_BITS - 32 - s; \ + ret.high = tmp << high_shift; \ + ret.low = 0; \ + } else { \ + high_shift = s - (DOUBLE_FRAC_BITS - 32); \ + ret.high = tmp >> high_shift; \ + ret.low = tmp << (32 - high_shift); \ + } \ + } else { \ + ret.high = ret.low = 0; \ + double_unsigned_struct_return(ret); \ + } \ + } \ + \ + /* fill exponent bits */ \ + ret.high |= (s + ONE_EXP(DOUBLE)) << (DOUBLE_FRAC_BITS - 32); \ + \ + /* fill sign bit */ \ + ret.high |= sign << 31; \ + \ + double_unsigned_struct_return(ret); \ +} + +/* unsigned long long to double conversion */ +__AEABI_XL2D(ul2d, 0) + +/* long long to double conversion */ +__AEABI_XL2D(l2d, 1) + + +/* Long long helper functions */ + +/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */ + +#define define_aeabi_xdivmod_signed_type(basetype, type) \ +typedef struct type { \ + basetype quot; \ + unsigned basetype rem; \ +} type + +#define define_aeabi_xdivmod_unsigned_type(basetype, type) \ +typedef struct type { \ + basetype quot; \ + basetype rem; \ +} type + +#define AEABI_UXDIVMOD(name,type, rettype, typemacro) \ +static inline rettype aeabi_ ## name (type num, type den) \ +{ \ + rettype ret; \ + type quot = 0; \ + \ + /* Increase quotient while it is less than numerator */ \ + while (num >= den) { \ + type q = 1; \ + \ + /* Find closest power of two */ \ + while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \ + q <<= 1; \ + \ + /* Compute difference between current quotient and numerator */ \ + num -= q * den; \ + quot += q; \ + } \ + ret.quot = quot; \ + ret.rem = num; \ + return ret; \ +} + +#define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ +void __aeabi_ ## name(type numerator, type denominator) \ +{ \ + unsigned type num, den; \ + urettype uxdiv_ret; \ + rettype ret; \ + \ + num = numerator & typemacro ## _MAX; \ + den = denominator & typemacro ## _MAX; \ + uxdiv_ret = aeabi_ ## uiname(num, den); \ + /* signs differ */ \ + if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ + ret.quot = uxdiv_ret.quot * -1; \ + else \ + ret.quot = uxdiv_ret.quot; \ + if (numerator & typemacro ## _MIN) \ + ret.rem = uxdiv_ret.rem * -1; \ + else \ + ret.rem = uxdiv_ret.rem; \ + \ + rettype ## _return(ret); \ +} + +define_aeabi_xdivmod_signed_type(long long, lldiv_t); +define_aeabi_xdivmod_unsigned_type(unsigned long long, ulldiv_t); +define_aeabi_xdivmod_signed_type(int, idiv_t); +define_aeabi_xdivmod_unsigned_type(unsigned, uidiv_t); + +REGS_RETURN(lldiv_t, lldiv_t) +REGS_RETURN(ulldiv_t, ulldiv_t) +REGS_RETURN(idiv_t, idiv_t) +REGS_RETURN(uidiv_t, uidiv_t) + +AEABI_UXDIVMOD(uldivmod, unsigned long long, ulldiv_t, ULONG) + +__AEABI_XDIVMOD(ldivmod, long long, uldivmod, lldiv_t, ulldiv_t, LLONG) + +void __aeabi_uldivmod(unsigned long long num, unsigned long long den) +{ + ulldiv_t_return(aeabi_uldivmod(num, den)); +} + +void __aeabi_llsl(double_unsigned_struct val, int shift) +{ + double_unsigned_struct ret; + + if (shift >= 32) { + val.high = val.low; + val.low = 0; + shift -= 32; + } + if (shift > 0) { + ret.low = val.low << shift; + ret.high = (val.high << shift) | (val.low >> (32 - shift)); + double_unsigned_struct_return(ret); + return; + } + double_unsigned_struct_return(val); +} + +#define aeabi_lsr(val, shift, fill, type) \ + type ## _struct ret; \ + \ + if (shift >= 32) { \ + val.low = val.high; \ + val.high = fill; \ + shift -= 32; \ + } \ + if (shift > 0) { \ + ret.high = val.high >> shift; \ + ret.low = (val.high << (32 - shift)) | (val.low >> shift); \ + type ## _struct_return(ret); \ + return; \ + } \ + type ## _struct_return(val); + +void __aeabi_llsr(double_unsigned_struct val, int shift) +{ + aeabi_lsr(val, shift, 0, double_unsigned); +} + +void __aeabi_lasr(unsigned_int_struct val, int shift) +{ + aeabi_lsr(val, shift, val.high >> 31, unsigned_int); +} + + +/* Integer division functions */ + +AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT) + +int __aeabi_idiv(int numerator, int denominator) +{ + unsigned num, den; + uidiv_t ret; + + num = numerator & INT_MAX; + den = denominator & INT_MAX; + ret = aeabi_uidivmod(num, den); + if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ + ret.quot *= -1; + return ret.quot; +} + +unsigned __aeabi_uidiv(unsigned num, unsigned den) +{ + return aeabi_uidivmod(num, den).quot; +} + +__AEABI_XDIVMOD(idivmod, int, uidivmod, idiv_t, uidiv_t, INT) + +void __aeabi_uidivmod(unsigned num, unsigned den) +{ + uidiv_t_return(aeabi_uidivmod(num, den)); +} diff --git a/tests/tcctest.c b/tests/tcctest.c index c5a3e73..eb284f0 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -59,6 +59,7 @@ #include "tcclib.h" +void intdiv_test(); void string_test(); void expr_test(); void macro_test(); @@ -167,6 +168,71 @@ int qq(int x) #define wq_spin_lock spin_lock #define TEST2() wq_spin_lock(a) +#define UINT_MAX ((unsigned) -1) + +void intdiv_test(void) +{ + printf("18/21=%u\n", 18/21); + printf("18%21=%u\n", 18%21); + printf("41/21=%u\n", 41/21); + printf("41%21=%u\n", 41%21); + printf("42/21=%u\n", 42/21); + printf("42%21=%u\n", 42%21); + printf("43/21=%u\n", 43/21); + printf("43%21=%u\n", 43%21); + printf("126/21=%u\n", 126/21); + printf("12%/21=%u\n", 126%21); + printf("131/21=%u\n", 131/21); + printf("131%21=%u\n", 131%21); + printf("(UINT_MAX/2+3)/2=%u\n", (UINT_MAX/2+3)/2); + printf("(UINT_MAX/2+3)%2=%u\n", (UINT_MAX/2+3)%2); + + printf("18/-21=%u\n", 18/-21); + printf("18%-21=%u\n", 18%-21); + printf("41/-21=%u\n", 41/-21); + printf("41%-21=%u\n", 41%-21); + printf("42/-21=%u\n", 42/-21); + printf("42%-21=%u\n", 42%-21); + printf("43/-21=%u\n", 43/-21); + printf("43%-21=%u\n", 43%-21); + printf("126/-21=%u\n", 126/-21); + printf("12%/-21=%u\n", 126%-21); + printf("131/-21=%u\n", 131/-21); + printf("131%-21=%u\n", 131%-21); + printf("(UINT_MAX/2+3)/-2=%u\n", (UINT_MAX/2+3)/-2); + printf("(UINT_MAX/2+3)%-2=%u\n", (UINT_MAX/2+3)%-2); + + printf("-18/21=%u\n", -18/21); + printf("-18%21=%u\n", -18%21); + printf("-41/21=%u\n", -41/21); + printf("-41%21=%u\n", -41%21); + printf("-42/21=%u\n", -42/21); + printf("-42%21=%u\n", -42%21); + printf("-43/21=%u\n", -43/21); + printf("-43%21=%u\n", -43%21); + printf("-126/21=%u\n", -126/21); + printf("-12%/21=%u\n", -126%21); + printf("-131/21=%u\n", -131/21); + printf("-131%21=%u\n", -131%21); + printf("-(UINT_MAX/2+3)/2=%u\n", (0-(UINT_MAX/2+3))/2); + printf("-(UINT_MAX/2+3)%2=%u\n", (0-(UINT_MAX/2+3))%2); + + printf("-18/-21=%u\n", -18/-21); + printf("-18%-21=%u\n", -18%-21); + printf("-41/-21=%u\n", -41/-21); + printf("-41%-21=%u\n", -41%-21); + printf("-42/-21=%u\n", -42/-21); + printf("-42%-21=%u\n", -42%-21); + printf("-43/-21=%u\n", -43/-21); + printf("-43%-21=%u\n", -43%-21); + printf("-126/-21=%u\n", -126/-21); + printf("-12%/-21=%u\n", -126%-21); + printf("-131/-21=%u\n", -131/-21); + printf("-131%-21=%u\n", -131%-21); + printf("-(UINT_MAX/2+3)/-2=%u\n", (0-(UINT_MAX/2+3))/-2); + printf("-(UINT_MAX/2+3)%-2=%u\n", (0-(UINT_MAX/2+3))%-2); +} + void macro_test(void) { printf("macro:\n"); @@ -619,6 +685,7 @@ int main(int argc, char **argv) math_cmp_test(); callsave_test(); builtin_frame_address_test(); + intdiv_test(); return 0; } -- cgit v1.3.1 From a24e31e85d2980bf4863ad3dd371c6501810ae97 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 15 Dec 2013 09:44:20 +0800 Subject: Fix signed integer division in ARM runtime ABI - fix computation of absolute value (clearing the sign bit does not since integers are encoded in 2's complement) - test sign of integer in a more conventional way (binary and with the high bit does not work for long long due to a bug in gtst) - spacing in include --- lib/armeabi.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/armeabi.c b/lib/armeabi.c index c00ace6..e787ec1 100644 --- a/lib/armeabi.c +++ b/lib/armeabi.c @@ -1,4 +1,4 @@ -#include +#include /* We rely on the little endianness and EABI calling convention for this to work */ @@ -325,22 +325,28 @@ static inline rettype aeabi_ ## name (type num, type den) \ } #define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ -void __aeabi_ ## name(type numerator, type denominator) \ +void __aeabi_ ## name(type numerator, type denominator) \ { \ unsigned type num, den; \ urettype uxdiv_ret; \ rettype ret; \ \ - num = numerator & typemacro ## _MAX; \ - den = denominator & typemacro ## _MAX; \ + if (numerator >= 0) \ + num = numerator; \ + else \ + num = 0 - numerator; \ + if (denominator >= 0) \ + den = denominator; \ + else \ + den = 0 - denominator; \ uxdiv_ret = aeabi_ ## uiname(num, den); \ /* signs differ */ \ if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ - ret.quot = uxdiv_ret.quot * -1; \ + ret.quot = 0 - uxdiv_ret.quot; \ else \ ret.quot = uxdiv_ret.quot; \ - if (numerator & typemacro ## _MIN) \ - ret.rem = uxdiv_ret.rem * -1; \ + if (numerator < 0) \ + ret.rem = 0 - uxdiv_ret.rem; \ else \ ret.rem = uxdiv_ret.rem; \ \ @@ -420,8 +426,14 @@ int __aeabi_idiv(int numerator, int denominator) unsigned num, den; uidiv_t ret; - num = numerator & INT_MAX; - den = denominator & INT_MAX; + if (numerator >= 0) + num = numerator; + else + num = 0 - numerator; + if (denominator >= 0) + den = denominator; + else + den = 0 - denominator; ret = aeabi_uidivmod(num, den); if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ ret.quot *= -1; -- 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') 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 2bd0daabbe1fc40e65e4a4631e68f5ca093ea1fb Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 6 Jan 2014 19:56:26 +0100 Subject: misc. fixes - tccgen: error out for cast to void, as in void foo(void) { return 1; } This avoids an assertion failure in x86_64-gen.c, also. also fix tests2/03_struct.c accordingly - Error: "memory full" - be more specific - Makefiles: remove circular dependencies, lookup tcctest.c from VPATH - tcc.h: cleanup lib, include, crt and libgcc search paths" avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR (as from 9382d6f1a0e2d0104a82ed805207d9e742c6b068) - tcc.h: remove ";{B}" from PE search path in ce5e12c2f950052d8109b6b7a56d900547705c08 James Lyon wrote: "... I'm not sure this is the right way to fix this problem." And the answer is: No, please. (copying libtcc1.a for tests instead) - win32/build_tcc.bat: do not move away a versioned file --- Makefile | 3 --- lib/Makefile | 3 --- libtcc.c | 4 ++-- tcc.h | 30 +++++++++++++++--------------- tccgen.c | 8 ++++---- tccpp.c | 4 ++-- tests/Makefile | 39 ++++++++++++++++++++------------------- tests/tests2/03_struct.c | 2 +- tests/tests2/Makefile | 3 --- win32/build-tcc.bat | 4 ++-- 10 files changed, 46 insertions(+), 54 deletions(-) (limited to 'lib') diff --git a/Makefile b/Makefile index 24a7c09..5052758 100644 --- a/Makefile +++ b/Makefile @@ -362,9 +362,6 @@ tar: tcc-doc.html rm -rf $(TCC-VERSION) git reset -Makefile: $(top_srcdir)/Makefile - cp $< $@ - .PHONY: all clean tar distclean install uninstall FORCE endif # ifeq ($(TOP),.) diff --git a/lib/Makefile b/lib/Makefile index a8a2b5d..394df67 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -111,6 +111,3 @@ $(DIR)/exists : clean : rm -rfv i386-win32 x86_64-win32 i386 x86_64 - -Makefile: $(top_srcdir)/lib/Makefile - cp $< $@ diff --git a/libtcc.c b/libtcc.c index df201ae..072b77f 100644 --- a/libtcc.c +++ b/libtcc.c @@ -214,7 +214,7 @@ PUB_FUNC void *tcc_malloc(unsigned long size) void *ptr; ptr = malloc(size); if (!ptr && size) - tcc_error("memory full"); + tcc_error("memory full (malloc)"); #ifdef MEM_DEBUG mem_cur_size += malloc_usable_size(ptr); if (mem_cur_size > mem_max_size) @@ -239,7 +239,7 @@ PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) #endif ptr1 = realloc(ptr, size); if (!ptr1 && size) - tcc_error("memory full"); + tcc_error("memory full (realloc)"); #ifdef MEM_DEBUG /* NOTE: count not correct if alloc error, but not critical */ mem_cur_size += malloc_usable_size(ptr1); diff --git a/tcc.h b/tcc.h index 21957e7..0933b01 100644 --- a/tcc.h +++ b/tcc.h @@ -169,13 +169,18 @@ #ifndef CONFIG_LDDIR # define CONFIG_LDDIR "lib" #endif -#ifndef CONFIG_MULTIARCHDIR -#define CONFIG_MULTIARCHDIR + +#ifdef CONFIG_MULTIARCHDIR +# define USE_MUADIR(s) s "/" CONFIG_MULTIARCHDIR +# define ALSO_MUADIR(s) s "/" CONFIG_MULTIARCHDIR ":" s +#else +# define USE_MUADIR(s) s +# define ALSO_MUADIR(s) s #endif /* path to find crt1.o, crti.o and crtn.o */ #ifndef CONFIG_TCC_CRTPREFIX -# define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR +# define CONFIG_TCC_CRTPREFIX USE_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) #endif /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */ @@ -186,10 +191,8 @@ # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi" # else # define CONFIG_TCC_SYSINCLUDEPATHS \ - CONFIG_SYSROOT "/usr/local/include/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/local/include" \ - ":" CONFIG_SYSROOT "/usr/include/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/include" \ + ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/include") \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/include") \ ":" "{B}/include" # endif #endif @@ -197,15 +200,12 @@ /* library search paths */ #ifndef CONFIG_TCC_LIBPATHS # ifdef TCC_TARGET_PE -# define CONFIG_TCC_LIBPATHS "{B}/lib;{B}" +# define CONFIG_TCC_LIBPATHS "{B}/lib" # else # define CONFIG_TCC_LIBPATHS \ - CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \ - ":" CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/" CONFIG_LDDIR \ - ":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR + ALSO_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) # endif #endif @@ -237,7 +237,7 @@ #endif /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */ -#define TCC_LIBGCC CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR "/libgcc_s.so.1" +#define TCC_LIBGCC USE_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1" /* -------------------------------------------- */ /* include the target specific definitions */ diff --git a/tccgen.c b/tccgen.c index 8355aae..f23cd07 100644 --- a/tccgen.c +++ b/tccgen.c @@ -309,7 +309,7 @@ static void vsetc(CType *type, int r, CValue *vc) int v; if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full"); + tcc_error("memory full (vstack)"); /* cannot let cpu flags if other instruction are generated. Also avoid leaving VT_JMP anywhere except on the top of the stack because it would complicate the code generator. */ @@ -483,7 +483,7 @@ ST_FUNC void vswap(void) ST_FUNC void vpushv(SValue *v) { if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full"); + tcc_error("memory full (vstack)"); vtop++; *vtop = *v; } @@ -2348,8 +2348,8 @@ static void gen_assign_cast(CType *dt) st = &vtop->type; /* source type */ dbt = dt->t & VT_BTYPE; sbt = st->t & VT_BTYPE; - if (sbt == VT_VOID) - tcc_error("Cannot assign void value"); + if (sbt == VT_VOID || dbt == VT_VOID) + tcc_error("cannot cast from/to void"); if (dt->t & VT_CONSTANT) tcc_warning("assignment of read-only location"); switch(dbt) { diff --git a/tccpp.c b/tccpp.c index aeaf6be..e1ccded 100644 --- a/tccpp.c +++ b/tccpp.c @@ -197,7 +197,7 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) int i; if (tok_ident >= SYM_FIRST_ANOM) - tcc_error("memory full"); + tcc_error("memory full (symbols)"); /* expand token table if needed */ i = tok_ident - TOK_IDENT; @@ -1528,7 +1528,7 @@ include_done: c = (define_find(tok) != 0) ^ c; do_if: if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE) - tcc_error("memory full"); + tcc_error("memory full (ifdef)"); *s1->ifdef_stack_ptr++ = c; goto test_skip; case TOK_ELSE: diff --git a/tests/Makefile b/tests/Makefile index 08dfa42..b958a48 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -27,7 +27,7 @@ ifneq ($(ARCH),i386) TESTS := $(filter-out btest,$(TESTS)) endif ifdef CONFIG_WIN32 - TESTS := $(filter-out test3,$(TESTS)) + TESTS := w32-prep $(filter-out test3,$(TESTS)) endif ifeq ($(TARGETOS),Darwin) TESTS := $(filter-out hello-exe test3 btest,$(TESTS)) @@ -84,6 +84,9 @@ moretests: @echo ------------ $@ ------------ $(MAKE) -C tests2 +w32-prep: + cp ../libtcc1.a ../lib + # test.ref - generate using gcc # copy only tcclib.h so GCC's stddef and stdarg will be used test.ref: tcctest.c @@ -91,41 +94,41 @@ test.ref: tcctest.c ./tcctest.gcc > $@ # auto test -test1: test.ref +test1: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) -run $(SRCDIR)/tcctest.c > test.out1 + $(TCC) -run $< > test.out1 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi # iterated test2 (compile tcc then compile tcctest.c !) -test2: test.ref +test2: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2 + $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) -test3: test.ref +test3: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3 + $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi # binary output test -test4: test.ref +test4: tcctest.c test.ref @echo ------------ $@ ------------ # object + link output - $(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c + $(TCC) -c -o tcctest3.o $< $(TCC) -o tcctest3 tcctest3.o ./tcctest3 > test3.out @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi # dynamic output - $(TCC) -o tcctest1 $(SRCDIR)/tcctest.c + $(TCC) -o tcctest1 $< ./tcctest1 > test1.out @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi # dynamic output + bound check - $(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c + $(TCC) -b -o tcctest4 $< ./tcctest4 > test4.out @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi # static output - $(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c + $(TCC) -static -o tcctest2 $< ./tcctest2 > test2.out @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi @@ -161,9 +164,9 @@ speedtest: ex2 ex3 time ./ex3 35 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35 -weaktest: test.ref - $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) - $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS) +weaktest: tcctest.c test.ref + $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) + $(CC) -c $< -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS) objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" @@ -220,7 +223,5 @@ cache: tcc_g clean: $(MAKE) -C tests2 $@ rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \ - hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h - -Makefile: $(SRCDIR)/Makefile - cp $< $@ + hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ + ../lib/libtcc1.a diff --git a/tests/tests2/03_struct.c b/tests/tests2/03_struct.c index df0d3e7..c5d48c5 100644 --- a/tests/tests2/03_struct.c +++ b/tests/tests2/03_struct.c @@ -6,7 +6,7 @@ struct fred int natasha; }; -void main() +int main() { struct fred bloggs; diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 369ed47..51dc38d 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -96,6 +96,3 @@ all test: $(TESTS) clean: rm -vf fred.txt *.output - -Makefile: $(top_srcdir)/tests/tests2/Makefile - cp $< $@ diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat index 772ed26..bd897c4 100644 --- a/win32/build-tcc.bat +++ b/win32/build-tcc.bat @@ -63,5 +63,5 @@ del *.o echo>..\config.texi @set VERSION %VERSION% if not exist doc md doc makeinfo --html --no-split -o doc\tcc-doc.html ../tcc-doc.texi -if exist tcc-win32.txt move tcc-win32.txt doc\ -copy ..\tests\libtcc_test.c examples\ +copy tcc-win32.txt doc +copy ..\tests\libtcc_test.c examples -- cgit v1.3.1 From 0ab07f39a63e1c183126a6b79db96819907e26dd Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 5 Feb 2014 16:09:54 +0800 Subject: Fix float to long long conversion on ARM Fix float to long long conversion on ARM when the result would fit in an int. --- lib/armeabi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/armeabi.c b/lib/armeabi.c index e787ec1..616b9b5 100644 --- a/lib/armeabi.c +++ b/lib/armeabi.c @@ -34,7 +34,7 @@ REGS_RETURN(double_unsigned_struct, double_unsigned_struct) /* float to [unsigned] long long conversion */ -#define DEFINE__AEABIT_F2XLZ(name, with_sign) \ +#define DEFINE__AEABI_F2XLZ(name, with_sign) \ void __aeabi_ ## name(unsigned val) \ { \ int exp, high_shift, sign; \ @@ -74,7 +74,7 @@ void __aeabi_ ## name(unsigned val) \ if (exp > FLOAT_FRAC_BITS) \ ret.low |= val << (exp - FLOAT_FRAC_BITS); \ else \ - ret.low = val >> (FLOAT_FRAC_BITS - exp); \ + ret.low |= val >> (FLOAT_FRAC_BITS - exp); \ } \ \ /* encode negative integer using 2's complement */ \ @@ -92,13 +92,13 @@ void __aeabi_ ## name(unsigned val) \ } /* float to unsigned long long conversion */ -DEFINE__AEABIT_F2XLZ(f2ulz, 0) +DEFINE__AEABI_F2XLZ(f2ulz, 0) /* float to long long conversion */ -DEFINE__AEABIT_F2XLZ(f2lz, 1) +DEFINE__AEABI_F2XLZ(f2lz, 1) /* double to [unsigned] long long conversion */ -#define DEFINE__AEABIT_D2XLZ(name, with_sign) \ +#define DEFINE__AEABI_D2XLZ(name, with_sign) \ void __aeabi_ ## name(double_unsigned_struct val) \ { \ int exp, high_shift, sign; \ @@ -143,7 +143,7 @@ void __aeabi_ ## name(double_unsigned_struct val) \ ret.low |= val.high << high_shift; \ ret.low |= val.low >> (32 - high_shift); \ } else \ - ret.low = val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ + ret.low |= val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ } \ \ /* encode negative integer using 2's complement */ \ @@ -161,10 +161,10 @@ void __aeabi_ ## name(double_unsigned_struct val) \ } /* double to unsigned long long conversion */ -DEFINE__AEABIT_D2XLZ(d2ulz, 0) +DEFINE__AEABI_D2XLZ(d2ulz, 0) /* double to long long conversion */ -DEFINE__AEABIT_D2XLZ(d2lz, 1) +DEFINE__AEABI_D2XLZ(d2lz, 1) /* long long to float conversion */ #define DEFINE__AEABI_XL2F(name, with_sign) \ -- cgit v1.3.1 From d0295074941816351c15fe3d4326b5e98364ff9c Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 5 Feb 2014 16:56:27 +0800 Subject: Fix negative long long to float conversion on ARM --- lib/armeabi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/armeabi.c b/lib/armeabi.c index 616b9b5..bf5e07a 100644 --- a/lib/armeabi.c +++ b/lib/armeabi.c @@ -175,7 +175,7 @@ unsigned __aeabi_ ## name(unsigned long long v) \ double_unsigned_struct val; \ \ /* fraction in negative float is encoded in 1's complement */ \ - if (with_sign && (v & (1 << 63))) { \ + if (with_sign && (v & (1ULL << 63))) { \ sign = 1; \ v = ~v + 1; \ } \ @@ -216,7 +216,7 @@ unsigned __aeabi_ ## name(unsigned long long v) \ DEFINE__AEABI_XL2F(ul2f, 0) /* long long to float conversion */ -DEFINE__AEABI_XL2F(l2f, 0) +DEFINE__AEABI_XL2F(l2f, 1) /* long long to double conversion */ #define __AEABI_XL2D(name, with_sign) \ -- cgit v1.3.1 From 88c9f1bb4e64d9dab658061b058b8bedc2c66ac5 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 5 Feb 2014 19:47:15 +0800 Subject: Round mode of ll -> float conversion to nearest Change rounding mode of long long to float conversion to nearest in libtcc1. --- lib/armeabi.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/armeabi.c b/lib/armeabi.c index bf5e07a..ce5e232 100644 --- a/lib/armeabi.c +++ b/lib/armeabi.c @@ -170,7 +170,7 @@ DEFINE__AEABI_D2XLZ(d2lz, 1) #define DEFINE__AEABI_XL2F(name, with_sign) \ unsigned __aeabi_ ## name(unsigned long long v) \ { \ - int s /* shift */, sign = 0; \ + int s /* shift */, flb /* first lost bit */, sign = 0; \ unsigned p = 0 /* power */, ret; \ double_unsigned_struct val; \ \ @@ -188,20 +188,28 @@ unsigned __aeabi_ ## name(unsigned long long v) \ if (s < FLOAT_FRAC_BITS) { \ ret <<= FLOAT_FRAC_BITS - s; \ ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \ - } else \ + flb = (val.low >> (32 - (FLOAT_FRAC_BITS - s - 1))) & 1; \ + } else { \ + flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ ret >>= s - FLOAT_FRAC_BITS; \ + } \ s += 32; \ } else { \ for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ if (p) { \ ret = val.low & (p - 1); \ - if (s <= FLOAT_FRAC_BITS) \ + if (s <= FLOAT_FRAC_BITS) { \ ret <<= FLOAT_FRAC_BITS - s; \ - else \ + flb = 0; \ + } else { \ + flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \ ret >>= s - FLOAT_FRAC_BITS; \ + } \ } else \ return 0; \ } \ + if (flb) \ + ret++; \ \ /* fill exponent bits */ \ ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \ @@ -222,7 +230,7 @@ DEFINE__AEABI_XL2F(l2f, 1) #define __AEABI_XL2D(name, with_sign) \ void __aeabi_ ## name(unsigned long long v) \ { \ - int s, high_shift, sign = 0; \ + int s /* shift */, high_shift, sign = 0; \ unsigned tmp, p = 0; \ double_unsigned_struct val, ret; \ \ @@ -248,6 +256,13 @@ void __aeabi_ ## name(unsigned long long v) \ ret.high = tmp >> high_shift; \ ret.low = tmp << (32 - high_shift); \ ret.low |= val.low >> high_shift; \ + if ((val.low >> (high_shift - 1)) & 1) { \ + if (ret.low == UINT_MAX) { \ + ret.high++; \ + ret.low = 0; \ + } else \ + ret.low++; \ + } \ } \ s += 32; \ } else { \ -- 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') 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') 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') 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') 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') 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 From b125743323f92b3492634cd875be820c890d5f29 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 29 Mar 2014 14:28:02 +0800 Subject: Create bcheck region for argv and arge argument For program manipulating argv or arge as pointer with construct such as: (while *argv++) { do_something_with_argv; } it is necessary to have argv and arge inside a region. This patch create regions argv and arge) if main is declared with those parameters. --- lib/bcheck.c | 7 +++++++ tccgen.c | 15 +++++++++++++++ tcctok.h | 1 + 3 files changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/bcheck.c b/lib/bcheck.c index 064fb5d..968cdf4 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -418,6 +418,13 @@ void __bound_init(void) } } +void __bound_main_arg(void **p) +{ + void *start = p; + while (*p++); + __bound_new_region(start, (void *) p - start); +} + void __bound_exit(void) { restore_malloc_hooks(); diff --git a/tccgen.c b/tccgen.c index b4f97f4..fa03daf 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5770,6 +5770,21 @@ static void gen_function(Sym *sym) /* push a dummy symbol to enable local sym storage */ sym_push2(&local_stack, SYM_FIELD, 0, 0); gfunc_prolog(&sym->type); +#ifdef CONFIG_TCC_BCHECK + if (tcc_state->do_bound_check + && !strcmp(get_tok_str(sym->v, NULL), "main")) { + int i; + + sym = local_stack; + for (i = 0, sym = local_stack; i < 2; i++, sym = sym->prev) { + if (sym->v & SYM_FIELD || sym->prev->v & SYM_FIELD) + break; + vpush_global_sym(&func_old_type, TOK___bound_main_arg); + vset(&sym->type, sym->r, sym->c); + gfunc_call(1); + } + } +#endif rsym = 0; block(NULL, NULL, NULL, NULL, 0, 0); gsym(rsym); diff --git a/tcctok.h b/tcctok.h index 73b0cf9..c17711f 100644 --- a/tcctok.h +++ b/tcctok.h @@ -237,6 +237,7 @@ DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8") DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12") DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16") + DEF(TOK___bound_main_arg, "__bound_main_arg") DEF(TOK___bound_local_new, "__bound_local_new") DEF(TOK___bound_local_delete, "__bound_local_delete") # ifdef TCC_TARGET_PE -- cgit v1.3.1 From ea2805f097414bf7bf299c131be1aba27b79f5d1 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Wed, 2 Apr 2014 21:27:22 +0200 Subject: shared libs: Build libtcc1.a with -fPIC TCCs runtime library must be compiled as position independend code, so it can be linked into shared libraries. --- lib/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 394df67..7ef267f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -49,6 +49,10 @@ ARM_O = libtcc1.o armeabi.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 +# build TCC runtime library to contain PIC code, so it can be linked +# into shared libraries +PICFLAGS = -fPIC + ifeq "$(TARGET)" "i386-win32" OBJ = $(addprefix $(DIR)/,$(WIN32_O)) TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE @@ -83,7 +87,7 @@ endif endif endif -XFLAGS = $(CPPFLAGS) $(CFLAGS) $(TGT) +XFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAGS) $(TGT) ifeq ($(TARGETOS),Darwin) XAR = $(DIR)/tiny_libmaker$(EXESUF) -- cgit v1.3.1 From c4427747e6e5890b65c70e8fad5b30309b2b0279 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 5 Apr 2014 22:54:11 +0200 Subject: arm: Provide alloca() This provides a simple implementation of alloca for ARM (and enables the associated testcase). As tcc for ARM doesn't contain an assembler, we'll have to resort using gcc for compiling it. --- lib/Makefile | 4 ++-- lib/alloca-arm.S | 11 +++++++++++ tests/tcctest.c | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 lib/alloca-arm.S (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 7ef267f..cf3cd71 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -45,7 +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 armeabi.o +ARM_O = libtcc1.o armeabi.o alloca-arm.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 @@ -104,7 +104,7 @@ $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) $(DIR)/%.o : %.c $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%.o : %.S - $(XCC) -c $< -o $@ $(XFLAGS) + $(CC) -c $< -o $@ $(XFLAGS) $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) diff --git a/lib/alloca-arm.S b/lib/alloca-arm.S new file mode 100644 index 0000000..9deae63 --- /dev/null +++ b/lib/alloca-arm.S @@ -0,0 +1,11 @@ + .text + .align 2 + .global alloca + .type alloca, %function +alloca: + rsb sp, r0, sp + bic sp, sp, #7 + mov r0, sp + mov pc, lr + .size alloca, .-alloca + .section .note.GNU-stack,"",%progbits diff --git a/tests/tcctest.c b/tests/tcctest.c index 1653927..c48c1bc 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2221,7 +2221,7 @@ void old_style_function(void) void alloca_test() { -#if defined __i386__ || defined __x86_64__ +#if defined __i386__ || defined __x86_64__ || defined __arm__ char *p = alloca(16); strcpy(p,"123456789012345"); printf("alloca: p is %s\n", p); @@ -2794,7 +2794,7 @@ double get100 () { return 100.0; } void callsave_test(void) { -#if defined __i386__ || defined __x86_64__ +#if defined __i386__ || defined __x86_64__ || defined __arm__ int i, s; double *d; double t; s = sizeof (double); printf ("callsavetest: %d\n", s); -- cgit v1.3.1 From 76accfb8d5b16664207fa8ae43d02b015bc8e019 Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 7 Apr 2014 11:13:19 +0200 Subject: win32: libtcc1.a needs to be built with tcc gcc/mingw produces msvc compatible pecoff objects, tcc only knows ELF. --- lib/Makefile | 7 +++++-- tests/tests2/Makefile | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index cf3cd71..e9e12f1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -6,7 +6,7 @@ TOP = .. include $(TOP)/Makefile VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib -ifndef TARGET +ifndef TARGET # native library ifdef CONFIG_WIN64 TARGET = x86_64-win32 else @@ -27,6 +27,7 @@ ifndef TARGET else ifeq ($(ARCH),arm) TARGET = arm + XCC = $(CC) endif endif endif @@ -58,12 +59,14 @@ ifeq "$(TARGET)" "i386-win32" TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include XAR = $(DIR)/tiny_libmaker$(EXESUF) + PICFLAGS = else ifeq "$(TARGET)" "x86_64-win32" OBJ = $(addprefix $(DIR)/,$(WIN64_O)) TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include XAR = $(DIR)/tiny_libmaker$(EXESUF) + PICFLAGS = else ifeq "$(TARGET)" "i386" OBJ = $(addprefix $(DIR)/,$(I386_O)) @@ -104,7 +107,7 @@ $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) $(DIR)/%.o : %.c $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%.o : %.S - $(CC) -c $< -o $@ $(XFLAGS) + $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index d523b77..e5790c7 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -1,10 +1,10 @@ TOP = ../.. include $(TOP)/Makefile -VPATH = $(top_srcdir)/tests/tests2 -TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include ifdef CONFIG_WIN32 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) +else + TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include -lm endif ifeq ($(TARGETOS),Darwin) @@ -94,7 +94,7 @@ endif @if [ "x`echo $* | grep args`" != "x" ]; \ then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output 2>&1; \ else $(TCC) -run $< >$*.output 2>&1; \ - ($(TCC) -o $*.exe $< -lm && ./$*.exe) >$*.output2 2>&1; \ + ($(TCC) -o $*.exe $< && ./$*.exe) >$*.output2 2>&1; \ fi || true @if diff -bu $(<:.c=.expect) $*.output ; \ then rm -f $*.output; \ -- cgit v1.3.1 From 3e9a7e9d69e3adb0e9ed65d11caf415e74458fe9 Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Mon, 7 Apr 2014 13:31:00 +0200 Subject: Corrected spelling mistakes in comments and strings --- arm-gen.c | 4 ++-- c67-gen.c | 4 ++-- i386-asm.c | 2 +- i386-tok.h | 2 +- include/stddef.h | 2 +- lib/bcheck.c | 2 +- tccasm.c | 2 +- tccgen.c | 4 ++-- tests/Makefile | 2 +- tests/tcctest.c | 2 +- tests/tests2/46_grep.c | 10 +++++----- 11 files changed, 18 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/arm-gen.c b/arm-gen.c index a9c05fe..680a490 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -943,7 +943,7 @@ struct plan { Returns the amount of stack space needed for parameter passing Note: this function allocated an array in plan->pplans with tcc_malloc. It - is the responsability of the caller to free this array once used (ie not + is the responsibility of the caller to free this array once used (ie not before copy_params). */ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) { @@ -1860,7 +1860,7 @@ void gen_opf(int op) case TOK_UGE: case TOK_ULE: case TOK_UGT: - tcc_error("unsigned comparision on floats?"); + tcc_error("unsigned comparison on floats?"); break; case TOK_LT: op=TOK_Nset; diff --git a/c67-gen.c b/c67-gen.c index 6d9068a..a26dfaa 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -245,8 +245,8 @@ void gsym(int t) } // these are regs that tcc doesn't really know about, -// but asign them unique values so the mapping routines -// can distinquish them +// but assign them unique values so the mapping routines +// can distinguish them #define C67_A0 105 #define C67_SP 106 diff --git a/i386-asm.c b/i386-asm.c index 8473d06..a524658 100644 --- a/i386-asm.c +++ b/i386-asm.c @@ -1382,7 +1382,7 @@ ST_FUNC void subst_asm_operand(CString *add_str, } } -/* generate prolog and epilog code for asm statment */ +/* generate prolog and epilog code for asm statement */ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, diff --git a/i386-tok.h b/i386-tok.h index d1e4bf3..6ba865d 100644 --- a/i386-tok.h +++ b/i386-tok.h @@ -191,7 +191,7 @@ DEF_FP(mul) DEF_ASM(fcom) - DEF_ASM(fcom_1) /* non existant op, just to have a regular table */ + DEF_ASM(fcom_1) /* non existent op, just to have a regular table */ DEF_FP1(com) DEF_FP(comp) diff --git a/include/stddef.h b/include/stddef.h index eaf0669..9e43de9 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -31,7 +31,7 @@ void *alloca(size_t size); by __need_wint_t, as otherwise stddef.h isn't allowed to define this type). Note that this must be outside the normal _STDDEF_H guard, so that it works even when we've included the file - already (without requring wint_t). Some other libs define _WINT_T + already (without requiring wint_t). Some other libs define _WINT_T if they've already provided that type, so we can use that as guard. TCC defines __WINT_TYPE__ for us. */ #if defined (__need_wint_t) diff --git a/lib/bcheck.c b/lib/bcheck.c index 968cdf4..76413ad 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -635,7 +635,7 @@ int __bound_delete_region(void *p) } /* return the size of the region starting at p, or EMPTY_SIZE if non - existant region. */ + existent region. */ static unsigned long get_region_size(void *p) { unsigned long addr = (unsigned long)p; diff --git a/tccasm.c b/tccasm.c index 9c77960..1c6a65d 100644 --- a/tccasm.c +++ b/tccasm.c @@ -232,7 +232,7 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) } else { goto cannot_relocate; } - pe->sym = NULL; /* same symbols can be substracted to NULL */ + pe->sym = NULL; /* same symbols can be subtracted to NULL */ } else { cannot_relocate: tcc_error("invalid operation with label"); diff --git a/tccgen.c b/tccgen.c index e6e0fe1..ec92797 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1579,7 +1579,7 @@ static inline int is_integer_btype(int bt) bt == VT_INT || bt == VT_LLONG); } -/* check types for comparison or substraction of pointers */ +/* check types for comparison or subtraction of pointers */ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) { CType *type1, *type2, tmp_type1, tmp_type2; @@ -5574,7 +5574,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, if (sym->type.t & VT_EXTERN) { /* if the variable is extern, it was not allocated */ sym->type.t &= ~VT_EXTERN; - /* set array size if it was ommited in extern + /* set array size if it was omitted in extern declaration */ if ((sym->type.t & VT_ARRAY) && sym->type.ref->c < 0 && diff --git a/tests/Makefile b/tests/Makefile index 55bf29c..ee0eafe 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -158,7 +158,7 @@ btest: boundtest.c @for i in $(BOUNDS_OK); do \ echo ; echo --- boundtest $$i ---; \ if $(TCC) -b -run $< $$i ; then \ - echo succeded as expected; \ + echo succeeded as expected; \ else\ echo Failed positive test $$i ; exit 1 ; \ fi ;\ diff --git a/tests/tcctest.c b/tests/tcctest.c index c48c1bc..cc8ffd8 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2254,7 +2254,7 @@ void c99_vla_test(int size1, int size2) printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); tab1_ptr = tab1; tab2_ptr = tab2; - printf("Test C99 VLA 2 (ptrs substract): "); + printf("Test C99 VLA 2 (ptrs subtract): "); printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); printf("Test C99 VLA 3 (ptr add): "); printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c index 5f52220..27589a4 100644 --- a/tests/tests2/46_grep.c +++ b/tests/tests2/46_grep.c @@ -29,10 +29,10 @@ char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list\n", - "Flags are single characters preceeded by '-':", + "Flags are single characters preceded by '-':", " -c Only a count of matching lines is printed", " -f Print file name for matching lines switch, see below", - " -n Each line is preceeded by its line number", + " -n Each line is preceded by its line number", " -v Only print non-matching lines\n", "The file_list is a list of files (wildcards are acceptable on RSX modes).", "\nThe file name is normally printed if there is a file given.", @@ -54,10 +54,10 @@ char *patdoc[] = { "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", "': ' other control characters, such as new-line.", "'*' An expression followed by an asterisk matches zero or more", - " occurrances of that expression: \"fo*\" matches \"f\", \"fo\"", + " occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", " \"foo\", etc.", "'+' An expression followed by a plus sign matches one or more", - " occurrances of that expression: \"fo+\" matches \"fo\", etc.", + " occurrences of that expression: \"fo+\" matches \"fo\", etc.", "'-' An expression followed by a minus sign optionally matches", " the expression.", "'[]' A string enclosed in square brackets matches any character in", @@ -153,7 +153,7 @@ void compile(char *source) o == STAR || o == PLUS || o == MINUS) - badpat("Illegal occurrance op.", source, s); + badpat("Illegal occurrence op.", source, s); store(ENDPAT); store(ENDPAT); spp = pp; /* Save pattern end */ -- cgit v1.3.1 From 9714d2e75f70f8fcca9fd7b596440a346e504742 Mon Sep 17 00:00:00 2001 From: minux Date: Sat, 12 Apr 2014 01:42:46 -0400 Subject: build: add initial NetBSD support. Not able to generate ELF files on NetBSD yet (lacks the note and crt1.o is actually named crt0.o on NetBSD), but -run works with these extra defines: -D__lint__ -D"__symbolrename(x)=asm(#x)" -D__NetBSD__ The -D__lint__ is an ugly hack, TCC should be able to emulate GCC just fine, but it seems TCC doesn't support __builtin_va_list yet? typedef __builtin_va_list __va_list; /usr/include/sys/ansi.h:72: error: ';' expected (got "__va_list") --- configure | 1 + lib/bcheck.c | 4 ++-- tccrun.c | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/configure b/configure index 8c44e5c..c309de6 100755 --- a/configure +++ b/configure @@ -56,6 +56,7 @@ case $targetos in DragonFly) noldl=yes;; OpenBSD) noldl=yes;; FreeBSD) noldl=yes;; + NetBSD) noldl=yes;; *) ;; esac diff --git a/lib/bcheck.c b/lib/bcheck.c index 76413ad..8ac7d4e 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -22,7 +22,7 @@ #include #include #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \ - && !defined(__DragonFly__) && !defined(__OpenBSD__) + && !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) #include #endif #if !defined(_WIN32) @@ -41,7 +41,7 @@ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__DragonFly__) || defined(__dietlibc__) \ - || defined(__UCLIBC__) || defined(__OpenBSD__) \ + || defined(__UCLIBC__) || defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(_WIN32) || defined(TCC_UCLIBC) #warning Bound checking does not support malloc (etc.) in this environment. #undef CONFIG_TCC_MALLOC_HOOKS diff --git a/tccrun.c b/tccrun.c index a3e496e..13c2012 100644 --- a/tccrun.c +++ b/tccrun.c @@ -486,10 +486,12 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) if (level == 0) { #if defined(__APPLE__) *paddr = uc->uc_mcontext->__ss.__eip; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) *paddr = uc->uc_mcontext.mc_eip; #elif defined(__dietlibc__) *paddr = uc->uc_mcontext.eip; +#elif defined(__NetBSD__) + *paddr = uc->uc_mcontext.__gregs[_REG_EIP]; #else *paddr = uc->uc_mcontext.gregs[REG_EIP]; #endif @@ -497,10 +499,12 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) } else { #if defined(__APPLE__) fp = uc->uc_mcontext->__ss.__ebp; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) fp = uc->uc_mcontext.mc_ebp; #elif defined(__dietlibc__) fp = uc->uc_mcontext.ebp; +#elif defined(__NetBSD__) + fp = uc->uc_mcontext.__gregs[_REG_EBP]; #else fp = uc->uc_mcontext.gregs[REG_EBP]; #endif @@ -530,6 +534,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) *paddr = uc->uc_mcontext->__ss.__rip; #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) *paddr = uc->uc_mcontext.mc_rip; +#elif defined(__NetBSD__) + *paddr = uc->uc_mcontext.__gregs[_REG_RIP]; #else *paddr = uc->uc_mcontext.gregs[REG_RIP]; #endif @@ -539,6 +545,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level) fp = uc->uc_mcontext->__ss.__rbp; #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) fp = uc->uc_mcontext.mc_rbp; +#elif defined(__NetBSD__) + fp = uc->uc_mcontext.__gregs[_REG_RBP]; #else fp = uc->uc_mcontext.gregs[REG_RBP]; #endif -- cgit v1.3.1