From 4266ebd69c2c7d12abee1da1f6c2228232c6bc87 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 25 Nov 2017 19:41:03 +0100 Subject: [PATCH] tccasm: Don't abuse dllexport/dllimport For tracking if asm symbols are connected with a C symbol, and if asm symbols need to be global use new flags, instead of reusing dllimport/dllexport, which would cause unrequested exported entries on Windows. This is a stop-gap until the C and asm symtable are unified. --- tcc.h | 4 +++- tccasm.c | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tcc.h b/tcc.h index 1efd046..5fc71a5 100644 --- a/tcc.h +++ b/tcc.h @@ -440,7 +440,9 @@ struct SymAttr { visibility : 2, dllexport : 1, dllimport : 1, - unused : 5; + asmcsym : 1, + asmexport : 1, + unused : 3; }; /* function attributes or temporary attributes for parsing */ diff --git a/tccasm.c b/tccasm.c index 7761c39..e6ad5aa 100644 --- a/tccasm.c +++ b/tccasm.c @@ -91,8 +91,8 @@ ST_FUNC Sym* get_asm_sym(int name, Sym *csym) /* XXX can't yet store st_size anywhere. */ sym->type.t = VT_VOID | (csym->type.t & VT_STATIC); /* Mark that this asm symbol doesn't need to be fed back. */ - sym->a.dllimport = 1; - sym->a.dllexport = !(csym->type.t & VT_STATIC); + sym->a.asmcsym = 1; + sym->a.asmexport = !(csym->type.t & VT_STATIC); } } return sym; @@ -454,11 +454,11 @@ ST_FUNC void asm_free_labels(TCCState *st) /* define symbol value in object file and care for updating the C and asm symbols */ s->type.t &= ~VT_EXTERN; - if (!s->a.dllimport) { + if (!s->a.asmcsym) { Sym *csym = sym_find(s->v); ElfW(Sym) *esym = NULL; if (csym) { - s->a.dllexport |= !(csym->type.t & VT_STATIC); + s->a.asmexport |= !(csym->type.t & VT_STATIC); if (csym->c) { esym = &((ElfW(Sym) *)symtab_section->data)[csym->c]; if (s->c) { @@ -473,7 +473,7 @@ ST_FUNC void asm_free_labels(TCCState *st) } } } - if (!s->a.dllexport) + if (!s->a.asmexport) s->type.t |= VT_STATIC; if (s->r) { if (s->r == SHN_ABS) @@ -485,7 +485,7 @@ ST_FUNC void asm_free_labels(TCCState *st) if (!esym || esym->st_shndx == SHN_UNDEF || !was_ext) put_extern_sym2(s, sec, s->jnext, 0, 0); } else /* undefined symbols are global */ - s->type.t &= ~VT_STATIC, s->a.dllexport = 1; + s->type.t &= ~VT_STATIC, s->a.asmexport = 1; patch_binding(s); } /* remove label */ @@ -750,7 +750,7 @@ static void asm_parse_directive(TCCState *s1, int global) next(); sym = get_asm_sym(tok, NULL); if (tok1 != TOK_ASMDIR_hidden) - sym->type.t &= ~VT_STATIC, sym->a.dllexport = 1; + sym->type.t &= ~VT_STATIC, sym->a.asmexport = 1; if (tok1 == TOK_ASMDIR_weak) sym->a.weak = 1; else if (tok1 == TOK_ASMDIR_hidden)