tccpe: adjust for new 'hidden' symbols feature

in order to avoid conflicts with windows specific (ab)usage
of the Elf32_Sym -> st_other field.
This commit is contained in:
grischka 2014-04-17 17:01:28 +02:00
parent 6b7a6fcbc8
commit 2ac238fc50
3 changed files with 17 additions and 15 deletions

View File

@ -491,22 +491,22 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
#ifdef TCC_TARGET_PE
if (sym->type.t & VT_EXPORT)
other |= 1;
other |= ST_PE_EXPORT;
if (sym_type == STT_FUNC && sym->type.ref) {
Sym *ref = sym->type.ref;
if (ref->a.func_export)
other |= 1;
other |= ST_PE_EXPORT;
if (ref->a.func_call == FUNC_STDCALL && can_add_underscore) {
sprintf(buf1, "_%s@%d", name, ref->a.func_args * PTR_SIZE);
name = buf1;
other |= 2;
other |= ST_PE_STDCALL;
can_add_underscore = 0;
}
} else {
if (find_elf_sym(tcc_state->dynsymtab_section, name))
other |= 4;
other |= ST_PE_IMPORT;
if (sym->type.t & VT_IMPORT)
other |= 4;
other |= ST_PE_IMPORT;
}
#else
if (! (sym->type.t & VT_STATIC))
@ -1316,8 +1316,6 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val)
So it is handled here as if it were in a DLL. */
pe_putimport(s, 0, name, (uintptr_t)val);
#else
/* XXX: Same problem on linux but currently "solved" elsewhere
via the rather dirty 'runtime_plt_and_got' hack. */
add_elf_sym(symtab_section, (uintptr_t)val, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_ABS, name);

4
tcc.h
View File

@ -1392,6 +1392,10 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
#ifdef TCC_TARGET_X86_64
ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
#endif
/* symbol properties stored in Elf32_Sym->st_other */
# define ST_PE_EXPORT 0x10
# define ST_PE_IMPORT 0x20
# define ST_PE_STDCALL 0x40
#endif
/* ------------ tccrun.c ----------------- */

16
tccpe.c
View File

@ -363,7 +363,7 @@ struct pe_info {
static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym)
{
const char *name = symtab_section->link->data + sym->st_name;
if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & 2))
if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & ST_PE_STDCALL))
return name + 1;
return name;
}
@ -378,7 +378,7 @@ static int pe_find_import(TCCState * s1, ElfW(Sym) *sym)
s = pe_export_name(s1, sym);
if (n) {
/* second try: */
if (sym->st_other & 2) {
if (sym->st_other & ST_PE_STDCALL) {
/* try w/0 stdcall deco (windows API convention) */
p = strrchr(s, '@');
if (!p || s[0] != '_')
@ -899,7 +899,7 @@ static void pe_build_exports(struct pe_info *pe)
for (sym_index = 1; sym_index < sym_end; ++sym_index) {
sym = (ElfW(Sym)*)symtab_section->data + sym_index;
name = pe_export_name(pe->s1, sym);
if ((sym->st_other & 1)
if ((sym->st_other & ST_PE_EXPORT)
/* export only symbols from actually written sections */
&& pe->s1->sections[sym->st_shndx]->sh_addr) {
p = tcc_malloc(sizeof *p);
@ -908,9 +908,9 @@ static void pe_build_exports(struct pe_info *pe)
dynarray_add((void***)&sorted, &sym_count, p);
}
#if 0
if (sym->st_other & 1)
if (sym->st_other & ST_PE_EXPORT)
printf("export: %s\n", name);
if (sym->st_other & 2)
if (sym->st_other & ST_PE_STDCALL)
printf("stdcall: %s\n", name);
#endif
}
@ -1282,7 +1282,7 @@ static int pe_check_symbols(struct pe_info *pe)
/* patch the original symbol */
sym->st_value = offset;
sym->st_shndx = text_section->sh_num;
sym->st_other &= ~1; /* do not export */
sym->st_other &= ~ST_PE_EXPORT; /* do not export */
continue;
}
@ -1301,7 +1301,7 @@ static int pe_check_symbols(struct pe_info *pe)
} else if (pe->s1->rdynamic
&& ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
/* if -rdynamic option, then export all non local symbols */
sym->st_other |= 1;
sym->st_other |= ST_PE_EXPORT;
}
}
return ret;
@ -1463,7 +1463,7 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2)
if (!sym->c)
put_extern_sym(sym, NULL, 0, 0);
esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
if (!(esym->st_other & 4))
if (!(esym->st_other & ST_PE_IMPORT))
return sv;
// printf("import %04x %04x %04x %s\n", sv->type.t, sym->type.t, sv->r, get_tok_str(sv->sym->v, NULL));