From 9e0d23cc47359149a39eafffdbb133963980b6ed Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 27 Nov 2017 04:03:03 +0100 Subject: tccasm: Unify C and asm symbol table This makes the asm symbols use the same members as the C symbols for global decls, e.g. using the ELF symbol to hold offset and section. That allows us to use only one symbol table for C and asm symbols and to get rid of hacks to synch between them. We still need some special handling for symbols that come purely from asm sources. --- i386-asm.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'i386-asm.c') diff --git a/i386-asm.c b/i386-asm.c index 2e18497..1b992ca 100644 --- a/i386-asm.c +++ b/i386-asm.c @@ -500,12 +500,13 @@ ST_FUNC void gen_expr64(ExprValue *pe) static void gen_disp32(ExprValue *pe) { Sym *sym = pe->sym; - if (sym && sym->r == cur_text_section->sh_num) { + ElfSym *esym = elfsym(sym); + if (esym && esym->st_shndx == cur_text_section->sh_num) { /* same section: we can output an absolute value. Note that the TCC compiler behaves differently here because it always outputs a relocation to ease (future) code elimination in the linker */ - gen_le32(pe->v + sym->jnext - ind - 4); + gen_le32(pe->v + esym->st_value - ind - 4); } else { if (sym && sym->type.t == VT_VOID) { sym->type.t = VT_FUNC; @@ -1017,16 +1018,14 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) if (pa->instr_type & OPC_B) v += s >= 1; if (nb_ops == 1 && pa->op_type[0] == OPT_DISP8) { - Sym *sym; + ElfSym *esym; int jmp_disp; /* see if we can really generate the jump with a byte offset */ - sym = ops[0].e.sym; - if (!sym) + esym = elfsym(ops[0].e.sym); + if (!esym || esym->st_shndx != cur_text_section->sh_num) goto no_short_jump; - if (sym->r != cur_text_section->sh_num) - goto no_short_jump; - jmp_disp = ops[0].e.v + sym->jnext - ind - 2 - (v >= 0xff); + jmp_disp = ops[0].e.v + esym->st_value - ind - 2 - (v >= 0xff); if (jmp_disp == (int8_t)jmp_disp) { /* OK to generate jump */ ops[0].e.sym = 0; -- cgit v1.3.1