aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji _at_ gmail.com>2009-03-20 20:34:58 +0900
committergrischka <grischka>2009-04-18 15:07:09 +0200
commitb8a32d8d4026a645de2e9974be88436eb3c4913f (patch)
tree66708bd91d144607910d5675552e09f449828533
parent7db1e69df29ff682cc9fcffd31ec11a50ac14ce7 (diff)
downloadtinycc-b8a32d8d4026a645de2e9974be88436eb3c4913f.tar.gz
tinycc-b8a32d8d4026a645de2e9974be88436eb3c4913f.tar.bz2
Generate PIC for addresses of symbols.
-rw-r--r--x86_64-gen.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/x86_64-gen.c b/x86_64-gen.c
index cfaf84c..f3382ae 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -198,14 +198,6 @@ static void gen_addr64(int r, Sym *sym, int64_t c)
}
/* output constant with relocation if 'r & VT_SYM' is true */
-static void gen_addr32(int r, Sym *sym, int c)
-{
- if (r & VT_SYM)
- greloc(cur_text_section, sym, ind, R_X86_64_32);
- gen_le32(c);
-}
-
-/* output constant with relocation if 'r & VT_SYM' is true */
static void gen_addrpc32(int r, Sym *sym, int c)
{
if (r & VT_SYM)
@@ -317,9 +309,14 @@ void load(int r, SValue *sv)
o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
gen_addr64(fr, sv->sym, sv->c.ull);
} else {
- o(0xc748);
- o(0xc0 + REG_VALUE(r)); /* mov $xx, r */
- gen_addr32(fr, sv->sym, fc);
+ if (fr & VT_SYM) {
+ o(0x8d48);
+ o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
+ gen_addrpc32(fr, sv->sym, fc);
+ } else {
+ o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
+ gen_le32(fc);
+ }
}
} else if (v == VT_LOCAL) {
o(0x48 | REX_BASE(r));