aboutsummaryrefslogtreecommitdiff
path: root/tccpe.c
diff options
context:
space:
mode:
authorYX Hao <lifenjoiner@163.com>2013-09-19 21:50:38 +0800
committerYX Hao <lifenjoiner@163.com>2013-09-19 21:50:38 +0800
commit642b6d0f50c6b6a842c9239a102fe34d5619e931 (patch)
tree60ca755ef6d92565ce21a9d4ca9baf8ebd146a0a /tccpe.c
parent76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 (diff)
downloadtinycc-642b6d0f50c6b6a842c9239a102fe34d5619e931.tar.gz
tinycc-642b6d0f50c6b6a842c9239a102fe34d5619e931.tar.bz2
Add the possibility to use noname functions by ordinal
tcc.c: process.h:177:20: note: expected 'char * const*' but argument is of type 'char const*const*' tccpe.c: Add the possibility to use noname functions by ordinal. use def file: "AliasName @n" build-tcc.bat: 1. Enable 32 bits mode on 64 bits OS. 2. build doc. _parseLibs.bat: Convenient to use "*.def + *.c" instead of *.a, just use -l* _tcc.bat: a practice of _parseLibs.bat Signed-off-by: YX Hao <lifenjoiner@163.com>
Diffstat (limited to 'tccpe.c')
-rw-r--r--tccpe.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/tccpe.c b/tccpe.c
index 19b20ab..bc1545e 100644
--- a/tccpe.c
+++ b/tccpe.c
@@ -813,6 +813,7 @@ static void pe_build_imports(struct pe_info *pe)
hdr->Name = v + rva_base;
for (k = 0, n = p->sym_count; k <= n; ++k) {
+ int ordinal = 0;
if (k < n) {
int iat_index = p->symbols[k]->iat_index;
int sym_index = p->symbols[k]->sym_index;
@@ -823,25 +824,31 @@ static void pe_build_imports(struct pe_info *pe)
org_sym->st_value = thk_ptr;
org_sym->st_shndx = pe->thunk->sh_num;
v = pe->thunk->data_offset + rva_base;
- section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */
- put_elf_str(pe->thunk, name);
+
+ /* ordinal or name */
+ ordinal = imp_sym->st_value; /* from pe_load_def, temperary use */
+ //if (ordinal) printf("ordinal: %d\n", ordinal);
+ if (!ordinal) {
+ section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */
+ put_elf_str(pe->thunk, name);
+ }
#ifdef TCC_IS_NATIVE
if (pe->type == PE_RUN) {
v = imp_sym->st_value;
if (dllref) {
if ( !dllref->handle )
dllref->handle = LoadLibrary(dllref->name);
- v = (ADDR3264)GetProcAddress(dllref->handle, name);
+ v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(LPCSTR)NULL+ordinal:name);
}
if (!v)
- tcc_error_noabort("undefined symbol '%s'", name);
+ tcc_error_noabort("can't build symbol '%s'", name);
}
#endif
} else {
v = 0; /* last entry is zero */
}
*(ADDR3264*)(pe->thunk->data+thk_ptr) =
- *(ADDR3264*)(pe->thunk->data+ent_ptr) = v;
+ *(ADDR3264*)(pe->thunk->data+ent_ptr) = (ordinal && pe->type != PE_RUN)?(ADDR3264)1<<(sizeof(ADDR3264)*8-1)|ordinal:v;
thk_ptr += sizeof (ADDR3264);
ent_ptr += sizeof (ADDR3264);
}
@@ -1590,6 +1597,8 @@ static int pe_load_def(TCCState *s1, int fd)
char line[400], dllname[80], *p;
for (;;) {
+ int ord = 0;
+ char *x, *d, idxstr[8];
p = get_line(line, sizeof line, fd);
if (NULL == p)
break;
@@ -1614,7 +1623,24 @@ static int pe_load_def(TCCState *s1, int fd)
++state;
default:
- pe_putimport(s1, dllindex, p, 0);
+ /* get ordianl and will store in sym->st_value */
+ d = NULL;
+ x = strchr(line, ' ');
+ if (x) x = strchr(line, '@');
+ while (x != NULL) {
+ d =x;
+ x = strchr(x+1, '@');
+ }
+ if (d) {
+ ord = atoi(d+1);
+ itoa(ord, idxstr, 10);
+ if (strcmp(idxstr, d+1) == 0) {
+ memset(d, 0, 1);
+ trimback(p, d);
+ } else
+ ord = 0;
+ }
+ pe_putimport(s1, dllindex, p, ord);
continue;
}
}