From 1445fea5827a948996e1c7bea24df4c0df79f432 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 19 Dec 2009 19:14:01 +0100 Subject: [PATCH] tccpe: allow linkage to extern symbols from asm --- libtcc.c | 1 + tccpe.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libtcc.c b/libtcc.c index 9a04a9e8..40b845ec 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1074,6 +1074,7 @@ static Sym *sym_push2(Sym **ps, int v, int t, long c) s = sym_malloc(); s->v = v; s->type.t = t; + s->type.ref = NULL; #ifdef _WIN64 s->d = NULL; #endif diff --git a/tccpe.c b/tccpe.c index 9b6c524c..41de3f60 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1184,6 +1184,21 @@ ST_FN void pe_relocate_rva (struct pe_info *pe, Section *s) } } +/*----------------------------------------------------------------------------*/ +static int pe_isafunc(int sym_index) +{ + Section *sr = text_section->reloc; + ElfW_Rel *rel, *rel_end; + Elf32_Word info = ELF32_R_INFO(sym_index, R_386_PC32); + if (!sr) + return 0; + rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); + for (rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) + if (rel->r_info == info) + return 1; + return 0; +} + /*----------------------------------------------------------------------------*/ ST_FN int pe_check_symbols(struct pe_info *pe) { @@ -1210,6 +1225,14 @@ ST_FN int pe_check_symbols(struct pe_info *pe) if (!is) goto not_found; + if (type == STT_NOTYPE) { + /* symbols from assembler have no type, find out which */ + if (pe_isafunc(sym_index)) + type = STT_FUNC; + else + type = STT_OBJECT; + } + if (type == STT_FUNC) { unsigned long offset = is->thk_offset; if (offset) {