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
369 vpush64(VT_LLONG, v);369 vpush64(VT_LLONG, v);
370}370}
371 371
372/* push a symbol value of TYPE */
373static 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
372/* Return a static symbol pointing to a section */382/* Return a static symbol pointing to a section */
373ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)383ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
374{384{
@@ -386,11 +396,7 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign · 11 unmodified lines
386/* push a reference to a section offset by adding a dummy symbol */396/* push a reference to a section offset by adding a dummy symbol */
387static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)397static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
388{398{
389 CValue cval;399 vpushsym(type, get_sym_ref(type, sec, offset, size));
390
391 cval.ul = 0;
392 vsetc(type, VT_CONST | VT_SYM, &cval);
393 vtop->sym = get_sym_ref(type, sec, offset, size);
394}400}
395 401
396/* define a new external reference to a symbol 'v' of type 'u' */402/* 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
435/* push a reference to global symbol v */441/* push a reference to global symbol v */
436ST_FUNC void vpush_global_sym(CType *type, int v)442ST_FUNC void vpush_global_sym(CType *type, int v)
437{443{
438 Sym *sym;444 vpushsym(type, external_global_sym(v, type, 0));
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;
445}445}
446 446
447ST_FUNC void vset(CType *type, int r, int v)447ST_FUNC void vset(CType *type, int r, int v)
448{448{
449 CValue cval = {0};449 CValue cval;
450 450
451 cval.i = v;451 cval.i = v;
452 vsetc(type, r, &cval);452 vsetc(type, r, &cval);
@@ -764,7 +764,7 @@ ST_FUNC int gv(int rc) · 311 unmodified lines
764 sym = get_sym_ref(&vtop->type, data_section, offset, size << 2);764 sym = get_sym_ref(&vtop->type, data_section, offset, size << 2);
765 vtop->r |= VT_LVAL | VT_SYM;765 vtop->r |= VT_LVAL | VT_SYM;
766 vtop->sym = sym;766 vtop->sym = sym;
767 vtop->c.ul = 0;767 vtop->c.ull = 0;
768 }768 }
769#ifdef CONFIG_TCC_BCHECK769#ifdef CONFIG_TCC_BCHECK
770 if (vtop->r & VT_MUSTBOUND) 770 if (vtop->r & VT_MUSTBOUND)
@@ -1949,15 +1949,16 @@ static void gen_cast(CType *type) · 1178 unmodified lines
1949 vtop->c.ull = vtop->c.ll;1949 vtop->c.ull = vtop->c.ll;
1950 else if (dbt == VT_BOOL)1950 else if (dbt == VT_BOOL)
1951 vtop->c.i = (vtop->c.ll != 0);1951 vtop->c.i = (vtop->c.ll != 0);
1952#ifdef TCC_TARGET_X86_64
1953 else if (dbt == VT_PTR)
1954 ;
1955#endif
1952 else if (dbt != VT_LLONG) {1956 else if (dbt != VT_LLONG) {
1953 int s = 0;1957 int s = 0;
1954 if ((dbt & VT_BTYPE) == VT_BYTE)1958 if ((dbt & VT_BTYPE) == VT_BYTE)
1955 s = 24;1959 s = 24;
1956 else if ((dbt & VT_BTYPE) == VT_SHORT)1960 else if ((dbt & VT_BTYPE) == VT_SHORT)
1957 s = 16;1961 s = 16;
1958#ifdef TCC_TARGET_X86_64
1959 if (!(dbt & (VT_PTR|VT_LLONG|VT_FUNC|VT_STRUCT)))
1960#endif
1961 if(dbt & VT_UNSIGNED)1962 if(dbt & VT_UNSIGNED)
1962 vtop->c.ui = ((unsigned int)vtop->c.ll << s) >> s;1963 vtop->c.ui = ((unsigned int)vtop->c.ll << s) >> s;
1963 else1964 else
@@ -3908,11 +3909,7 @@ ST_FUNC void unary(void) · 1944 unmodified lines
3908 /* if forward reference, we must point to s */3909 /* if forward reference, we must point to s */
3909 if (vtop->r & VT_SYM) {3910 if (vtop->r & VT_SYM) {
3910 vtop->sym = s;3911 vtop->sym = s;
3911#ifdef TCC_TARGET_X86_643912 vtop->c.ull = 0;
3912 vtop->c.ull = 0;
3913#else
3914 vtop->c.ul = 0;
3915#endif
3916 }3913 }
3917 break;3914 break;
3918 }3915 }
@@ -5617,13 +5614,9 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 1698 unmodified lines
5617 esym->st_shndx = SHN_COMMON;5614 esym->st_shndx = SHN_COMMON;
5618 }5615 }
5619 } else {5616 } else {
5620 CValue cval;
5621
5622 /* push global reference */5617 /* push global reference */
5623 sym = get_sym_ref(type, sec, addr, size);5618 sym = get_sym_ref(type, sec, addr, size);
5624 cval.ul = 0;5619 vpushsym(type, sym);
5625 vsetc(type, VT_CONST | VT_SYM, &cval);
5626 vtop->sym = sym;
5627 }5620 }
5628 /* patch symbol weakness */5621 /* patch symbol weakness */
5629 if (type->t & VT_WEAK)5622 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