History

tccpe: adjust for new 'hidden' symbols feature

in order to avoid conflicts with windows specific (ab)usage of the Elf32_Sym -> st_other field.

grischka committed 12 years ago

Commit 2ac238f1 parent 6b7a6fc3 files · +17 −15Browse files

Unified · Split

3 files
  1. libtcc.c +5 −7
  2. tcc.h +4 −0
  3. tccpe.c +8 −8
libtcc.c+5−7
@@ -491,22 +491,22 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 490 unmodified lines
491491
492492 #ifdef TCC_TARGET_PE
493493 if (sym->type.t & VT_EXPORT)
494− other |= 1;
494+ other |= ST_PE_EXPORT;
495495 if (sym_type == STT_FUNC && sym->type.ref) {
496496 Sym *ref = sym->type.ref;
497497 if (ref->a.func_export)
498− other |= 1;
498+ other |= ST_PE_EXPORT;
499499 if (ref->a.func_call == FUNC_STDCALL && can_add_underscore) {
500500 sprintf(buf1, "_%s@%d", name, ref->a.func_args * PTR_SIZE);
501501 name = buf1;
502− other |= 2;
502+ other |= ST_PE_STDCALL;
503503 can_add_underscore = 0;
504504 }
505505 } else {
506506 if (find_elf_sym(tcc_state->dynsymtab_section, name))
507− other |= 4;
507+ other |= ST_PE_IMPORT;
508508 if (sym->type.t & VT_IMPORT)
509− other |= 4;
509+ other |= ST_PE_IMPORT;
510510 }
511511 #else
512512 if (! (sym->type.t & VT_STATIC))
@@ -1316,8 +1316,6 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 803 unmodified lines
13161316 So it is handled here as if it were in a DLL. */
13171317 pe_putimport(s, 0, name, (uintptr_t)val);
13181318 #else
1319− /* XXX: Same problem on linux but currently "solved" elsewhere
1320− via the rather dirty 'runtime_plt_and_got' hack. */
13211319 add_elf_sym(symtab_section, (uintptr_t)val, 0,
13221320 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
13231321 SHN_ABS, name);
tcc.h+4−0
@@ -1392,6 +1392,10 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); · 1391 unmodified lines
13921392 #ifdef TCC_TARGET_X86_64
13931393 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
13941394 #endif
1395+/* symbol properties stored in Elf32_Sym->st_other */
1396+# define ST_PE_EXPORT 0x10
1397+# define ST_PE_IMPORT 0x20
1398+# define ST_PE_STDCALL 0x40
13951399 #endif
13961400
13971401 /* ------------ tccrun.c ----------------- */
tccpe.c+8−8
@@ -363,7 +363,7 @@ struct pe_info { · 362 unmodified lines
363363 static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym)
364364 {
365365 const char *name = symtab_section->link->data + sym->st_name;
366− if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & 2))
366+ if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & ST_PE_STDCALL))
367367 return name + 1;
368368 return name;
369369 }
@@ -378,7 +378,7 @@ static int pe_find_import(TCCState * s1, ElfW(Sym) *sym) · 8 unmodified lines
378378 s = pe_export_name(s1, sym);
379379 if (n) {
380380 /* second try: */
381− if (sym->st_other & 2) {
381+ if (sym->st_other & ST_PE_STDCALL) {
382382 /* try w/0 stdcall deco (windows API convention) */
383383 p = strrchr(s, '@');
384384 if (!p || s[0] != '_')
@@ -899,7 +899,7 @@ static void pe_build_exports(struct pe_info *pe) · 514 unmodified lines
899899 for (sym_index = 1; sym_index < sym_end; ++sym_index) {
900900 sym = (ElfW(Sym)*)symtab_section->data + sym_index;
901901 name = pe_export_name(pe->s1, sym);
902− if ((sym->st_other & 1)
902+ if ((sym->st_other & ST_PE_EXPORT)
903903 /* export only symbols from actually written sections */
904904 && pe->s1->sections[sym->st_shndx]->sh_addr) {
905905 p = tcc_malloc(sizeof *p);
@@ -908,9 +908,9 @@ static void pe_build_exports(struct pe_info *pe) · 2 unmodified lines
908908 dynarray_add((void***)&sorted, &sym_count, p);
909909 }
910910 #if 0
911− if (sym->st_other & 1)
911+ if (sym->st_other & ST_PE_EXPORT)
912912 printf("export: %s\n", name);
913− if (sym->st_other & 2)
913+ if (sym->st_other & ST_PE_STDCALL)
914914 printf("stdcall: %s\n", name);
915915 #endif
916916 }
@@ -1282,7 +1282,7 @@ static int pe_check_symbols(struct pe_info *pe) · 365 unmodified lines
12821282 /* patch the original symbol */
12831283 sym->st_value = offset;
12841284 sym->st_shndx = text_section->sh_num;
1285− sym->st_other &= ~1; /* do not export */
1285+ sym->st_other &= ~ST_PE_EXPORT; /* do not export */
12861286 continue;
12871287 }
12881288
@@ -1301,7 +1301,7 @@ static int pe_check_symbols(struct pe_info *pe) · 12 unmodified lines
13011301 } else if (pe->s1->rdynamic
13021302 && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
13031303 /* if -rdynamic option, then export all non local symbols */
1304− sym->st_other |= 1;
1304+ sym->st_other |= ST_PE_EXPORT;
13051305 }
13061306 }
13071307 return ret;
@@ -1463,7 +1463,7 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2) · 155 unmodified lines
14631463 if (!sym->c)
14641464 put_extern_sym(sym, NULL, 0, 0);
14651465 esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
1466− if (!(esym->st_other & 4))
1466+ if (!(esym->st_other & ST_PE_IMPORT))
14671467 return sv;
14681468
14691469 // printf("import %04x %04x %04x %s\n", sv->type.t, sym->type.t, sv->r, get_tok_str(sv->sym->v, NULL));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t