History

Fix Fixes for PE x86_64 for fail in code

Applying 64bit relocs assumes that the CVal is initialized to zero for the whole 64bit. Consolidate this a bit, at the same time zeroing the .ull member more consistently when needed. Fixes segfault on x86_64-linux using global vars in tcctest.c.

Michael Matz committed 12 years ago

Commit 9e114761 parent 80b36ab1 file · +20 −27Browse files

Unified · Split

tccgen.c+20−27
@@ -369,6 +369,16 @@ static inline void vpushll(long long v) · 368 unmodified lines
369369 vpush64(VT_LLONG, v);
370370 }
371371
372+/* push a symbol value of TYPE */
373+static inline void vpushsym(CType *type, Sym *sym)
374+{
375+ CValue cval;
376+
377+ cval.ull = 0;
378+ vsetc(type, VT_CONST | VT_SYM, &cval);
379+ vtop->sym = sym;
380+}
381+
372382 /* Return a static symbol pointing to a section */
373383 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
374384 {
@@ -386,11 +396,7 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign · 11 unmodified lines
386396 /* push a reference to a section offset by adding a dummy symbol */
387397 static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
388398 {
389− CValue cval;
390−
391− cval.ul = 0;
392− vsetc(type, VT_CONST | VT_SYM, &cval);
393− vtop->sym = get_sym_ref(type, sec, offset, size);
399+ vpushsym(type, get_sym_ref(type, sec, offset, size));
394400 }
395401
396402 /* define a new external reference to a symbol 'v' of type 'u' */
@@ -435,18 +441,12 @@ static Sym *external_sym(int v, CType *type, int r, char *asm_label) · 38 unmodified lines
435441 /* push a reference to global symbol v */
436442 ST_FUNC void vpush_global_sym(CType *type, int v)
437443 {
438− Sym *sym;
439− CValue cval;
440−
441− sym = external_global_sym(v, type, 0);
442− cval.ul = 0;
443− vsetc(type, VT_CONST | VT_SYM, &cval);
444− vtop->sym = sym;
444+ vpushsym(type, external_global_sym(v, type, 0));
445445 }
446446
447447 ST_FUNC void vset(CType *type, int r, int v)
448448 {
449− CValue cval = {0};
449+ CValue cval;
450450
451451 cval.i = v;
452452 vsetc(type, r, &cval);
@@ -764,7 +764,7 @@ ST_FUNC int gv(int rc) · 311 unmodified lines
764764 sym = get_sym_ref(&vtop->type, data_section, offset, size << 2);
765765 vtop->r |= VT_LVAL | VT_SYM;
766766 vtop->sym = sym;
767− vtop->c.ul = 0;
767+ vtop->c.ull = 0;
768768 }
769769 #ifdef CONFIG_TCC_BCHECK
770770 if (vtop->r & VT_MUSTBOUND)
@@ -1949,15 +1949,16 @@ static void gen_cast(CType *type) · 1178 unmodified lines
19491949 vtop->c.ull = vtop->c.ll;
19501950 else if (dbt == VT_BOOL)
19511951 vtop->c.i = (vtop->c.ll != 0);
1952+#ifdef TCC_TARGET_X86_64
1953+ else if (dbt == VT_PTR)
1954+ ;
1955+#endif
19521956 else if (dbt != VT_LLONG) {
19531957 int s = 0;
19541958 if ((dbt & VT_BTYPE) == VT_BYTE)
19551959 s = 24;
19561960 else if ((dbt & VT_BTYPE) == VT_SHORT)
19571961 s = 16;
1958−#ifdef TCC_TARGET_X86_64
1959− if (!(dbt & (VT_PTR|VT_LLONG|VT_FUNC|VT_STRUCT)))
1960−#endif
19611962 if(dbt & VT_UNSIGNED)
19621963 vtop->c.ui = ((unsigned int)vtop->c.ll << s) >> s;
19631964 else
@@ -3908,11 +3909,7 @@ ST_FUNC void unary(void) · 1944 unmodified lines
39083909 /* if forward reference, we must point to s */
39093910 if (vtop->r & VT_SYM) {
39103911 vtop->sym = s;
3911−#ifdef TCC_TARGET_X86_64
3912− vtop->c.ull = 0;
3913−#else
3914− vtop->c.ul = 0;
3915−#endif
3912+ vtop->c.ull = 0;
39163913 }
39173914 break;
39183915 }
@@ -5617,13 +5614,9 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 1698 unmodified lines
56175614 esym->st_shndx = SHN_COMMON;
56185615 }
56195616 } else {
5620− CValue cval;
5621−
56225617 /* push global reference */
56235618 sym = get_sym_ref(type, sec, addr, size);
5624− cval.ul = 0;
5625− vsetc(type, VT_CONST | VT_SYM, &cval);
5626− vtop->sym = sym;
5619+ vpushsym(type, sym);
56275620 }
56285621 /* patch symbol weakness */
56295622 if (type->t & VT_WEAK)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t