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
491 491
492#ifdef TCC_TARGET_PE492#ifdef TCC_TARGET_PE
493 if (sym->type.t & VT_EXPORT)493 if (sym->type.t & VT_EXPORT)
494 other |= 1;494 other |= ST_PE_EXPORT;
495 if (sym_type == STT_FUNC && sym->type.ref) {495 if (sym_type == STT_FUNC && sym->type.ref) {
496 Sym *ref = sym->type.ref;496 Sym *ref = sym->type.ref;
497 if (ref->a.func_export)497 if (ref->a.func_export)
498 other |= 1;498 other |= ST_PE_EXPORT;
499 if (ref->a.func_call == FUNC_STDCALL && can_add_underscore) {499 if (ref->a.func_call == FUNC_STDCALL && can_add_underscore) {
500 sprintf(buf1, "_%s@%d", name, ref->a.func_args * PTR_SIZE);500 sprintf(buf1, "_%s@%d", name, ref->a.func_args * PTR_SIZE);
501 name = buf1;501 name = buf1;
502 other |= 2;502 other |= ST_PE_STDCALL;
503 can_add_underscore = 0;503 can_add_underscore = 0;
504 }504 }
505 } else {505 } else {
506 if (find_elf_sym(tcc_state->dynsymtab_section, name))506 if (find_elf_sym(tcc_state->dynsymtab_section, name))
507 other |= 4;507 other |= ST_PE_IMPORT;
508 if (sym->type.t & VT_IMPORT)508 if (sym->type.t & VT_IMPORT)
509 other |= 4;509 other |= ST_PE_IMPORT;
510 }510 }
511#else511#else
512 if (! (sym->type.t & VT_STATIC))512 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
1316 So it is handled here as if it were in a DLL. */1316 So it is handled here as if it were in a DLL. */
1317 pe_putimport(s, 0, name, (uintptr_t)val);1317 pe_putimport(s, 0, name, (uintptr_t)val);
1318#else1318#else
1319 /* XXX: Same problem on linux but currently "solved" elsewhere
1320 via the rather dirty 'runtime_plt_and_got' hack. */
1321 add_elf_sym(symtab_section, (uintptr_t)val, 0,1319 add_elf_sym(symtab_section, (uintptr_t)val, 0,
1322 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,1320 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1323 SHN_ABS, name);1321 SHN_ABS, name);
tcc.h+4−0
@@ -1392,6 +1392,10 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); · 1391 unmodified lines
1392#ifdef TCC_TARGET_X86_641392#ifdef TCC_TARGET_X86_64
1393ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);1393ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
1394#endif1394#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
1395#endif1399#endif
1396 1400
1397/* ------------ tccrun.c ----------------- */1401/* ------------ tccrun.c ----------------- */
tccpe.c+8−8
@@ -363,7 +363,7 @@ struct pe_info { · 362 unmodified lines
363static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym)363static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym)
364{364{
365 const char *name = symtab_section->link->data + sym->st_name;365 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))
367 return name + 1;367 return name + 1;
368 return name;368 return name;
369}369}
@@ -378,7 +378,7 @@ static int pe_find_import(TCCState * s1, ElfW(Sym) *sym) · 8 unmodified lines
378 s = pe_export_name(s1, sym);378 s = pe_export_name(s1, sym);
379 if (n) {379 if (n) {
380 /* second try: */380 /* second try: */
381 if (sym->st_other & 2) {381 if (sym->st_other & ST_PE_STDCALL) {
382 /* try w/0 stdcall deco (windows API convention) */382 /* try w/0 stdcall deco (windows API convention) */
383 p = strrchr(s, '@');383 p = strrchr(s, '@');
384 if (!p || s[0] != '_')384 if (!p || s[0] != '_')
@@ -899,7 +899,7 @@ static void pe_build_exports(struct pe_info *pe) · 514 unmodified lines
899 for (sym_index = 1; sym_index < sym_end; ++sym_index) {899 for (sym_index = 1; sym_index < sym_end; ++sym_index) {
900 sym = (ElfW(Sym)*)symtab_section->data + sym_index;900 sym = (ElfW(Sym)*)symtab_section->data + sym_index;
901 name = pe_export_name(pe->s1, sym);901 name = pe_export_name(pe->s1, sym);
902 if ((sym->st_other & 1)902 if ((sym->st_other & ST_PE_EXPORT)
903 /* export only symbols from actually written sections */903 /* export only symbols from actually written sections */
904 && pe->s1->sections[sym->st_shndx]->sh_addr) {904 && pe->s1->sections[sym->st_shndx]->sh_addr) {
905 p = tcc_malloc(sizeof *p);905 p = tcc_malloc(sizeof *p);
@@ -908,9 +908,9 @@ static void pe_build_exports(struct pe_info *pe) · 2 unmodified lines
908 dynarray_add((void***)&sorted, &sym_count, p);908 dynarray_add((void***)&sorted, &sym_count, p);
909 }909 }
910#if 0910#if 0
911 if (sym->st_other & 1)911 if (sym->st_other & ST_PE_EXPORT)
912 printf("export: %s\n", name);912 printf("export: %s\n", name);
913 if (sym->st_other & 2)913 if (sym->st_other & ST_PE_STDCALL)
914 printf("stdcall: %s\n", name);914 printf("stdcall: %s\n", name);
915#endif915#endif
916 }916 }
@@ -1282,7 +1282,7 @@ static int pe_check_symbols(struct pe_info *pe) · 365 unmodified lines
1282 /* patch the original symbol */1282 /* patch the original symbol */
1283 sym->st_value = offset;1283 sym->st_value = offset;
1284 sym->st_shndx = text_section->sh_num;1284 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 */
1286 continue;1286 continue;
1287 }1287 }
1288 1288
@@ -1301,7 +1301,7 @@ static int pe_check_symbols(struct pe_info *pe) · 12 unmodified lines
1301 } else if (pe->s1->rdynamic1301 } else if (pe->s1->rdynamic
1302 && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {1302 && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
1303 /* if -rdynamic option, then export all non local symbols */1303 /* if -rdynamic option, then export all non local symbols */
1304 sym->st_other |= 1;1304 sym->st_other |= ST_PE_EXPORT;
1305 }1305 }
1306 }1306 }
1307 return ret;1307 return ret;
@@ -1463,7 +1463,7 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2) · 155 unmodified lines
1463 if (!sym->c)1463 if (!sym->c)
1464 put_extern_sym(sym, NULL, 0, 0);1464 put_extern_sym(sym, NULL, 0, 0);
1465 esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];1465 esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
1466 if (!(esym->st_other & 4))1466 if (!(esym->st_other & ST_PE_IMPORT))
1467 return sv;1467 return sv;
1468 1468
1469 // printf("import %04x %04x %04x %s\n", sv->type.t, sym->type.t, sv->r, get_tok_str(sv->sym->v, NULL));1469 // 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