From ea7b17f641cb962d0e9a79137e93c7e1e24b99ce Mon Sep 17 00:00:00 2001 From: Archidemon <_dangerdl@mail.ru> Date: Fri, 10 Jan 2014 09:45:18 +0600 Subject: [PATCH] Fixes for PE x86_64 for fail in code int (*fn1)=0x13fde16b5; and int fn1(int a) {...} struct { int (*fn2)(int a); } b = { fn1 }; --- tccgen.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tccgen.c b/tccgen.c index 7a675cc0..99cab530 100644 --- a/tccgen.c +++ b/tccgen.c @@ -446,7 +446,7 @@ ST_FUNC void vpush_global_sym(CType *type, int v) ST_FUNC void vset(CType *type, int r, int v) { - CValue cval; + CValue cval = {0}; cval.i = v; vsetc(type, r, &cval); @@ -1955,7 +1955,9 @@ static void gen_cast(CType *type) s = 24; else if ((dbt & VT_BTYPE) == VT_SHORT) s = 16; - +#ifdef TCC_TARGET_X86_64 + if (!(dbt & (VT_PTR|VT_LLONG|VT_FUNC|VT_STRUCT))) +#endif if(dbt & VT_UNSIGNED) vtop->c.ui = ((unsigned int)vtop->c.ll << s) >> s; else @@ -3906,7 +3908,11 @@ ST_FUNC void unary(void) /* if forward reference, we must point to s */ if (vtop->r & VT_SYM) { vtop->sym = s; - vtop->c.ul = 0; +#ifdef TCC_TARGET_X86_64 + s1->vtop->c.ull = 0; +#else + s1->vtop->c.ul = 0; +#endif } break; } @@ -5120,6 +5126,12 @@ static void init_putv(CType *type, Section *sec, unsigned long c, case VT_LLONG: *(long long *)ptr |= (vtop->c.ll & bit_mask) << bit_pos; break; + case VT_PTR: + if (s1->vtop->r & VT_SYM) { + greloc(s1, sec, s1->vtop->sym, c, R_DATA_PTR); + } + *(addr_t *)ptr |= (s1->vtop->c.ull & bit_mask) << bit_pos; + break; default: if (vtop->r & VT_SYM) { greloc(sec, vtop->sym, c, R_DATA_PTR);