From b8a32d8d4026a645de2e9974be88436eb3c4913f Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Fri, 20 Mar 2009 20:34:58 +0900 Subject: [PATCH] Generate PIC for addresses of symbols. --- x86_64-gen.c | 19 ++++++++----------- 1 file 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 @@ -197,14 +197,6 @@ static void gen_addr64(int r, Sym *sym, int64_t c) gen_le64(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) { @@ -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));