From 9382d6f1a0e2d0104a82ed805207d9e742c6b068 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 7 Sep 2013 19:26:36 +0200 Subject: Fix lib, include, crt and libgcc search paths --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configure') diff --git a/configure b/configure index b513cc1..d654fd9 100755 --- a/configure +++ b/configure @@ -304,7 +304,7 @@ if test -z "$cross_prefix" ; then if test "$mingw32" = "no" ; then triplet="$($CONFTEST triplet)" if test -f "/usr/lib/$triplet/crti.o" ; then - tcc_lddir="lib/$triplet" + tcc_lddir="lib" multiarch_triplet="$triplet" elif test -f "/usr/lib64/crti.o" ; then tcc_lddir="lib64" -- cgit v1.3.1 From 9e79b18bca641b12b6b12e5cec46202f6d6fad65 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Fri, 3 Jan 2014 18:17:52 +0800 Subject: Use libtcc.a for static link even with USE_LIBGCC When statically linking, runtime library should be static as well. tcc could link with libgcc.a but it's in a gcc version specific directory. Another solution, followed by this patch, is to use libtcc.a when statically linking, even if USE_LIBGCC was configured. --- configure | 2 +- tccelf.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'configure') diff --git a/configure b/configure index d654fd9..cc8ca5a 100755 --- 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 /lib/libgcc_s.so.1 instead of libtcc.a + --with-libgcc use libgcc_s.so.1 instead of libtcc.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/tccelf.c b/tccelf.c index 91155e3..caa8281 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1363,7 +1363,12 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) if (!s1->nostdlib) { tcc_add_library(s1, "c"); #ifdef CONFIG_USE_LIBGCC - tcc_add_file(s1, TCC_LIBGCC); + if (!s1->static_link) + tcc_add_file(s1, TCC_LIBGCC); +#if !defined WITHOUT_LIBTCC + else + tcc_add_support(s1, "libtcc1.a"); +#endif #elif !defined WITHOUT_LIBTCC tcc_add_support(s1, "libtcc1.a"); #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 'configure') 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 3fe2a95d7fe854c8cf496a009a467bb65cdf030d Mon Sep 17 00:00:00 2001 From: grischka Date: Tue, 7 Jan 2014 14:57:07 +0100 Subject: be stricter with aliasing Refactoring (no logical changes): - use memcpy in tccgen.c:ieee_finite(double d) - use union to store attribute flags in Sym Makefile: "CFLAGS+=-fno-strict-aliasing" basically not necessary anymore but I left it for now because gcc sometimes behaves unexpectedly without. Also: - configure: back to mode 100755 - tcc.h: remove unused variables tdata/tbss_section - x86_64-gen.c: adjust gfunc_sret for prototype --- configure | 0 i386-gen.c | 4 +-- libtcc.c | 8 ++--- tcc.h | 57 ++++++++++++++++------------------- tccgen.c | 97 +++++++++++++++++++++++++++++++----------------------------- x86_64-gen.c | 15 ++++++---- 6 files changed, 92 insertions(+), 89 deletions(-) mode change 100644 => 100755 configure (limited to 'configure') diff --git a/configure b/configure old mode 100644 new mode 100755 diff --git a/i386-gen.c b/i386-gen.c index 4c4a54b..ece054b 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -457,7 +457,7 @@ ST_FUNC void gfunc_call(int nb_args) } save_regs(0); /* save used temporary registers */ func_sym = vtop->type.ref; - func_call = FUNC_CALL(func_sym->r); + func_call = func_sym->a.func_call; /* fast call case */ if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) || func_call == FUNC_FASTCALLW) { @@ -505,7 +505,7 @@ ST_FUNC void gfunc_prolog(CType *func_type) CType *type; sym = func_type->ref; - func_call = FUNC_CALL(sym->r); + func_call = sym->a.func_call; addr = 8; loc = 0; func_vc = 0; diff --git a/libtcc.c b/libtcc.c index 072b77f..154a266 100644 --- a/libtcc.c +++ b/libtcc.c @@ -493,11 +493,11 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, if (sym->type.t & VT_EXPORT) other |= 1; if (sym_type == STT_FUNC && sym->type.ref) { - int attr = sym->type.ref->r; - if (FUNC_EXPORT(attr)) + Sym *ref = sym->type.ref; + if (ref->a.func_export) other |= 1; - if (FUNC_CALL(attr) == FUNC_STDCALL && can_add_underscore) { - sprintf(buf1, "_%s@%d", name, FUNC_ARGS(attr) * PTR_SIZE); + if (ref->a.func_call == FUNC_STDCALL && can_add_underscore) { + sprintf(buf1, "_%s@%d", name, ref->a.func_args * PTR_SIZE); name = buf1; other |= 2; can_add_underscore = 0; diff --git a/tcc.h b/tcc.h index 0933b01..f3d868f 100644 --- a/tcc.h +++ b/tcc.h @@ -326,11 +326,35 @@ typedef struct SValue { struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */ } SValue; +struct Attribute { + unsigned + func_call : 3, /* calling convention (0..5), see below */ + aligned : 5, /* alignement (0..16) */ + packed : 1, + func_export : 1, + func_import : 1, + func_args : 5, + func_proto : 1, + mode : 4, + weak : 1, + fill : 10; // 10 bits left to fit well in union below +}; + +/* GNUC attribute definition */ +typedef struct AttributeDef { + struct Attribute a; + struct Section *section; + int alias_target; /* token */ +} AttributeDef; + /* symbol management */ typedef struct Sym { int v; /* symbol token */ char *asm_label; /* associated asm label */ - long r; /* associated register */ + union { + long r; /* associated register */ + struct Attribute a; + }; union { long c; /* associated number */ int *d; /* define token stream */ @@ -381,34 +405,6 @@ typedef struct DLLReference { char name[1]; } DLLReference; -/* GNUC attribute definition */ -typedef struct AttributeDef { - unsigned - func_call : 3, /* calling convention (0..5), see below */ - aligned : 5, /* alignement (0..16) */ - packed : 1, - func_export : 1, - func_import : 1, - func_args : 5, - func_proto : 1, - mode : 4, - weak : 1, - fill : 10; - struct Section *section; - int alias_target; /* token */ -} AttributeDef; - -/* gr: wrappers for casting sym->r for other purposes */ -#define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call) -#define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export) -#define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import) -#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args) -#define FUNC_PROTO(r) (((AttributeDef*)&(r))->func_proto) -#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned) -#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed) -#define ATTR_MODE(r) (((AttributeDef*)&(r))->mode) -#define INT_ATTR(ad) (*(int*)(ad)) - /* -------------------------------------------------- */ #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */ @@ -1142,7 +1138,6 @@ ST_FUNC void expect(const char *msg); /* ------------ tccgen.c ------------ */ ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ -ST_DATA Section *tdata_section, *tbss_section; /* thread-local storage sections */ ST_DATA Section *cur_text_section; /* current section where function code is generated */ #ifdef CONFIG_TCC_ASM ST_DATA Section *last_text_section; /* to handle .previous asm directive */ @@ -1268,7 +1263,7 @@ ST_FUNC void build_got_entries(TCCState *s1); ST_FUNC void tcc_add_runtime(TCCState *s1); ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err); -#ifdef TCC_IS_NATIVE +#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); #endif diff --git a/tccgen.c b/tccgen.c index f23cd07..7a675cc 100644 --- a/tccgen.c +++ b/tccgen.c @@ -103,7 +103,8 @@ ST_INLN int is_float(int t) /* XXX: endianness dependent */ ST_FUNC int ieee_finite(double d) { - int *p = (int *)&d; + int p[4]; + memcpy(p, &d, sizeof(double)); return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; } @@ -2172,7 +2173,7 @@ static int is_compatible_func(CType *type1, CType *type2) if (!is_compatible_types(&s1->type, &s2->type)) return 0; /* check func_call */ - if (FUNC_CALL(s1->r) != FUNC_CALL(s2->r)) + if (s1->a.func_call != s2->a.func_call) return 0; /* XXX: not complete */ if (s1->c == FUNC_OLD || s2->c == FUNC_OLD) @@ -2659,15 +2660,15 @@ static void parse_attribute(AttributeDef *ad) } else { n = MAX_ALIGN; } - ad->aligned = n; + ad->a.aligned = n; break; case TOK_PACKED1: case TOK_PACKED2: - ad->packed = 1; + ad->a.packed = 1; break; case TOK_WEAK1: case TOK_WEAK2: - ad->weak = 1; + ad->a.weak = 1; break; case TOK_UNUSED1: case TOK_UNUSED2: @@ -2682,12 +2683,12 @@ static void parse_attribute(AttributeDef *ad) case TOK_CDECL1: case TOK_CDECL2: case TOK_CDECL3: - ad->func_call = FUNC_CDECL; + ad->a.func_call = FUNC_CDECL; break; case TOK_STDCALL1: case TOK_STDCALL2: case TOK_STDCALL3: - ad->func_call = FUNC_STDCALL; + ad->a.func_call = FUNC_STDCALL; break; #ifdef TCC_TARGET_I386 case TOK_REGPARM1: @@ -2699,26 +2700,26 @@ static void parse_attribute(AttributeDef *ad) else if (n < 0) n = 0; if (n > 0) - ad->func_call = FUNC_FASTCALL1 + n - 1; + ad->a.func_call = FUNC_FASTCALL1 + n - 1; skip(')'); break; case TOK_FASTCALL1: case TOK_FASTCALL2: case TOK_FASTCALL3: - ad->func_call = FUNC_FASTCALLW; + ad->a.func_call = FUNC_FASTCALLW; break; #endif case TOK_MODE: skip('('); switch(tok) { case TOK_MODE_DI: - ad->mode = VT_LLONG + 1; + ad->a.mode = VT_LLONG + 1; break; case TOK_MODE_HI: - ad->mode = VT_SHORT + 1; + ad->a.mode = VT_SHORT + 1; break; case TOK_MODE_SI: - ad->mode = VT_INT + 1; + ad->a.mode = VT_INT + 1; break; default: tcc_warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL)); @@ -2728,10 +2729,10 @@ static void parse_attribute(AttributeDef *ad) skip(')'); break; case TOK_DLLEXPORT: - ad->func_export = 1; + ad->a.func_export = 1; break; case TOK_DLLIMPORT: - ad->func_import = 1; + ad->a.func_import = 1; break; default: if (tcc_state->warn_unsupported) @@ -2873,10 +2874,10 @@ static void struct_decl(CType *type, int u, int tdef) get_tok_str(v, NULL)); } size = type_size(&type1, &align); - if (ad.aligned) { - if (align < ad.aligned) - align = ad.aligned; - } else if (ad.packed) { + if (ad.a.aligned) { + if (align < ad.a.aligned) + align = ad.a.aligned; + } else if (ad.a.packed) { align = 1; } else if (*tcc_state->pack_stack_ptr) { if (align > *tcc_state->pack_stack_ptr) @@ -3118,8 +3119,8 @@ static int parse_btype(CType *type, AttributeDef *ad) case TOK_ATTRIBUTE1: case TOK_ATTRIBUTE2: parse_attribute(ad); - if (ad->mode) { - u = ad->mode -1; + if (ad->a.mode) { + u = ad->a.mode -1; t = (t & ~VT_BTYPE) | u; } break; @@ -3143,11 +3144,11 @@ static int parse_btype(CType *type, AttributeDef *ad) type->ref = s->type.ref; if (s->r) { /* get attributes from typedef */ - if (0 == ad->aligned) - ad->aligned = FUNC_ALIGN(s->r); - if (0 == ad->func_call) - ad->func_call = FUNC_CALL(s->r); - ad->packed |= FUNC_PACKED(s->r); + if (0 == ad->a.aligned) + ad->a.aligned = s->a.aligned; + if (0 == ad->a.func_call) + ad->a.func_call = s->a.func_call; + ad->a.packed |= s->a.packed; } next(); typespec_found = 1; @@ -3287,8 +3288,9 @@ static void post_type(CType *type, AttributeDef *ad) type->t |= VT_PTR; } /* we push a anonymous symbol which will contain the function prototype */ - ad->func_args = arg_size; - s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l); + ad->a.func_args = arg_size; + s = sym_push(SYM_FIELD, type, 0, l); + s->a = ad->a; s->next = first; type->t = VT_FUNC; type->ref = s; @@ -5484,10 +5486,10 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, if (flexible_array) size += flexible_array->type.ref->c * pointed_size(&flexible_array->type); /* take into account specified alignment if bigger */ - if (ad->aligned) { - if (ad->aligned > align) - align = ad->aligned; - } else if (ad->packed) { + if (ad->a.aligned) { + if (ad->a.aligned > align) + align = ad->a.aligned; + } else if (ad->a.packed) { align = 1; } if ((r & VT_VALMASK) == VT_LOCAL) { @@ -5869,12 +5871,12 @@ static int decl0(int l, int is_for_loop_init) parse_attribute(&ad); } - if (ad.weak) + if (ad.a.weak) type.t |= VT_WEAK; #ifdef TCC_TARGET_PE - if (ad.func_import) + if (ad.a.func_import) type.t |= VT_IMPORT; - if (ad.func_export) + if (ad.a.func_export) type.t |= VT_EXPORT; #endif if (tok == '{') { @@ -5895,22 +5897,22 @@ static int decl0(int l, int is_for_loop_init) sym = sym_find(v); if (sym) { + Sym *ref; if ((sym->type.t & VT_BTYPE) != VT_FUNC) goto func_error1; - r = sym->type.ref->r; - - if (!FUNC_PROTO(r)) + ref = sym->type.ref; + if (0 == ref->a.func_proto) tcc_error("redefinition of '%s'", get_tok_str(v, NULL)); /* use func_call from prototype if not defined */ - if (FUNC_CALL(r) != FUNC_CDECL - && FUNC_CALL(type.ref->r) == FUNC_CDECL) - FUNC_CALL(type.ref->r) = FUNC_CALL(r); + if (ref->a.func_call != FUNC_CDECL + && type.ref->a.func_call == FUNC_CDECL) + type.ref->a.func_call = ref->a.func_call; /* use export from prototype */ - if (FUNC_EXPORT(r)) - FUNC_EXPORT(type.ref->r) = 1; + if (ref->a.func_export) + type.ref->a.func_export = 1; /* use static from prototype */ if (sym->type.t & VT_STATIC) @@ -5921,7 +5923,7 @@ static int decl0(int l, int is_for_loop_init) tcc_error("incompatible types for redefinition of '%s'", get_tok_str(v, NULL)); } - FUNC_PROTO(type.ref->r) = 0; + type.ref->a.func_proto = 0; /* if symbol is already defined, then put complete type */ sym->type = type; } else { @@ -5980,15 +5982,16 @@ static int decl0(int l, int is_for_loop_init) if (btype.t & VT_TYPEDEF) { /* save typedefed type */ /* XXX: test storage specifiers ? */ - sym = sym_push(v, &type, INT_ATTR(&ad), 0); + sym = sym_push(v, &type, 0, 0); + sym->a = ad.a; sym->type.t |= VT_TYPEDEF; } else { r = 0; if ((type.t & VT_BTYPE) == VT_FUNC) { /* external function definition */ /* specific case for func_call attribute */ - ad.func_proto = 1; - type.ref->r = INT_ATTR(&ad); + ad.a.func_proto = 1; + type.ref->a = ad.a; } else if (!(type.t & VT_ARRAY)) { /* not lvalue if array */ r |= lvalue_type(type.t); @@ -6039,7 +6042,7 @@ static int decl0(int l, int is_for_loop_init) } next(); } - ad.aligned = 0; + ad.a.aligned = 0; } } return 0; diff --git a/x86_64-gen.c b/x86_64-gen.c index 9aee875..9acca3c 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -933,7 +933,8 @@ typedef enum X86_64_Mode { x86_64_mode_x87 } X86_64_Mode; -static X86_64_Mode classify_x86_64_merge(X86_64_Mode a, X86_64_Mode b) { +static X86_64_Mode classify_x86_64_merge(X86_64_Mode a, X86_64_Mode b) +{ if (a == b) return a; else if (a == x86_64_mode_none) @@ -950,7 +951,8 @@ static X86_64_Mode classify_x86_64_merge(X86_64_Mode a, X86_64_Mode b) { return x86_64_mode_sse; } -static X86_64_Mode classify_x86_64_inner(CType *ty) { +static X86_64_Mode classify_x86_64_inner(CType *ty) +{ X86_64_Mode mode; Sym *f; @@ -988,7 +990,8 @@ static X86_64_Mode classify_x86_64_inner(CType *ty) { assert(0); } -static X86_64_Mode classify_x86_64_arg(CType *ty, CType *ret, int *psize, int *palign, int *reg_count) { +static X86_64_Mode classify_x86_64_arg(CType *ty, CType *ret, int *psize, int *palign, int *reg_count) +{ X86_64_Mode mode; int size, align, ret_t = 0; @@ -1045,7 +1048,8 @@ static X86_64_Mode classify_x86_64_arg(CType *ty, CType *ret, int *psize, int *p return mode; } -ST_FUNC int classify_x86_64_va_arg(CType *ty) { +ST_FUNC int classify_x86_64_va_arg(CType *ty) +{ /* This definition must be synced with stdarg.h */ enum __va_arg_type { __va_gen_reg, __va_float_reg, __va_stack @@ -1061,7 +1065,8 @@ ST_FUNC int classify_x86_64_va_arg(CType *ty) { /* Return the number of registers needed to return the struct, or 0 if returning via struct pointer. */ -int gfunc_sret(CType *vt, CType *ret, int *ret_align) { +ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align) +{ int size, align, reg_count; *ret_align = 1; // Never have to re-align return values for x86-64 return (classify_x86_64_arg(vt, ret, &size, &align, ®_count) != x86_64_mode_memory); -- 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 'configure') 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 From 0e3d2e0bea9eb90bef98c5bfe751949109bcadd0 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 12 Apr 2014 16:20:12 +0800 Subject: Make build CPU detection a tad more flexible --- configure | 109 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 50 deletions(-) (limited to 'configure') diff --git a/configure b/configure index c309de6..f6df9ad 100755 --- a/configure +++ b/configure @@ -71,46 +71,52 @@ if test -z "$source_path" -o "$source_path" = "." ; then source_path_used="no" fi -case "$cpu" in - i386|i486|i586|i686|i86pc|BePC|i686-AT386) - cpu="x86" - ;; - x86_64|amd64) - cpu="x86-64" - ;; - arm*) - case "$cpu" in - arm|armv4l) - cpuver=4 - ;; - armv5tel|armv5tejl) - cpuver=5 - ;; - armv6j|armv6l) - cpuver=6 - ;; - armv7a|armv7l) - cpuver=7 - ;; - esac - cpu="armv4l" - ;; - alpha) - cpu="alpha" - ;; - "Power Macintosh"|ppc|ppc64) - cpu="powerpc" - ;; - mips) - cpu="mips" - ;; - s390) - cpu="s390" - ;; - *) - cpu="unknown" - ;; -esac +classify_cpu () +{ + cpu="$1" + + case "$cpu" in + x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386) + cpu="x86" + ;; + x86_64|amd64) + cpu="x86-64" + ;; + arm*) + case "$cpu" in + arm|armv4l) + cpuver=4 + ;; + armv5tel|armv5tejl) + cpuver=5 + ;; + armv6j|armv6l) + cpuver=6 + ;; + armv7a|armv7l) + cpuver=7 + ;; + esac + cpu="armv4l" + ;; + alpha) + cpu="alpha" + ;; + "Power Macintosh"|ppc|ppc64) + cpu="powerpc" + ;; + mips) + cpu="mips" + ;; + s390) + cpu="s390" + ;; + *) + echo "Unsupported CPU: $cpu" + exit 1 + ;; + esac +} for opt do eval opt=\"$opt\" @@ -141,14 +147,6 @@ for opt do ;; --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2` ;; - --cc=*) cc=`echo $opt | cut -d '=' -f 2` - ;; - --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" - ;; - --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}" - ;; - --extra-libs=*) extralibs=${opt#--extra-libs=} - ;; --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2` ;; --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2` @@ -157,7 +155,15 @@ for opt do ;; --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2` ;; - --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` + --cc=*) cc=`echo $opt | cut -d '=' -f 2` + ;; + --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" + ;; + --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}" + ;; + --extra-libs=*) extralibs=${opt#--extra-libs=} + ;; + --cpu=*) build_cpu=`echo $opt | cut -d '=' -f 2` ;; --enable-gprof) gprof="yes" ;; @@ -186,6 +192,8 @@ for opt do esac done +classify_cpu "$cpu" + # Checking for CFLAGS if test -z "$CFLAGS"; then CFLAGS="-Wall -g -O2" @@ -271,6 +279,7 @@ Advanced options (experts only): --cc=CC use C compiler CC [$cc] --extra-cflags= specify compiler flags [$CFLAGS] --extra-ldflags= specify linker options [] + --cpu=CPU CPU [$cpu] --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 @@ -356,8 +365,8 @@ Doc directory $docdir Target root prefix $sysroot Source path $source_path C compiler $cc +Build CPU $cpu Target OS $targetos -CPU $cpu Big Endian $bigendian gprof enabled $gprof cross compilers $build_cross -- cgit v1.3.1