History

x86-64: fix load() for const pointers: (void*)-2

grischka committed 17 years ago

Commit bb5e0df1 parent fc977d51 file · +22 −21Browse files

Unified · Split

x86_64-gen.c+22−21
@@ -191,6 +191,7 @@ static int oad(int c, int s) · 190 unmodified lines
191191 return s;
192192 }
193193
194+#if 0
194195 /* output constant with relocation if 'r & VT_SYM' is true */
195196 static void gen_addr64(int r, Sym *sym, int64_t c)
196197 {
@@ -198,6 +199,7 @@ static void gen_addr64(int r, Sym *sym, int64_t c) · 1 unmodified line
198199 greloc(cur_text_section, sym, ind, R_X86_64_64);
199200 gen_le64(c);
200201 }
202+#endif
201203
202204 /* output constant with relocation if 'r & VT_SYM' is true */
203205 static void gen_addrpc32(int r, Sym *sym, int c)
@@ -354,30 +356,29 @@ void load(int r, SValue *sv) · 150 unmodified lines
354356 gen_modrm(r, fr, sv->sym, fc);
355357 } else {
356358 if (v == VT_CONST) {
357− if ((ft & VT_BTYPE) == VT_LLONG) {
358− assert(!(fr & VT_SYM));
359+ if (fr & VT_SYM) {
360+#ifdef TCC_TARGET_PE
361+ o(0x8d48);
362+ o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
363+ gen_addrpc32(fr, sv->sym, fc);
364+#else
365+ if (sv->sym->type.t & VT_STATIC) {
366+ o(0x8d48);
367+ o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
368+ gen_addrpc32(fr, sv->sym, fc);
369+ } else {
370+ o(0x8b48);
371+ o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */
372+ gen_gotpcrel(r, sv->sym, fc);
373+ }
374+#endif
375+ } else if (is64_type(ft)) {
359376 o(0x48);
360377 o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
361− gen_addr64(fr, sv->sym, sv->c.ull);
378+ gen_le64(sv->c.ull);
362379 } else {
363− if (fr & VT_SYM) {
364−#ifndef TCC_TARGET_PE
365− if (sv->sym->type.t & VT_STATIC) {
366−#endif
367− o(0x8d48);
368− o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
369− gen_addrpc32(fr, sv->sym, fc);
370−#ifndef TCC_TARGET_PE
371− } else {
372− o(0x8b48);
373− o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */
374− gen_gotpcrel(r, sv->sym, fc);
375− }
376−#endif
377− } else {
378− o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
379− gen_le32(fc);
380− }
380+ o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
381+ gen_le32(fc);
381382 }
382383 } else if (v == VT_LOCAL) {
383384 o(0x48 | REX_BASE(r));