gendef: Do not set stdcall @0 for non-stdcall functions parsed from existing def files If there is a def file "lib1.def" with line "func1" and gendef was called on lib2.dll which contains func2 symbol defined as PE forward to lib1.func1 then gendef produces "lib2.def" file with line "func2@0 = lib1.func1" even when gendef was not called with -a option. This behavior is wrong because func1 in lib1.def is not defined as stdcall therefore gendef should not add stdcall decoration for func2. This change fixes this issue, changes the way how gendef reads and parse input def files. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-tools/gendef/src/gendef.c b/mingw-w64-tools/gendef/src/gendef.c index c25734c..e0d8fee 100644 --- a/mingw-w64-tools/gendef/src/gendef.c +++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -737,6 +737,7 @@ while ((exp = gExp) != NULL) { sImportname *pimpname; + int has_info = 0; int seen_ret; seen_ret = 1; gExp = exp->next; @@ -759,6 +760,7 @@ uint32_t at = 0; if (gendef_getsymbol_info (pimpname->dll, pimpname->name, &isD, &at)) { + has_info = 1; exp->beData = isD; if (!isD) exp->retpop = at; @@ -770,6 +772,7 @@ uint32_t at = 0; if (gendef_getsymbol_info (exp->forward, NULL, &isD, &at)) { + has_info = 1; exp->beData = isD; if (!isD) exp->retpop = at; @@ -842,7 +845,7 @@ if (exp->retpop != (uint32_t) -1 && !exp->be64 && has_atdecoration() && exp->name[0] == '?') fprintf(fp," ; has WINAPI (@%u)", (unsigned int) exp->retpop); - if (exp->name[0] != 0 && (exp->retpop != (uint32_t) -1 || (exp->retpop == 0 && exp->be64) || !has_atdecoration ())) + if (exp->name[0] != 0 && (has_info || exp->retpop != (uint32_t) -1 || (exp->retpop == 0 && exp->be64) || !has_atdecoration ())) { } else if (pimpname)
diff --git a/mingw-w64-tools/gendef/src/gendef_def.c b/mingw-w64-tools/gendef/src/gendef_def.c index 3dc33b8..7d17268 100644 --- a/mingw-w64-tools/gendef/src/gendef_def.c +++ b/mingw-w64-tools/gendef/src/gendef_def.c
@@ -49,7 +49,7 @@ static sImpDef *is_def_loaded (const char *); static sImpDef *gendef_loaddef (const char *); static FILE *fopen_def (const char *name); -static uint32_t get_uint32_by_str (const char *txt); +static uint32_t get_uint32_by_str (const char **txt_ptr); int gendef_getsymbol_info (const char *dllname, const char *symbolname, int *isData, uint32_t *at) @@ -91,7 +91,7 @@ id = gendef_loaddef (def); if (id) { - char *t = id->data; + const char *t = id->data; while (t != NULL && *t != 0) { t = strchr (t, '\n'); @@ -99,10 +99,18 @@ t++; if (t && strncmp (t, symbolname, symlen) == 0) { - if ((t[symlen] > 0 && t[symlen] <= 0x20) || t[symlen] == '@') + if ((t[symlen] >= 0 && t[symlen] <= 0x20) || t[symlen] == '@') { - t += symlen + 1; - *at = get_uint32_by_str (t); + *at = -1; + t += symlen; + if (*t == '@') + { + t++; + const char *old_t = t; + int num = get_uint32_by_str (&t); + if (old_t != t) + *at = num; + } while (*t != 0 && *t != '\n') { if (!strncmp (t, "DATA", 4)) @@ -228,8 +236,9 @@ } static uint32_t -get_uint32_by_str (const char *txt) +get_uint32_by_str (const char **txt_ptr) { + const char *txt = *txt_ptr; uint32_t ret = 0; while (*txt != 0 && *txt >= '0' && *txt <= '9') { @@ -237,6 +246,7 @@ ret += (uint32_t) (txt[0] - '0'); ++txt; } + *txt_ptr = txt; return ret; }